diff options
Diffstat (limited to 'src/views')
-rw-r--r-- | src/views/comment.pug | 18 | ||||
-rw-r--r-- | src/views/comments.pug | 25 | ||||
-rw-r--r-- | src/views/index.pug | 19 | ||||
-rw-r--r-- | src/views/post.pug | 21 | ||||
-rw-r--r-- | src/views/utils.pug | 3 |
5 files changed, 86 insertions, 0 deletions
diff --git a/src/views/comment.pug b/src/views/comment.pug new file mode 100644 index 0000000..24e1a9b --- /dev/null +++ b/src/views/comment.pug | |||
@@ -0,0 +1,18 @@ | |||
1 | include utils | ||
2 | mixin comment(com, isfirst) | ||
3 | - var data = com.data | ||
4 | - var kind = com.kind | ||
5 | if kind == "more" | ||
6 | div.more #{data.count} more comments | ||
7 | else | ||
8 | div(class=`comment ${isfirst?'first':''}`) | ||
9 | div.comment-body !{data.body} | ||
10 | div.info-container | ||
11 | div.info-item by u/#{data.author} | ||
12 | div.info-item ↑ #{fmtnum(data.ups)} | ||
13 | div.replies | ||
14 | if data.replies | ||
15 | if data.replies.data | ||
16 | if data.replies.data.children | ||
17 | each reply in data.replies.data.children | ||
18 | +comment(reply,false) | ||
diff --git a/src/views/comments.pug b/src/views/comments.pug new file mode 100644 index 0000000..f7964a3 --- /dev/null +++ b/src/views/comments.pug | |||
@@ -0,0 +1,25 @@ | |||
1 | doctype html | ||
2 | html | ||
3 | head | ||
4 | meta(charset='UTF-8') | ||
5 | title reddit | ||
6 | link(rel='stylesheet', href='/styles.css') | ||
7 | body | ||
8 | main#content | ||
9 | div.header | ||
10 | a(href=`/r/${post.subreddit}`) | ||
11 | h4 ← r/#{post.subreddit} | ||
12 | h2 #{post.title} | ||
13 | if post.post_hint == 'image' | ||
14 | img(src=post.url).post-media | ||
15 | else if post.post_hint == 'hosted:video' | ||
16 | video(src=post.url).post-media | ||
17 | p.self-text !{post.selftext} | ||
18 | hr | ||
19 | |||
20 | div.comments-container | ||
21 | each child in comments | ||
22 | include comment | ||
23 | +comment(child, true) | ||
24 | |||
25 | script(src='https://unpkg.com/[email protected]') | ||
diff --git a/src/views/index.pug b/src/views/index.pug new file mode 100644 index 0000000..d017570 --- /dev/null +++ b/src/views/index.pug | |||
@@ -0,0 +1,19 @@ | |||
1 | doctype html | ||
2 | html | ||
3 | head | ||
4 | meta(charset='UTF-8') | ||
5 | title reddit | ||
6 | link(rel='stylesheet', href='/styles.css') | ||
7 | body | ||
8 | main#content | ||
9 | div.header | ||
10 | a(href=`/r/#{subreddit}`) | ||
11 | h1 r/#{subreddit} | ||
12 | if about | ||
13 | p #{about.public_description} | ||
14 | |||
15 | each child in posts.posts | ||
16 | include post | ||
17 | +post(child.data) | ||
18 | |||
19 | script(src='https://unpkg.com/[email protected]') | ||
diff --git a/src/views/post.pug b/src/views/post.pug new file mode 100644 index 0000000..77ef3f5 --- /dev/null +++ b/src/views/post.pug | |||
@@ -0,0 +1,21 @@ | |||
1 | include utils | ||
2 | mixin post(p) | ||
3 | article.post | ||
4 | div.post-container | ||
5 | div.post-text | ||
6 | div.title-container !{p.title} | ||
7 | div.info-container | ||
8 | div.info-item by u/#{p.author} | ||
9 | div.info-item ↑ #{fmtnum(p.ups)} | ||
10 | div.info-item #{p.domain} | ||
11 | div.info-item | ||
12 | a(href=`/r/${p.subreddit}`) r/#{p.subreddit} | ||
13 | div.info-item | ||
14 | a(href=`/comments/${p.id}`) #{fmtnum (p.num_comments)} #{fmttxt(p.num_comments, 'comment')} | ||
15 | div.media-preview | ||
16 | if p.post_hint == "image" || p.post_hint == "link" | ||
17 | if p.thumbnail && p.thumbnail != "self" || p.thumbnail != "default" | ||
18 | a(href=p.url) | ||
19 | img(src=p.thumbnail width='100px') | ||
20 | else if p.post_hint == "hosted:video" | ||
21 | video(src=p.secure_media.reddit_video.scrubber_media_url width='100px') | ||
diff --git a/src/views/utils.pug b/src/views/utils.pug new file mode 100644 index 0000000..f3f61bb --- /dev/null +++ b/src/views/utils.pug | |||
@@ -0,0 +1,3 @@ | |||
1 | - var fmtnum = (n)=>n>=1000?(n/1000).toFixed(1)+'k':n; | ||
2 | - var fmttxt = (n,t)=>`${t}${n==1?'':'s'}` | ||
3 | |||