don't freak if posts.post = []

This commit is contained in:
deadvey 2025-07-13 00:51:01 +01:00
parent d75a74b7a8
commit 3a821b5eba
2 changed files with 36 additions and 33 deletions

67
app.js
View File

@ -111,38 +111,41 @@ function hyperlink_tags(tags) {
function replace_format_indicators(input_string, post_index=0, tag_name="tag") { function replace_format_indicators(input_string, post_index=0, tag_name="tag") {
post_object = posts.posts[post_index] post_object = posts.posts[post_index]
output_string = input_string output_string = input_string
.replaceAll("%%", "%") .replaceAll("%%", "%")
.replaceAll("%A", (post_object["tags"])) .replaceAll("%P", "/post")
.replaceAll("%B", (hyperlink_tags(post_object["tags"]))) .replaceAll("%O", `/edit/${post_index}`)
.replaceAll("%C", converter.makeHtml(post_object["content"])) .replaceAll("%R", "/rss")
.replaceAll("%D", unix_time_to_date_format(post_object["pubdate"])) .replaceAll("%Y", config.site_name)
.replaceAll("%E", unix_time_to_date_format(post_object["editdate"])) .replaceAll("%W", config.site_description)
.replaceAll("%F", users.users[post_object["userID"]]['prettyname']) .replaceAll("%Z", config.attribution)
.replaceAll("%G", tag_name) if (posts.posts.length > 0) {
.replaceAll("%I", users.users[post_object['userID']]['description']) output_string = output_string
.replaceAll("%L", `/post/${post_index}`) .replaceAll("%A", (post_object["tags"]))
.replaceAll("%M", return_comments(post_index)) .replaceAll("%B", (hyperlink_tags(post_object["tags"])))
.replaceAll("%N", users.users[post_object["userID"]]['username']) .replaceAll("%C", converter.makeHtml(post_object["content"]))
.replaceAll("%P", "/post") .replaceAll("%D", unix_time_to_date_format(post_object["pubdate"]))
.replaceAll("%O", `/edit/${post_index}`) .replaceAll("%E", unix_time_to_date_format(post_object["editdate"]))
.replaceAll("%R", "/rss") .replaceAll("%F", users.users[post_object["userID"]]['prettyname'])
.replaceAll("%S", config.seperator) .replaceAll("%G", tag_name)
.replaceAll("%T", post_object["title"]) .replaceAll("%I", users.users[post_object['userID']]['description'])
.replaceAll("%U", `/user/${users.users[post_object["userID"]]['username']}`) .replaceAll("%L", `/post/${post_index}`)
.replaceAll("%X", `<form method="POST" action="/submit_comment"> .replaceAll("%M", return_comments(post_index))
<input type="hidden" name="post_index" value="${post_index}"> .replaceAll("%N", users.users[post_object["userID"]]['username'])
<input placeholder="username" name="name"><br/> .replaceAll("%S", config.seperator)
<textarea placeholder="comment" name="content"></textarea><br/> .replaceAll("%T", post_object["title"])
<button type="submit">Submit</button> .replaceAll("%U", `/user/${users.users[post_object["userID"]]['username']}`)
</form>`) .replaceAll("%X", `<form method="POST" action="/submit_comment">
.replaceAll("%Y", config.site_name) <input type="hidden" name="post_index" value="${post_index}">
.replaceAll("%W", config.site_description) <input placeholder="username" name="name"><br/>
.replaceAll("%Z", config.attribution) <textarea placeholder="comment" name="content"></textarea><br/>
if (config.enable_hitcount == true) { <button type="submit">Submit</button>
output_string = output_string </form>`)
.replaceAll("%H", fs.readFileSync('hitcount.txt')) }
} if (config.enable_hitcount == true) {
output_string = output_string
.replaceAll("%H", fs.readFileSync('hitcount.txt'))
}
return output_string return output_string
} }

View File

@ -1 +1 @@
244 248