From: Lady Date: Fri, 28 Jul 2023 09:24:29 +0000 (-0700) Subject: Move symbol definition into external config file X-Git-Tag: 0.2.0~1 X-Git-Url: https://git.ladys.computer/GitWikiWeb/commitdiff_plain/723e420d74a7792435cfc6ff7714acef25a8dcf3?ds=sidebyside;hp=50f9a55cd48d652f15a913237c166af00e554186 Move symbol definition into external config file This file is planned to be used for other site configuration as well. --- diff --git a/build.js b/build.js index df9c016..e8b7003 100644 --- a/build.js +++ b/build.js @@ -37,7 +37,11 @@ import { emptyDir, ensureDir, -} from "https://deno.land/std@0.195.0/fs/mod.ts"; +} from "https://deno.land/std@0.196.0/fs/mod.ts"; +import { + JSON_SCHEMA, + parse as parseYaml, +} from "https://deno.land/std@0.196.0/yaml/mod.ts"; import djot from "npm:@djot/djot@0.2.3"; import { Parser } from "npm:htmlparser2@9.0.0"; import { DomHandler, Element, Text } from "npm:domhandler@5.0.3"; @@ -217,7 +221,7 @@ class GitWikiWebPage { #internalLinks = new Set(); #externalLinks = new Map(); - constructor(namespace, name, ast, source) { + constructor(namespace, name, ast, source, config) { const internalLinks = this.#internalLinks; const externalLinks = this.#externalLinks; const sections = Object.create(null); @@ -480,23 +484,8 @@ class GitWikiWebPage { String.fromCodePoint(parseInt(codepoint, 16)) }`; } else { - return { - "--8": str`${"—\u2060:\u202F"}`, // reverse puppyprick - "8--": str`${"\u202F:\u2060—"}`, // forward puppyprick - sp: rawInline` `, // space - nbsp: str`${"\xA0"}`, // no‐break space - cgj: str`${"\u034F"}`, // combining grapheme joiner - ensp: str`${"\u2002"}`, // enspace - emsp: str`${"\u2003"}`, // emspace - figsp: str`${"\u2007"}`, // figure space - zwsp: str`${"\u200B"}`, // zero‐width space - zwnj: str`${"\u200C"}`, // zero‐width nonjoiner - zwj: str`${"\u200D"}`, // zero‐width joiner - nnbsp: str`${"\u202F"}`, // narrow no‐break space - mathsp: str`${"\u205F"}`, // math space - wj: str`${"\u2060"}`, // word joiner - fwsp: str`${"\u3000"}`, // fullwidth space - }[alias] ?? e; + const resolved = config.symbols?.[alias]; + return resolved != null ? str`${resolved}` : e; } }, }, @@ -524,6 +513,9 @@ class GitWikiWebPage { } { + const config = await getRemoteContent("config.yaml").then((yaml) => + parseYaml(yaml, { schema: JSON_SCHEMA }) + ); const ls = new Deno.Command("git", { args: ["ls-tree", "-rz", "live"], stdout: "piped", @@ -597,6 +589,7 @@ class GitWikiWebPage { console.warn(`Djot(${reference}): ${$.render()}`), }), source, + config, ); const reference = `${namespace}:${pageName}`; pages.set(reference, page); @@ -618,6 +611,7 @@ class GitWikiWebPage { console.warn(`Djot(${reference}): ${$.render()}`), }), source, + config, ); pages.set(reference, page); } diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..555db2b --- /dev/null +++ b/config.yaml @@ -0,0 +1,16 @@ +# Modify this file to configure your GitWikiWeb instance. +symbols: + nbsp: "\xA0" # no‐break space + cgj: "\u034F" # combining grapheme joiner + ensp: "\u2002" # enspace + emsp: "\u2003" # emspace + figsp: "\u2007" # figure space + zwsp: "\u200B" # zero‐width space + zwnj: "\u200C" # zero‐width nonjoiner + zwj: "\u200D" # zero‐width joiner + nnbsp: "\u202F" # narrow no‐break space + mathsp: "\u205F" # math space + wj: "\u2060" # word joiner + fwsp: "\u3000" # fullwidth space + as_text: "\uFE0E" # text variation + as_emoji: "\uFE0F" # emoji variation