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(`