diff --git a/README.md b/README.md
index 17e9ae3..370df42 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ Read the [configuation guide](docs/CONFIG.md) for configuration help (in config.
* site wide and user specific rss, atom
* hitcount
* Markdown syntax in posts
-* Commenting on posts
+* Commenting on posts and replying to other comments
* site wide custom CSS
# Bugs
@@ -34,7 +34,6 @@ Read the [configuation guide](docs/CONFIG.md) for configuration help (in config.
* formatable custom strings
* inline comments and docs
* clean up code a bit
-* comment pages?
* /postID and /userID pages
* site index
* Make EJS modification more user friendly
diff --git a/data/example-config.json b/data/example-config.json
index 6569884..99fc2b5 100755
--- a/data/example-config.json
+++ b/data/example-config.json
@@ -9,7 +9,7 @@
"timeline_length": 20,
"enable_hitcount": true,
"charset": "UTF-8",
- "root_path": "/home/deadvey/code/web/blogger-webroot/",
+ "root_path": "/home/deadvey/code/web/webroot/",
"edit_account_base_url": "/edit_account",
"new_post_url": "/post",
"signup_url": "/signup",
@@ -24,6 +24,7 @@
"signups_unavailable": "Sorry, this server does not allow signups",
"user_exists": "Sorry, this user already exists, try a different username",
"user_doesnt_exist": "Sorry, this user does not exist",
+ "comment_doesnt_exist": "This comment doesn't exist, this could be because the post it was attached to was deleted",
"delete_account_confirmation": "Delete my account - (I agree that my account and all of my posts will be permanently deleted instantly)",
"incorrect_password": "Incorrect Password",
"rss_disabled": "Sorry, RSS is disabled",
diff --git a/example-config.json b/example-config.json
index e044268..aae04c1 100755
--- a/example-config.json
+++ b/example-config.json
@@ -24,6 +24,7 @@
"signups_unavailable": "Sorry, this server does not allow signups",
"user_exists": "Sorry, this user already exists, try a different username",
"user_doesnt_exist": "Sorry, this user does not exist",
+ "comment_doesnt_exist": "This comment doesn't exist, this could be because the post it was attached to was deleted",
"delete_account_confirmation": "I agree that my account and all of my posts will be permanently deleted instantly",
"incorrect_password": "Incorrect Password",
"rss_disabled": "Sorry, RSS is disabled",
diff --git a/src/functions.js b/src/functions.js
index 51843f3..8923102 100644
--- a/src/functions.js
+++ b/src/functions.js
@@ -61,6 +61,18 @@ export function get_userID(username) {
}
return -1 // If user is not present, return -1
}
+
+export function get_comment(commentID) { // TODO scales like shit
+ const comments = require("../data/comments.json")
+ for (let i = 0; i < comments.comments.length; i++) { // Loop over every post
+ for (let j = 0; j < comments.comments[i].length; j++) { // Then every comment in that post
+ if (comments.comments[i][j]["id"] == commentID) {
+ return comments.comments[i][j]
+ };
+ }
+ }
+ return -1 // If comment is not present, return -1
+}
// This escapes some potentially dangerous HTML characters with their HTML entities
// https://www.freeformatter.com/html-entities.html
// accepts a string
@@ -76,3 +88,13 @@ export function escape_input(input) {
.replaceAll("%", "%")
return output
}
+
+// Render comment content by replacing the >> int with a url link to that comment
+export function render_comment(comment_content) {
+ return comment_content
+ .replaceAll(/>> ([0-9]*)/g, ">> $1")
+ .replaceAll(/>>([0-9]*)/g, ">>$1")
+ .replaceAll(/>> ([0-9]*)/g, ">> $1")
+ .replaceAll(/>>([0-9]*)/g, ">>$1")
+ .replaceAll("\n", "
")
+};
diff --git a/src/server.js b/src/server.js
index b0a9dee..0204714 100644
--- a/src/server.js
+++ b/src/server.js
@@ -216,6 +216,30 @@ app.get("/tag/:tag", (req,res) => {
converter,
})
}); // /tag/:tag
+app.get("/comment/:commentID", (req,res) => {
+ const commentID = req.params.commentID;
+ const comment = func.get_comment(commentID)
+ if (comment == -1) {
+ res.render("partials/message", {
+ config,
+ message: config.string.comment_doesnt_exist,
+ })
+ }
+ else {
+ res.render("pages/comment",
+ {
+ config: config,
+ post: posts[comment["id"]],
+ users,
+ comment,
+ fromUnixTime: fromUnixTime,
+ format: format,
+ getUnixTime: getUnixTime,
+ func,
+ converter,
+ })
+ }
+});
///////////////////// Form pages ////////////////////////////
@@ -275,7 +299,7 @@ app.post("/submit_comment", (req,res) => {
"id": comments.counter,
"pubdate": unix_timestamp
};
- let counter = comments.counter+1;
+ comments.counter += 1;
comments.comments[req.body.post_index].push(new_comment);
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
diff --git a/views/pages/comment.ejs b/views/pages/comment.ejs
new file mode 100644
index 0000000..a6c671f
--- /dev/null
+++ b/views/pages/comment.ejs
@@ -0,0 +1,11 @@
+
+
+