From a84908b7e8a0e2423afd6b836eccf27a420270b4 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 20 Sep 2023 19:56:52 +0900 Subject: feat(blog/nuldoc): change content format from DocBook to NulDoc --- vhosts/blog/nuldoc-src/ndoc/parse.ts | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 vhosts/blog/nuldoc-src/ndoc/parse.ts (limited to 'vhosts/blog/nuldoc-src/ndoc/parse.ts') diff --git a/vhosts/blog/nuldoc-src/ndoc/parse.ts b/vhosts/blog/nuldoc-src/ndoc/parse.ts new file mode 100644 index 00000000..419d2630 --- /dev/null +++ b/vhosts/blog/nuldoc-src/ndoc/parse.ts @@ -0,0 +1,47 @@ +import { parse as parseToml } from "std/encoding/toml.ts"; +import { Config } from "../config.ts"; +import { parseXmlString } from "../xml.ts"; +import { createNewDocumentFromRootElement, Document } from "./document.ts"; +import toHtml from "./to_html.ts"; + +export async function parseNulDocFile( + filePath: string, + config: Config, +): Promise { + try { + const fileContent = await Deno.readTextFile(filePath); + const parts = fileContent.split(/^---$/m); + const meta = parseMetaInfo(parts[1]); + const root = parseXmlString("" + parts[2]); + const doc = createNewDocumentFromRootElement(root, meta, filePath, config); + return toHtml(doc); + } catch (e) { + e.message = `${e.message} in ${filePath}`; + throw e; + } +} + +function parseMetaInfo(s: string): { + article: { + title: string; + description: string; + tags: string[]; + revisions: { + date: string; + remark: string; + }[]; + }; +} { + const root = parseToml(s) as { + article: { + title: string; + description: string; + tags: string[]; + revisions: { + date: string; + remark: string; + }[]; + }; + }; + return root; +} -- cgit v1.2.3-70-g09d2