aboutsummaryrefslogtreecommitdiff
path: root/src/mixins
diff options
context:
space:
mode:
Diffstat (limited to 'src/mixins')
-rw-r--r--src/mixins/comment.pug20
-rw-r--r--src/mixins/post.pug25
-rw-r--r--src/mixins/sub.pug32
3 files changed, 77 insertions, 0 deletions
diff --git a/src/mixins/comment.pug b/src/mixins/comment.pug
new file mode 100644
index 0000000..ec01dad
--- /dev/null
+++ b/src/mixins/comment.pug
@@ -0,0 +1,20 @@
1include ../utils
2mixin comment(com, isfirst)
3 - var data = com.data
4 - var kind = com.kind
5 if kind == "more"
6 div(class=`${isfirst?'first':''}`)
7 div.more #{data.count} more comments
8 else
9 div(class=`comment ${isfirst?'first':''}`)
10 div.comment-info-container
11 div.info-item u/#{data.author}
12 div.info-item ↑ #{fmtnum(data.ups)}
13 div.comment-body
14 != data.body_html
15 div.replies
16 if data.replies
17 if data.replies.data
18 if data.replies.data.children
19 each reply in data.replies.data.children
20 +comment(reply,false)
diff --git a/src/mixins/post.pug b/src/mixins/post.pug
new file mode 100644
index 0000000..f5819d4
--- /dev/null
+++ b/src/mixins/post.pug
@@ -0,0 +1,25 @@
1include ../utils
2mixin post(p)
3 article.post
4 div.post-container
5 div.post-text
6 div.title-container
7 != p.title
8 span.domain (#{p.domain})
9 div.info-container
10 div.info-item ↑ #{fmtnum(p.ups)}
11 div.info-item by u/#{p.author}
12 div.info-item
13 a(href=`/r/${p.subreddit}`) r/#{p.subreddit}
14 div.info-item
15 a(href=`/comments/${p.id}`) #{fmtnum (p.num_comments)} #{fmttxt(p.num_comments, 'comment')}
16 div.media-preview
17 if p.post_hint == "image" || p.post_hint == "link"
18 if p.thumbnail && p.thumbnail != "self" || p.thumbnail != "default"
19 a(href=p.url)
20 img(src=p.thumbnail width='100px')
21 else if p.post_hint == "hosted:video"
22 - var url = p.secure_media.reddit_video.fallback_url
23 a(href=url)
24 video(src=url height='100px')
25
diff --git a/src/mixins/sub.pug b/src/mixins/sub.pug
new file mode 100644
index 0000000..a40aa68
--- /dev/null
+++ b/src/mixins/sub.pug
@@ -0,0 +1,32 @@
1mixin subMgmt()
2 script.
3 function getSubs() {
4 var store = localStorage.getItem('subs');
5 if (store) {
6 return store.split(',').map((n)=>n.replace(/\/?r\//,''));
7 } else {
8 return [];
9 }
10 }
11
12 function subscribe(newsub) {
13 var subs = getSubs();
14 if (!subs.includes(newsub)) {
15 localStorage.setItem('subs',[...subs,newsub]);
16 updateButton(newsub);
17 }
18 }
19
20 function unsubscribe(sub) {
21 var subs = getSubs();
22 if (subs.includes(sub)) {
23 localStorage.setItem('subs',subs.filter((s)=>s!=sub));
24 updateButton(sub);
25 }
26 }
27
28 function issub(sub) {
29 return getSubs().includes(sub);
30 }
31
32