An error occurred (<%= code %>)
+Go home?
+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/constants.mjs | 7 ++ app/directory.mjs | 92 +++++++++++++++ app/index.mjs | 94 +++++++++++++++ app/static/css/globalstyles.css | 76 ++++++++++++ app/static/scripts/purge.js | 15 +++ app/views/error.ejs | 16 +++ app/views/index.ejs | 15 +++ app/views/page.ejs | 17 +++ app/views/partials/header.ejs | 4 + app/views/purge.ejs | 21 ++++ app/views/rebuild.ejs | 17 +++ app/wikiparser.mjs | 254 ++++++++++++++++++++++++++++++++++++++++ 12 files changed, 628 insertions(+) create mode 100644 app/constants.mjs create mode 100644 app/directory.mjs create mode 100644 app/index.mjs create mode 100644 app/static/css/globalstyles.css create mode 100644 app/static/scripts/purge.js create mode 100644 app/views/error.ejs create mode 100644 app/views/index.ejs create mode 100644 app/views/page.ejs create mode 100644 app/views/partials/header.ejs create mode 100644 app/views/purge.ejs create mode 100644 app/views/rebuild.ejs create mode 100644 app/wikiparser.mjs (limited to 'app') diff --git a/app/constants.mjs b/app/constants.mjs new file mode 100644 index 0000000..98b1b03 --- /dev/null +++ b/app/constants.mjs @@ -0,0 +1,7 @@ +'use strict'; + +export const SERVER_PORT = 3000; +export const PARSER_MAX_RECURSION = 20; +export const PAGES_DIR = 'pages'; +export const TEMPLATE_DIR = 'pages/tempates'; +export const IMAGES_DIR = 'pages/images'; 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 = `
Go home?
+Are you sure you wish to purge the page <%= page %>?
+The last build time for this page was <%= buildTime %> (<%= buildTimeRelative %> minutes ago).
+ +Are you sure you wish to rebuild the page directory?
+ +| ${content} | `) + .replace(re(r`^ \|\+ (.*?) $`), (_, content) => `${content} | `) + .replace(re(r`^ \|- (.*?) $`), (_, attrs) => `
|---|---|
$1') + .replace(re(r` \`\` ([^\`]+?) \`\` `), '
$1')
+
+ // Spacing
+ .replace(/(\r?\n){2}/g, '\n\n') + + // Restore nowiki contents + .replace(/%NOWIKI#(\d+)%/g, (_, n) => htmlEscape(nowikis[n])); + } + metadata.buildTime = new Date(); + + let result = {}; + result.html = outText; + result.metadata = metadata; + return result; +} -- cgit v1.2.3-70-g09d2