diff --git a/.gitignore b/.gitignore
new file mode 100755
index 0000000..0ca753a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+package.json
+node_modules
+package-lock.json
+posts.js
+users.js
diff --git a/.posts.js.swp b/.posts.js.swp
new file mode 100644
index 0000000..1e9bcef
Binary files /dev/null and b/.posts.js.swp differ
diff --git a/app.js b/app.js
old mode 100644
new mode 100755
index 8c07af8..10d13e2
--- a/app.js
+++ b/app.js
@@ -1,48 +1,111 @@
const express = require('express');
-const crypto = require('crypto');
+const crypto = require('crypto'); // For encrypting passwords
+const { fromUnixTime, format, getUnixTime } = require("date-fns")
const fs = require('fs');
const users = require('./users.js');
const posts = require('./posts.js');
const config = require('./config.js');
const app = express();
-const port = 8005;
+const port = 8080;
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(express.static(config.root_path));
-function unix_time_to_date_format(unix_time) {
- let date_object = new Date(unix_time)
- let formatter = new Intl.DateTimeFormat(config.date_format,config.date_options);
- let formatted_time = formatter.format(date_object);
-
- return formatted_time
+function get_userID(username) {
+ for (let i = 0; i < users.users.length; i++) {
+ if (users.users[i]['username'] == username) {
+ return i
+ }
+ }
+ return -1
}
-function replace_format_indicators(input_string, post_index) {
+function unix_time_to_date_format(unix_time) {
+ date = fromUnixTime(unix_time)
+ formatted_date = format(date, config.date_format)
+
+ return formatted_date
+}
+
+function unix_time_to_rss_date(unix_time) {
+ date = fromUnixTime(unix_time)
+ formatted_date = format(date, "EEE, dd MMM yyyy HH:mm:ss")
+ return `${formatted_date} ${config.time_zone}`
+}
+
+function hyperlink_tags(tags) {
+ string = ""
+ for (let tag_index = 0; tag_index < tags.length; tag_index++) {
+ string += `${tags[tag_index]}`
+ if (tag_index < tags.length - 1) {
+ string += ", ";
+ }
+ }
+ return string
+}
+
+function replace_format_indicators(input_string, post_index=0, tag_name="tag") {
post_object = posts.posts[post_index]
output_string = input_string
- .replace("%A", (post_object["tags"]))
- .replace("%C", post_object["content"])
- .replace("%D", unix_time_to_date_format(post_object["pubdate"]))
- .replace("%E", unix_time_to_date_format(post_object["editdate"]))
- .replace("%L", `/post/${post_index}`)
- .replace("%N", post_object["poster"])
- .replace("%P", "/post")
- .replace("%O", "/edit")
- .replace("%R", "/rss")
- .replace("%S", config.seperator)
- .replace("%T", post_object["title"])
- .replace("%U", `/user/${post_object["poster"]}`)
- .replace("%Y", config.site_name)
- .replace("%W", config.site_description)
+ .replaceAll("%A", (post_object["tags"]))
+ .replaceAll("%B", (hyperlink_tags(post_object["tags"])))
+ .replaceAll("%C", post_object["content"].replaceAll("\n","
"))
+ .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("%N", users.users[post_object["userID"]]['username'])
+ .replaceAll("%P", "/post")
+ .replaceAll("%O", "/edit")
+ .replaceAll("%R", "/rss")
+ .replaceAll("%S", config.seperator)
+ .replaceAll("%T", post_object["title"])
+ .replaceAll("%U", `/user/${users.users[post_object["userID"]]['username']}`)
+ .replaceAll("%Y", config.site_name)
+ .replaceAll("%W", config.site_description)
return output_string
}
+app.get(config.rss_path, (req,res) => {
+ if (config.rss == false) {
+ res.send("Sorry, RSS is disabled!")
+ }
+ else {
+ let rss_content = `
+