From 07050c9cf6207f0ca462f12ada96b540b587bf05 Mon Sep 17 00:00:00 2001 From: teddit Date: Mon, 27 Jun 2022 21:48:40 +0200 Subject: [PATCH] properly fix 'continue this thread' links - no need to req.url checking (ref #82) --- inc/compilePostComments.js | 12 ++++-------- inc/processJsonPost.js | 6 ++---- routes/subreddit.js | 6 ++---- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/inc/compilePostComments.js b/inc/compilePostComments.js index b5157ca..6840d76 100644 --- a/inc/compilePostComments.js +++ b/inc/compilePostComments.js @@ -1,5 +1,5 @@ module.exports = function() { - this.compilePostCommentsHtml = (comments, next_comment, post_id, post_url, morechildren_ids, post_author, viewing_comment, user_preferences, last_known_depth, req_url) => { + this.compilePostCommentsHtml = (comments, next_comment, post_id, post_url, morechildren_ids, post_author, viewing_comment, user_preferences, last_known_depth) => { return new Promise((resolve, reject) => { (async () => { let comments_html @@ -115,9 +115,7 @@ module.exports = function() { } } else { let link = comments.parent_id.split('_')[1] - if (req_url.slice(-1) === '/') { - link = '../' + link - } + link = post_url + link comments_html = `
continue this thread @@ -202,7 +200,7 @@ module.exports = function() { if(comment.replies[j+1]) { next_reply = comment.replies[j+1] } - replies_html += await compilePostCommentsHtml(comment.replies[j], next_reply, post_id, post_url, null, post_author, viewing_comment, user_preferences, null, req_url) + replies_html += await compilePostCommentsHtml(comment.replies[j], next_reply, post_id, post_url, null, post_author, viewing_comment, user_preferences) } } } @@ -219,9 +217,7 @@ module.exports = function() { ` } else { let link = comment.parent_id.split('_')[1] - if (req_url.slice(-1) === '/') { - link = '../' + link - } + link = post_url + link comments_html = `
continue this thread diff --git a/inc/processJsonPost.js b/inc/processJsonPost.js index 043de81..d57711d 100644 --- a/inc/processJsonPost.js +++ b/inc/processJsonPost.js @@ -365,8 +365,7 @@ async function finalizeJsonPost( post_url, morechildren_ids, viewing_comment, - user_preferences, - req_url + user_preferences ) { let comments_html = `
`; let comments = processed_json.comments; @@ -389,8 +388,7 @@ async function finalizeJsonPost( processed_json.author, viewing_comment, user_preferences, - last_known_depth, - req_url + last_known_depth ); } diff --git a/routes/subreddit.js b/routes/subreddit.js index d45b028..5891d35 100644 --- a/routes/subreddit.js +++ b/routes/subreddit.js @@ -682,8 +682,7 @@ subredditRoutes.get( post_url, more_comments, viewing_comment, - req.cookies, - req.url + req.cookies ); return res.render('post', { post: finalized_json.post_data, @@ -760,8 +759,7 @@ subredditRoutes.get( post_url, more_comments, viewing_comment, - req.cookies, - req.url + req.cookies ); return res.render('post', { post: finalized_json.post_data,