diff options
author | Raphael <mail@raphaelkabo.com> | 2024-05-26 19:12:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-26 19:12:37 +0100 |
commit | 43296cd88b9ab6f3ba1d5f4de5f76f44b68de82a (patch) | |
tree | 9738de17d2be368ffc95f90644dbf98220c2a136 /src | |
parent | 53288fa3df3f828e99eaba679d436e65def2deb4 (diff) | |
parent | 4ce9c7d32fd834ff1dc87b7dd90f7428ad0eb44d (diff) |
Merge pull request #138 from lowercasename/rk/style-overhaul
Style overhaul
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/config.ts | 26 | ||||
-rw-r--r-- | src/routes/frontend.ts | 11 | ||||
-rw-r--r-- | src/routes/static.ts | 3 |
3 files changed, 39 insertions, 1 deletions
diff --git a/src/lib/config.ts b/src/lib/config.ts index 4bc43bd..b4086d8 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -2,6 +2,7 @@ import fs from "fs"; import toml from "toml"; import { exitWithError } from "./process.js"; import { Response } from "express"; +import { markdownToSanitizedHTML } from "../util/markdown.js"; interface StaticPage { title: string; @@ -152,6 +153,31 @@ export const instanceRules = (): InstanceRule[] => { return rules; }; +export const instanceDescription = (): string => { + const config = getConfig(); + 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, + config?.general.site_name, + ); + return instanceDescription; + } catch (err) { + console.log(err); + return defaultInstanceDescription; + } +}; + // Attempt to load our global config. Will stop the app if the config file // cannot be read (there's no point trying to continue!) export const getConfig = (): GathioConfig => { diff --git a/src/routes/frontend.ts b/src/routes/frontend.ts index 4d977d7..86ad69c 100644 --- a/src/routes/frontend.ts +++ b/src/routes/frontend.ts @@ -1,8 +1,13 @@ 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"; -import { frontendConfig, instanceRules } from "../lib/config.js"; +import { + frontendConfig, + instanceDescription, + instanceRules, +} from "../lib/config.js"; import { addToLog, exportICal } from "../helpers.js"; import Event from "../models/Event.js"; import EventGroup, { IEventGroup } from "../models/EventGroup.js"; @@ -26,6 +31,7 @@ router.get("/", (_: Request, res: Response) => { return res.render("home", { ...frontendConfig(res), instanceRules: instanceRules(), + instanceDescription: instanceDescription(), }); }); @@ -33,6 +39,7 @@ router.get("/about", (_: Request, res: Response) => { return res.render("home", { ...frontendConfig(res), instanceRules: instanceRules(), + instanceDescription: instanceDescription(), }); }); @@ -126,6 +133,8 @@ router.get("/events", async (_: Request, res: Response) => { upcomingEvents: upcomingEvents, pastEvents: pastEvents, eventGroups: updatedEventGroups, + instanceDescription: 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) |