summaryrefslogtreecommitdiffhomepage
path: root/vhosts/blog/nuldoc-src/docbook/document.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-09-20 19:56:52 +0900
committernsfisis <nsfisis@gmail.com>2023-09-20 19:56:57 +0900
commita84908b7e8a0e2423afd6b836eccf27a420270b4 (patch)
tree00204b62358f8c57fcb36f601db360626484cc1a /vhosts/blog/nuldoc-src/docbook/document.ts
parent0b488f85380f964c40b0b9aae69c6611bc7978bc (diff)
downloadnsfisis.dev-a84908b7e8a0e2423afd6b836eccf27a420270b4.tar.gz
nsfisis.dev-a84908b7e8a0e2423afd6b836eccf27a420270b4.tar.zst
nsfisis.dev-a84908b7e8a0e2423afd6b836eccf27a420270b4.zip
feat(blog/nuldoc): change content format from DocBook to NulDoc
Diffstat (limited to 'vhosts/blog/nuldoc-src/docbook/document.ts')
-rw-r--r--vhosts/blog/nuldoc-src/docbook/document.ts108
1 files changed, 0 insertions, 108 deletions
diff --git a/vhosts/blog/nuldoc-src/docbook/document.ts b/vhosts/blog/nuldoc-src/docbook/document.ts
deleted file mode 100644
index 677c8275..00000000
--- a/vhosts/blog/nuldoc-src/docbook/document.ts
+++ /dev/null
@@ -1,108 +0,0 @@
-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,
- findChildElements,
- findFirstChildElement,
- innerText,
-} from "../dom.ts";
-
-export type Document = {
- root: Element;
- sourceFilePath: string;
- link: string;
- title: string;
- summary: string; // TODO: should it be markup text?
- tags: string[];
- revisions: Revision[];
-};
-
-export function createNewDocumentFromRootElement(
- root: Element,
- sourceFilePath: string,
- config: Config,
-): Document {
- const article = findFirstChildElement(root, "article");
- if (!article) {
- throw new DocBookError(
- `[docbook.new] <article> element not found`,
- );
- }
- const info = findFirstChildElement(article, "info");
- if (!info) {
- throw new DocBookError(
- `[docbook.new] <info> element not found`,
- );
- }
-
- const titleElement = findFirstChildElement(info, "title");
- if (!titleElement) {
- throw new DocBookError(
- `[docbook.new] <title> element not found`,
- );
- }
- const title = innerText(titleElement).trim();
- const abstractElement = findFirstChildElement(info, "abstract");
- if (!abstractElement) {
- throw new DocBookError(
- `[docbook.new] <abstract> element not found`,
- );
- }
- const summary = innerText(abstractElement).trim();
- const keywordsetElement = findFirstChildElement(info, "keywordset");
- let tags: string[];
- if (!keywordsetElement) {
- tags = [];
- } else {
- tags = findChildElements(keywordsetElement, "keyword").map((x) =>
- innerText(x).trim()
- );
- }
- const revhistoryElement = findFirstChildElement(info, "revhistory");
- if (!revhistoryElement) {
- throw new DocBookError(
- `[docbook.new] <revhistory> element not found`,
- );
- }
- const revisions = findChildElements(revhistoryElement, "revision").map(
- (x, i) => {
- const dateElement = findFirstChildElement(x, "date");
- if (!dateElement) {
- throw new DocBookError(
- `[docbook.new] <date> element not found`,
- );
- }
- const revremarkElement = findFirstChildElement(x, "revremark");
- if (!revremarkElement) {
- throw new DocBookError(
- `[docbook.new] <revremark> element not found`,
- );
- }
- return {
- number: i + 1,
- date: stringToDate(innerText(dateElement).trim()),
- remark: innerText(revremarkElement).trim(),
- };
- },
- );
- if (revisions.length === 0) {
- throw new DocBookError(
- `[docbook.new] <revision> 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: title,
- summary: summary,
- tags: tags,
- revisions: revisions,
- };
-}