docs and also I improved the readability/user friendliness of the EJS

This commit is contained in:
2025-09-03 22:28:50 +01:00
parent 99e07389d0
commit c8af978259
15 changed files with 211 additions and 95 deletions

View File

@@ -1,5 +1,7 @@
import { createRequire } from 'module';
const require = createRequire(import.meta.url)
const config = require("../config.json")
const locale = require(`../locales/${config.locale}.json`)
// The configuration defines a date format using the date-fns (a datetime library) syntax
// eg "yyyy-MM-dd"
@@ -8,7 +10,6 @@ const require = createRequire(import.meta.url)
// returns the formatted date (string)
export function unix_time_to_date_format(unix_time) {
const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
const config = require("../config.json")
let date = fromUnixTime(unix_time)
let formatted_date = format(date, config.date_format)
return formatted_date
@@ -20,7 +21,6 @@ export function unix_time_to_date_format(unix_time) {
// returns the formatted date (string)
export function unix_time_to_rss_date(unix_time) {
const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
const config = require("../config.json")
let date = fromUnixTime(unix_time)
let formatted_date = format(date, "EEE, dd MMM yyyy HH:mm:ss")
return `${formatted_date} ${config.time_zone}`
@@ -37,14 +37,19 @@ export function unix_time_to_atom_date(unix_time) {
// eg "<a href="/tag/string1">string1</a>, <a href="/tag/string2">string2</a>, <a href="/tag/string3">string3</a>"
// this is so you can have a list of tags that each point to their individual tag page
// returns: string
export function hyperlink_tags(tags) {
export function render_tags(tags) {
let string = "" // Initialises the string
for (let tag_index = 0; tag_index < tags.length; tag_index++) { // Loop over each tag
string += `<a href="/tag/${tags[tag_index]}">${tags[tag_index]}</a>` // Adds the tag to the string as a HTML href
if (tag_index < tags.length - 1) { // If there are more tags, then insert a comma
string += ", ";
}
}
if (tags.length == 1 && tags[0] == "") {
string = locale.no_tags; // If there are no tags, output something
}
else {
for (let tag_index = 0; tag_index < tags.length; tag_index++) { // Loop over each tag
string += `<a href="/tag/${tags[tag_index]}">${tags[tag_index]}</a>` // Adds the tag to the string as a HTML href
if (tag_index < tags.length - 1) { // If there are more tags, then insert a comma
string += ", ";
}
}
}
return string
}
// The users are stored as a list of objects [ user_object, user_object, user_object ]
@@ -101,8 +106,6 @@ export function render_comment(comment_content) {
};
export function render_md(content) {
const markdownit = require("markdown-it")
const config = require("../config.json")
const locale = require(`../locales/${config.locale}.json`)
const md = markdownit({
html: false,
xhtmlOut: false,