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/document.ts | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 vhosts/blog/nuldoc-src/ndoc/document.ts (limited to 'vhosts/blog/nuldoc-src/ndoc/document.ts') diff --git a/vhosts/blog/nuldoc-src/ndoc/document.ts b/vhosts/blog/nuldoc-src/ndoc/document.ts new file mode 100644 index 00000000..31bae616 --- /dev/null +++ b/vhosts/blog/nuldoc-src/ndoc/document.ts @@ -0,0 +1,56 @@ +import { join } from "std/path/mod.ts"; +import { Config } from "../config.ts"; +import { DocBookError } from "../errors.ts"; +import { Revision, stringToDate } from "../revision.ts"; +import { Element, findFirstChildElement } from "../dom.ts"; + +export type Document = { + root: Element; + sourceFilePath: string; + link: string; + title: string; + description: string; // TODO: should it be markup text? + tags: string[]; + revisions: Revision[]; +}; + +export function createNewDocumentFromRootElement( + root: Element, + meta: { + article: { + title: string; + description: string; + tags: string[]; + revisions: { + date: string; + remark: string; + }[]; + }; + }, + sourceFilePath: string, + config: Config, +): Document { + const article = findFirstChildElement(root, "article"); + if (!article) { + throw new DocBookError( + `[docbook.new]
element not found`, + ); + } + + const cwd = Deno.cwd(); + const contentDir = join(cwd, config.locations.contentDir); + const link = sourceFilePath.replace(contentDir, "").replace(".xml", "/"); + return { + root: root, + sourceFilePath: sourceFilePath, + link: link, + title: meta.article.title, + description: meta.article.description, + tags: meta.article.tags, + revisions: meta.article.revisions.map((r, i) => ({ + number: i, + date: stringToDate(r.date), + remark: r.remark, + })), + }; +} -- cgit v1.2.3-70-g09d2