···11+const express = require('express');
22+const router = express.Router();
33+const geddit = require('../geddit.js');
44+const G = new geddit.Geddit();
55+const fs = require('fs/promises');
66+77+88+// GET /
99+router.get('/', async (req, res) => {
1010+ res.redirect("/r/all")
1111+});
1212+1313+// GET /r/:id
1414+router.get('/r/:subreddit', async (req, res) => {
1515+ var subreddit = req.params.subreddit;
1616+1717+ var postsReq = G.getSubmissions(`r/${subreddit}`);
1818+ var aboutReq = G.getSubreddit(`${subreddit}`);
1919+2020+ var [posts, about] = await Promise.all([postsReq, aboutReq]);
2121+ res.render('index', { subreddit, posts, about });
2222+});
2323+2424+// GET /comments/:id
2525+router.get('/comments/:id', async (req, res) => {
2626+ var id = req.params.id;
2727+2828+ response = await G.getSubmissionComments(id);
2929+ var post = response.submission.data;
3030+ var comments = response.comments;
3131+3232+ res.render('comments', { post, comments });
3333+});
3434+3535+module.exports = router;
+18
src/views/comment.pug
···11+include utils
22+mixin comment(com, isfirst)
33+ - var data = com.data
44+ - var kind = com.kind
55+ if kind == "more"
66+ div.more #{data.count} more comments
77+ else
88+ div(class=`comment ${isfirst?'first':''}`)
99+ div.comment-body !{data.body}
1010+ div.info-container
1111+ div.info-item by u/#{data.author}
1212+ div.info-item ↑ #{fmtnum(data.ups)}
1313+ div.replies
1414+ if data.replies
1515+ if data.replies.data
1616+ if data.replies.data.children
1717+ each reply in data.replies.data.children
1818+ +comment(reply,false)
+25
src/views/comments.pug
···11+doctype html
22+html
33+ head
44+ meta(charset='UTF-8')
55+ title reddit
66+ link(rel='stylesheet', href='/styles.css')
77+ body
88+ main#content
99+ div.header
1010+ a(href=`/r/${post.subreddit}`)
1111+ h4 ← r/#{post.subreddit}
1212+ h2 #{post.title}
1313+ if post.post_hint == 'image'
1414+ img(src=post.url).post-media
1515+ else if post.post_hint == 'hosted:video'
1616+ video(src=post.url).post-media
1717+ p.self-text !{post.selftext}
1818+ hr
1919+2020+ div.comments-container
2121+ each child in comments
2222+ include comment
2323+ +comment(child, true)
2424+2525+ script(src='https://unpkg.com/htmx.org@1.9.10')
+19
src/views/index.pug
···11+doctype html
22+html
33+ head
44+ meta(charset='UTF-8')
55+ title reddit
66+ link(rel='stylesheet', href='/styles.css')
77+ body
88+ main#content
99+ div.header
1010+ a(href=`/r/#{subreddit}`)
1111+ h1 r/#{subreddit}
1212+ if about
1313+ p #{about.public_description}
1414+1515+ each child in posts.posts
1616+ include post
1717+ +post(child.data)
1818+1919+ script(src='https://unpkg.com/htmx.org@1.9.10')