aboutsummaryrefslogtreecommitdiff
path: root/src/routes
diff options
context:
space:
mode:
authorAkshay <[email protected]>2024-08-31 08:25:09 +0100
committerAkshay <[email protected]>2024-08-31 08:28:11 +0100
commit55ef1a63136c2ff0ec808ba44160f5503cc4416b (patch)
treeb14d287ca284963d7469c48957380778da7182b2 /src/routes
parent17cb2b62fd8f31f49347ae5818acfc8c589fdbea (diff)
add markdown rendering, lay out localStorage subscriptions
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/index.js32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/routes/index.js b/src/routes/index.js
index 6cf5403..77ff118 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -1,8 +1,8 @@
1const express = require('express'); 1const express = require('express');
2const he = require('he');
2const router = express.Router(); 3const router = express.Router();
3const geddit = require('../geddit.js'); 4const geddit = require('../geddit.js');
4const G = new geddit.Geddit(); 5const G = new geddit.Geddit();
5const fs = require('fs/promises');
6 6
7 7
8// GET / 8// GET /
@@ -18,6 +18,7 @@ router.get('/r/:subreddit', async (req, res) => {
18 var aboutReq = G.getSubreddit(`${subreddit}`); 18 var aboutReq = G.getSubreddit(`${subreddit}`);
19 19
20 var [posts, about] = await Promise.all([postsReq, aboutReq]); 20 var [posts, about] = await Promise.all([postsReq, aboutReq]);
21
21 res.render('index', { subreddit, posts, about }); 22 res.render('index', { subreddit, posts, about });
22}); 23});
23 24
@@ -26,10 +27,33 @@ router.get('/comments/:id', async (req, res) => {
26 var id = req.params.id; 27 var id = req.params.id;
27 28
28 response = await G.getSubmissionComments(id); 29 response = await G.getSubmissionComments(id);
29 var post = response.submission.data;
30 var comments = response.comments;
31 30
32 res.render('comments', { post, comments }); 31 res.render('comments', unescape_submission(response));
33}); 32});
34 33
35module.exports = router; 34module.exports = router;
35
36function unescape_submission(response) {
37 var post = response.submission.data;
38 var comments = response.comments;
39
40 if (post.selftext_html) {
41 post.selftext_html = he.decode(post.selftext_html);
42 }
43 comments.forEach(unescape_comment);
44
45 return { post, comments };
46}
47
48function unescape_comment(comment) {
49 if (comment.data.body_html) {
50 comment.data.body_html = he.decode(comment.data.body_html);
51 }
52 if (comment.data.replies) {
53 if(comment.data.replies.data) {
54 if(comment.data.replies.data.children) {
55 comment.data.replies.data.children.forEach(unescape_comment);
56 }
57 }
58 }
59}