From f4a3e9bf53c657c3e6b9330eb6ad644094f75e61 Mon Sep 17 00:00:00 2001 From: LMBishop <13875753+LMBishop@users.noreply.github.com> Date: Sat, 20 Nov 2021 17:46:20 +0000 Subject: Initial commit --- app/directory.mjs | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 app/directory.mjs (limited to 'app/directory.mjs') diff --git a/app/directory.mjs b/app/directory.mjs new file mode 100644 index 0000000..8c0a36e --- /dev/null +++ b/app/directory.mjs @@ -0,0 +1,92 @@ +'use strict'; + +import { PAGES_DIR } from './constants.mjs'; +import { parse } from './wikiparser.mjs'; +import { readFileSync, readdirSync } from 'fs'; + +const pages = {}; +const metadata = {}; + +const PURGE_COOLDOWN_MIN = 10; + +export function pageFor(path) { + path = path.replace(/[^a-z0-9]/gi, '_').toLowerCase(); + let page = pages[path]; + if (!page) { + return undefined; + } + + if (!page.html) { + buildPage(path); + return pages[path]; + } + + return page; +} + +export function buildPage(path) { + let data = readFileSync(`${PAGES_DIR}/${path}.wiki`, 'utf-8'); + let result = parse(data); + let title = result.metadata.displayTitle ?? 'Unnamed page'; + let content = `