From 3efe4b78361ad491628869fd5863bd9459b4594c Mon Sep 17 00:00:00 2001 From: deadvey Date: Sun, 13 Jul 2025 02:48:15 +0100 Subject: [PATCH] headerLevelStart (for showdownjs) and some comments --- app.js | 42 ++++++++++++++++++++++-------------------- hitcount.txt | 2 +- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/app.js b/app.js index 45d22ce..39d4a27 100755 --- a/app.js +++ b/app.js @@ -3,11 +3,11 @@ const fs = require('fs'); // For modifying and reading files const express = require('express'); // For running a webserver in nodejs const showdown = require('showdown') // For converting markdown to html on demand, https://showdownjs.com/ const crypto = require('crypto'); // For encrypting passwords, I use sha512 -// fromUnixTime creates a date object out of an integer -// format is used to format a date object into a defined format eg yyyy-MM-dd -// getUnixTime converts a date object into an integer (unix time) -// find out more at https://date-fns.org/ \or docs: https://date-fns.org/docs/Getting-Started -const { fromUnixTime, format, getUnixTime } = require("date-fns") +// fromUnixTime(): Create a date from a Unix timestamp (in seconds). Decimal values will be discarded. +// format(): Return the formatted date string in the given format. The result may vary by locale. +// getUnixTime(): Get the seconds timestamp of the given date. +// find out more at https://date-fns.org/ \or docs: https://date-fns.org/docs/Getting-Startedyyyyyyyy +const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library // There's only one possible argument, so we can just check if the user passed that one // TODO I plan on adding more such as --help and --post so I should make this more robust at some point @@ -17,7 +17,7 @@ if (process.argv[2] == "--first-time") { // Define the modules now so they are global let users // contains a list of users, each user is an object containing username,prettyname,hash and description -let posts // contains a list of posts, +let posts // contains a list of posts, let comments let config @@ -42,7 +42,8 @@ let converter = new showdown.Converter({ tables: true, // Enable support for tables syntax. strikethrough: true, // Enable support for strikethrough: ~~text~~ tasklists: true, // Enable support for GitHub style tasklists. - [x] and - [ ] - encodeEmails: true //Enable automatic obfuscation of email addresses. emails are encoded via character entities + encodeEmails: true, //Enable automatic obfuscation of email addresses. emails are encoded via character entities + headerLevelStart: 3, //Set starting level for the heading tags. }) // The footer div is globale because it's a site wide, so define it here @@ -109,20 +110,21 @@ function get_userID(username) { return -1 // If user is not present, return -1 } -// The configuration defines a date format using the date-fns syntax +// The configuration defines a date format using the date-fns (a datetime library) syntax +// eg "yyyy-MM-dd" // this converts unix time (an integer) into a string that is formatted according to config.js -// uses date-fns's fromUnixTime() and format() +// uses date-fns's fromUnixTime() and format() functions // returns the formatted date (string) function unix_time_to_date_format(unix_time) { date = fromUnixTime(unix_time) formatted_date = format(date, config.date_format) - return formatted_date } // This is similar to the above function, however, instead of formatting to the users // configuration, it formats to RFC-822 which is the date format used by RSS feeds // eg "Mon, 23 May 2025 18:59:59 +0100" +// accepts unix time (int) // returns the formatted date (string) function unix_time_to_rss_date(unix_time) { date = fromUnixTime(unix_time) @@ -132,7 +134,7 @@ function unix_time_to_rss_date(unix_time) { // This function accepts a list of strings eg ["string1","string2,"string3"] (any length) // then returns a string of them each pointing to a seperate url -// eg "string1, string2, string3 +// eg "string1, string2, string3" // this is so you can have a list of tags that each point to their individual tag page // returns: string function hyperlink_tags(tags) { @@ -276,7 +278,7 @@ app.get("/", (req,res) => { counter -= 1; } res.send(`
${posts_div}
`); -}); +}); // / app.get("/user/:username", (req, res) => { header_div = config.user_page_header header_div = replace_format_indicators(header_div) @@ -288,13 +290,13 @@ app.get("/user/:username", (req, res) => { } } res.send(`
${posts_div}
`); -}); +}); // /user/:username app.get("/post/:post_index", (req, res) => { post_div = ""; let post = config.post_page_format; post_div += replace_format_indicators(post, req.params.post_index); res.send(`
${post_div}
`); -}); +}); // /post/:post_index app.get("/tag/:tag", (req,res) => { const tag = req.params.tag let header_div = config.tag_page_header @@ -307,7 +309,7 @@ app.get("/tag/:tag", (req,res) => { }; }; res.send(`
${page_content}
`); -}); +}); // /tag/:tag app.get("/post", (req,res) => { res.send(`
@@ -319,7 +321,7 @@ app.get("/post", (req,res) => {
* Markdown supported
`); -}); +}); // /post app.get("/edit/:post_id", (req,res) => { const post_id = req.params.post_id const post = posts.posts[post_id] @@ -336,7 +338,7 @@ app.get("/edit/:post_id", (req,res) => {
* Markdown supported `); -}); +}); // /edit/:post_id app.post("/submit_comment", (req,res) => { const unix_timestamp = getUnixTime(new Date()) @@ -355,7 +357,7 @@ app.post("/submit_comment", (req,res) => { fs.writeFileSync(`${__dirname}/comments.js`, `export const comments = ${JSON.stringify(comments.comments)}\nexport const counter = ${counter}`, 'utf-8'); res.redirect(301,`/post/${req.body.post_index}`) -}); +}); // /submit_comment app.post("/submit_edit", (req,res) => { const password = crypto.createHash('sha512').update(req.body.password).digest('hex'); const postID = req.body.postID @@ -385,7 +387,7 @@ app.post("/submit_edit", (req,res) => { else { res.send(`Invalid Password for user`,users.users[userID]['prettyname']); } -}); +}); // /submit_edit app.post("/submit_post", (req,res) => { const password = crypto.createHash('sha512').update(req.body.password).digest('hex'); const username = escape_input(req.body.username) @@ -416,7 +418,7 @@ app.post("/submit_post", (req,res) => { else { res.send(`Invalid Password for user`,username); } -}); +}); // /submit_post app.listen(config.port, () => { console.log(`Server is running at http://localhost:${config.port} in ${config.root_path}`); diff --git a/hitcount.txt b/hitcount.txt index 99bc3d5..9754915 100644 --- a/hitcount.txt +++ b/hitcount.txt @@ -1 +1 @@ -253 \ No newline at end of file +259 \ No newline at end of file