From 3a821b5eba7ecb3d34c0c037895016058067f3ba Mon Sep 17 00:00:00 2001 From: deadvey Date: Sun, 13 Jul 2025 00:51:01 +0100 Subject: [PATCH] don't freak if posts.post = [] --- app.js | 67 +++++++++++++++++++++++++++------------------------- hitcount.txt | 2 +- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/app.js b/app.js index 9cb4421..8f799e5 100755 --- a/app.js +++ b/app.js @@ -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", `
- -
-
- -
`) - .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("%%", "%") + .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", `
+ +
+
+ +
`) + } + if (config.enable_hitcount == true) { + output_string = output_string + .replaceAll("%H", fs.readFileSync('hitcount.txt')) + } return output_string } diff --git a/hitcount.txt b/hitcount.txt index e0c1820..030d25b 100644 --- a/hitcount.txt +++ b/hitcount.txt @@ -1 +1 @@ -244 \ No newline at end of file +248 \ No newline at end of file