diff options
-rw-r--r-- | src/lib/config.ts | 26 | ||||
-rw-r--r-- | src/routes/frontend.ts | 31 | ||||
-rwxr-xr-x | views/home.handlebars | 12 |
3 files changed, 45 insertions, 24 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 4e6f3ed..86ad69c 100644 --- a/src/routes/frontend.ts +++ b/src/routes/frontend.ts @@ -3,7 +3,11 @@ 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"; @@ -27,6 +31,7 @@ router.get("/", (_: Request, res: Response) => { return res.render("home", { ...frontendConfig(res), instanceRules: instanceRules(), + instanceDescription: instanceDescription(), }); }); @@ -34,6 +39,7 @@ router.get("/about", (_: Request, res: Response) => { return res.render("home", { ...frontendConfig(res), instanceRules: instanceRules(), + instanceDescription: instanceDescription(), }); }); @@ -122,33 +128,12 @@ 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, + instanceDescription: instanceDescription(), instanceRules: instanceRules(), ...frontendConfig(res), }); diff --git a/views/home.handlebars b/views/home.handlebars index aa98823..0d294d3 100755 --- a/views/home.handlebars +++ b/views/home.handlebars @@ -1,8 +1,18 @@ <main class="page"> -<p class="lead text-center">Gathio is a simple, federated, privacy-first event hosting platform.</p> +<h2 class="mb-3 pb-2 text-center border-bottom">About {{siteName}}</h2> + +{{#if instanceDescription}} + <div class="instance-description mb-4"> + {{{instanceDescription}}} + </div> +{{/if}} {{> instanceRules }} +<h2 class="mb-3 mt-5 pb-2 text-center border-bottom">About Gathio</h2> + +<p class="lead text-center">Gathio is a simple, federated, privacy-first event hosting platform.</p> + <div id="example-event" class="text-center w-100 mt-4 mb-5"> <img alt ="An example event page for a picnic. The page shows the event's location, host, date and time, and description, as well as buttons to save the event to Google Calendar, export it, and open the location in OpenStreetMap and Google Maps." src="images/example-event-2023.png" class="img-fluid w-75 mx-auto shadow-lg rounded"> </div> |