Comments now have their own pages, at /comment/commentID, these are
linked to when someone replies to another comment (>> id), I also fixed a bug in comment submission where the counter was not incrementing
This commit is contained in:
@@ -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, "<a href='/comment/$1'>>> $1</a>")
|
||||
.replaceAll(/>>([0-9]*)/g, "<a href='/comment/$1'>>>$1</a>")
|
||||
.replaceAll(/>> ([0-9]*)/g, "<a href='/comment/$1'>>> $1</a>")
|
||||
.replaceAll(/>>([0-9]*)/g, "<a href='/comment/$1'>>>$1</a>")
|
||||
.replaceAll("\n", "<br/>")
|
||||
};
|
||||
|
Reference in New Issue
Block a user