const express = require('express'); const crypto = require('crypto'); 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; 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 replace_format_indicators(input_string, post_index) { 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) return output_string } app.get("/", (req,res) => { header_div = config.timeline_header header_div = replace_format_indicators(header_div, 0); posts_div = ""; counter = posts.posts.length - 1; while ((counter >= 0) && (counter > (posts.posts.length - (config.timeline_length + 1)))) { let post = config.timeline_post_format; posts_div += replace_format_indicators(post, counter); counter -= 1; } res.send(`