diff options
author | Raphael Kabo <raphaelkabo@hey.com> | 2024-03-29 11:20:49 +0000 |
---|---|---|
committer | Raphael Kabo <raphaelkabo@hey.com> | 2024-05-26 16:05:32 +0100 |
commit | 0f6c06d3b37dbc277b211521a062223d96c540d0 (patch) | |
tree | 7b8dfe90b4c116028827186eaae5bd468e9fa406 /src/lib/config.ts | |
parent | 42fea055924bfa55991720f2f6b01ec111985200 (diff) |
Refactor instance description
Diffstat (limited to 'src/lib/config.ts')
-rw-r--r-- | src/lib/config.ts | 26 |
1 files changed, 26 insertions, 0 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 => { |