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

View File

@ -1 +1 @@
244
248