diff options
author | Raphael Kabo <raphaelkabo@hey.com> | 2024-02-28 22:40:33 +0000 |
---|---|---|
committer | Raphael Kabo <raphaelkabo@hey.com> | 2024-05-26 16:05:32 +0100 |
commit | 28be7ca850f41352a1e4e43f0c7035bdeeff6e83 (patch) | |
tree | 3d8bef1bec6dd3600c8ffb318c03b221ccb504b8 /src | |
parent | 53288fa3df3f828e99eaba679d436e65def2deb4 (diff) |
New frontend styles, instance description functionality
Diffstat (limited to 'src')
-rw-r--r-- | src/routes/frontend.ts | 24 | ||||
-rw-r--r-- | src/routes/static.ts | 3 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/routes/frontend.ts b/src/routes/frontend.ts index 4d977d7..4e6f3ed 100644 --- a/src/routes/frontend.ts +++ b/src/routes/frontend.ts @@ -1,4 +1,5 @@ import { Router, Request, Response } from "express"; +import fs from "fs"; import moment from "moment-timezone"; import { marked } from "marked"; import { markdownToSanitizedHTML, renderPlain } from "../util/markdown.js"; @@ -121,11 +122,34 @@ router.get("/events", async (_: Request, res: Response) => { }; }); + // Attempt to pull the instance description from a Markdown file + const defaultInstanceDescription = + "**{{ siteName }}** is running on Gathio — a simple, federated, privacy-first event hosting platform."; + let instanceDescription = defaultInstanceDescription; + try { + if (fs.existsSync("./static/instance-description.md")) { + const fileBody = fs.readFileSync( + "./static/instance-description.md", + "utf-8", + ); + instanceDescription = markdownToSanitizedHTML(fileBody); + } + // Replace {{siteName}} with the instance name + instanceDescription = instanceDescription.replace( + /\{\{ ?siteName ?\}\}/g, + res.locals.config?.general.site_name, + ); + } catch (err) { + console.log(err); + } + res.render("publicEventList", { title: "Public events", upcomingEvents: upcomingEvents, pastEvents: pastEvents, eventGroups: updatedEventGroups, + instanceDescription, + instanceRules: instanceRules(), ...frontendConfig(res), }); }); diff --git a/src/routes/static.ts b/src/routes/static.ts index 6fab98d..6670214 100644 --- a/src/routes/static.ts +++ b/src/routes/static.ts @@ -2,10 +2,13 @@ import { Router, Request, Response } from "express"; import fs from "fs"; import getConfig, { frontendConfig } from "../lib/config.js"; import { markdownToSanitizedHTML } from "../util/markdown.js"; +import { getConfigMiddleware } from "../lib/middleware.js"; const config = getConfig(); const router = Router(); +router.use(getConfigMiddleware); + if (config.static_pages?.length) { config.static_pages .filter((page) => page.path?.startsWith("/") && page.filename) |