summaryrefslogtreecommitdiffhomepage
path: root/vhosts/blog/nuldoc-src
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
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')
-rw-r--r--vhosts/blog/nuldoc-src/commands/build.ts8
-rw-r--r--vhosts/blog/nuldoc-src/commands/new.ts72
-rw-r--r--vhosts/blog/nuldoc-src/components/post_page_entry.ts2
-rw-r--r--vhosts/blog/nuldoc-src/docbook/document.ts108
-rw-r--r--vhosts/blog/nuldoc-src/docbook/parse.ts21
-rw-r--r--vhosts/blog/nuldoc-src/dom.ts6
-rw-r--r--vhosts/blog/nuldoc-src/ndoc/document.ts56
-rw-r--r--vhosts/blog/nuldoc-src/ndoc/parse.ts47
-rw-r--r--vhosts/blog/nuldoc-src/ndoc/to_html.ts (renamed from vhosts/blog/nuldoc-src/docbook/to_html.ts)96
-rw-r--r--vhosts/blog/nuldoc-src/pages/post.ts10
-rw-r--r--vhosts/blog/nuldoc-src/pages/slide.ts2
-rw-r--r--vhosts/blog/nuldoc-src/renderers/html.ts2
-rw-r--r--vhosts/blog/nuldoc-src/slide/parse.ts26
-rw-r--r--vhosts/blog/nuldoc-src/slide/slide.ts111
-rw-r--r--vhosts/blog/nuldoc-src/xml.ts4
15 files changed, 220 insertions, 351 deletions
diff --git a/vhosts/blog/nuldoc-src/commands/build.ts b/vhosts/blog/nuldoc-src/commands/build.ts
index da7e5cec..92230d7d 100644
--- a/vhosts/blog/nuldoc-src/commands/build.ts
+++ b/vhosts/blog/nuldoc-src/commands/build.ts
@@ -2,7 +2,7 @@ import { dirname, join, joinGlobs } from "std/path/mod.ts";
import { ensureDir } from "std/fs/mod.ts";
import { expandGlob } from "std/fs/expand_glob.ts";
import { Config } from "../config.ts";
-import { parseDocBookFile } from "../docbook/parse.ts";
+import { parseNulDocFile } from "../ndoc/parse.ts";
import { Page } from "../page.ts";
import { render } from "../render.ts";
import { dateToString } from "../revision.ts";
@@ -48,7 +48,7 @@ async function buildPostPages(config: Config): Promise<PostPage[]> {
async function collectPostFiles(sourceDir: string): Promise<string[]> {
const filePaths = [];
- const globPattern = joinGlobs([sourceDir, "**", "*.xml"]);
+ const globPattern = joinGlobs([sourceDir, "**", "*.ndoc"]);
for await (const entry of expandGlob(globPattern)) {
filePaths.push(entry.path);
}
@@ -62,7 +62,7 @@ async function parsePosts(
const posts = [];
for (const postFile of postFiles) {
posts.push(
- await generatePostPage(await parseDocBookFile(postFile, config), config),
+ await generatePostPage(await parseNulDocFile(postFile, config), config),
);
}
return posts;
@@ -85,7 +85,7 @@ async function buildSlidePages(config: Config): Promise<SlidePage[]> {
async function collectSlideFiles(sourceDir: string): Promise<string[]> {
const filePaths = [];
- const globPattern = joinGlobs([sourceDir, "**", "*.xml"]);
+ const globPattern = joinGlobs([sourceDir, "**", "*.toml"]);
for await (const entry of expandGlob(globPattern)) {
filePaths.push(entry.path);
}
diff --git a/vhosts/blog/nuldoc-src/commands/new.ts b/vhosts/blog/nuldoc-src/commands/new.ts
index 22329972..36125755 100644
--- a/vhosts/blog/nuldoc-src/commands/new.ts
+++ b/vhosts/blog/nuldoc-src/commands/new.ts
@@ -21,7 +21,7 @@ export async function runNewCommand(config: Config) {
config.locations.contentDir,
getDirPath(type),
ymd,
- "TODO.xml",
+ "TODO.ndoc",
);
await ensureDir(dirname(destFilePath));
@@ -39,54 +39,40 @@ function getDirPath(type: "post" | "slide"): string {
function getTemplate(type: "post" | "slide", date: string): string {
if (type === "post") {
- return `<?xml version="1.0" encoding="UTF-8"?>
-<article xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0">
- <info>
- <title>TODO</title>
- <abstract>
- TODO
- </abstract>
- <keywordset>
- <keyword>TODO</keyword>
- </keywordset>
- <revhistory>
- <revision>
- <date>${date}</date>
- <revremark>公開</revremark>
- </revision>
- </revhistory>
- </info>
- <section xml:id="TODO">
+ return `---
+[article]
+title = "TODO"
+description = "TODO"
+tags = [
+ "TODO",
+]
+
+[[article.revisions]]
+date = "${date}"
+remark = "公開"
+---
+<article>
+ <section id="TODO">
<title>TODO</title>
- <para>
+ <p>
TODO
- </para>
+ </p>
</section>
</article>
`;
} else {
- return `<?xml version="1.0" encoding="UTF-8"?>
-<slide>
- <info>
- <title>TODO</title>
- <event>
- TODO
- </event>
- <talktype>
- TODO
- </talktype>
- <link>TODO</link>
- <keywordset>
- <keyword>TODO</keyword>
- </keywordset>
- <revhistory>
- <revision>
- <date>${date}</date>
- <revremark>登壇</revremark>
- </revision>
- </revhistory>
- </info>
-</slide>
+ return `[slide]
+title = "TODO"
+event = "TODO"
+talkType = "TODO"
+link = "TODO"
+tags = [
+ "TODO",
+]
+
+[[slide.revisions]]
+date = "${date}"
+remark = "登壇"
`;
}
}
diff --git a/vhosts/blog/nuldoc-src/components/post_page_entry.ts b/vhosts/blog/nuldoc-src/components/post_page_entry.ts
index 685c03a8..bed7698a 100644
--- a/vhosts/blog/nuldoc-src/components/post_page_entry.ts
+++ b/vhosts/blog/nuldoc-src/components/post_page_entry.ts
@@ -21,7 +21,7 @@ export function postPageEntry(post: PostPage): Element {
el(
"section",
[["class", "entry-content"]],
- el("p", [], text(post.summary)),
+ el("p", [], text(post.description)),
),
el(
"footer",
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,
- };
-}
diff --git a/vhosts/blog/nuldoc-src/docbook/parse.ts b/vhosts/blog/nuldoc-src/docbook/parse.ts
deleted file mode 100644
index bce317e6..00000000
--- a/vhosts/blog/nuldoc-src/docbook/parse.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { Config } from "../config.ts";
-import { parseXmlFile } from "../xml.ts";
-import { DocBookError, XmlParseError } from "../errors.ts";
-import { createNewDocumentFromRootElement, Document } from "./document.ts";
-import toHtml from "./to_html.ts";
-
-export async function parseDocBookFile(
- filePath: string,
- config: Config,
-): Promise<Document> {
- try {
- const root = await parseXmlFile(filePath);
- const doc = createNewDocumentFromRootElement(root, filePath, config);
- return toHtml(doc);
- } catch (e) {
- if (e instanceof DocBookError || e instanceof XmlParseError) {
- e.message = `${e.message} in ${filePath}`;
- }
- throw e;
- }
-}
diff --git a/vhosts/blog/nuldoc-src/dom.ts b/vhosts/blog/nuldoc-src/dom.ts
index d8f53d76..1147f01b 100644
--- a/vhosts/blog/nuldoc-src/dom.ts
+++ b/vhosts/blog/nuldoc-src/dom.ts
@@ -53,12 +53,6 @@ export function findChildElements(e: Element, name: string): Element[] {
return cs;
}
-export function removeChildElements(e: Element, name: string) {
- e.children = e.children.filter((c) =>
- c.kind !== "element" || c.name !== name
- );
-}
-
export function innerText(e: Element): string {
let t = "";
forEachChild(e, (c) => {
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] <article> 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,
+ })),
+ };
+}
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<Document> {
+ try {
+ const fileContent = await Deno.readTextFile(filePath);
+ const parts = fileContent.split(/^---$/m);
+ const meta = parseMetaInfo(parts[1]);
+ const root = parseXmlString("<?xml ?>" + 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;
+}
diff --git a/vhosts/blog/nuldoc-src/docbook/to_html.ts b/vhosts/blog/nuldoc-src/ndoc/to_html.ts
index 4add912c..dc39919b 100644
--- a/vhosts/blog/nuldoc-src/docbook/to_html.ts
+++ b/vhosts/blog/nuldoc-src/ndoc/to_html.ts
@@ -10,30 +10,15 @@ import {
forEachChildRecursively,
Node,
RawHTML,
- removeChildElements,
Text,
} from "../dom.ts";
export default function toHtml(doc: Document): Document {
- removeArticleInfo(doc);
- removeArticleAttributes(doc);
removeUnnecessaryTextNode(doc);
- transformElementNames(doc, "emphasis", "em");
- transformElementNames(doc, "informaltable", "table");
- transformElementNames(doc, "itemizedlist", "ul");
- transformElementNames(doc, "link", "a");
- transformElementNames(doc, "listitem", "li");
- transformElementNames(doc, "literal", "code");
- transformElementNames(doc, "orderedlist", "ol");
- transformElementNames(doc, "para", "p");
- transformElementNames(doc, "superscript", "sup");
- transformAttributeNames(doc, "xml:id", "id");
- transformAttributeNames(doc, "xl:href", "href");
transformSectionIdAttribute(doc);
setSectionTitleAnchor(doc);
transformSectionTitleElement(doc);
- transformProgramListingElement(doc);
- transformLiteralLayoutElement(doc);
+ transformCodeBlockElement(doc);
transformNoteElement(doc);
setDefaultLangAttribute(doc);
traverseFootnotes(doc);
@@ -41,28 +26,6 @@ export default function toHtml(doc: Document): Document {
return doc;
}
-function removeArticleInfo(doc: Document) {
- const article = findFirstChildElement(doc.root, "article");
- if (!article) {
- throw new DocBookError(
- `[docbook.tohtml] <article> element not found`,
- );
- }
- removeChildElements(article, "info");
-}
-
-function removeArticleAttributes(doc: Document) {
- const article = findFirstChildElement(doc.root, "article");
- if (!article) {
- throw new DocBookError(
- `[docbook.tohtml] <article> element not found`,
- );
- }
- article.attributes.delete("xmlns");
- article.attributes.delete("xmlns:xl");
- article.attributes.delete("version");
-}
-
function removeUnnecessaryTextNode(doc: Document) {
const g = (n: Node) => {
if (n.kind !== "element") {
@@ -95,35 +58,6 @@ function removeUnnecessaryTextNode(doc: Document) {
forEachChild(doc.root, g);
}
-function transformElementNames(
- doc: Document,
- from: string,
- to: string,
-) {
- forEachChildRecursively(doc.root, (n) => {
- if (n.kind === "element" && n.name === from) {
- n.name = to;
- }
- });
-}
-
-function transformAttributeNames(
- doc: Document,
- from: string,
- to: string,
-) {
- forEachChildRecursively(doc.root, (n) => {
- if (n.kind !== "element") {
- return;
- }
- const value = n.attributes.get(from) as string;
- if (value !== undefined) {
- n.attributes.delete(from);
- n.attributes.set(to, value);
- }
- });
-}
-
function transformSectionIdAttribute(doc: Document) {
forEachChildRecursively(doc.root, (n) => {
if (n.kind !== "element" || n.name !== "section") {
@@ -149,11 +83,11 @@ function setSectionTitleAnchor(doc: Document) {
if (c.name === "section") {
sectionStack.pop();
}
- if (c.name === "title") {
+ if (c.name === "h") {
const currentSection = sectionStack[sectionStack.length - 1];
if (!currentSection) {
throw new DocBookError(
- "[docbook.tohtml] <title> element must be inside <section>",
+ "[docbook.tohtml] <h> element must be inside <section>",
);
}
const sectionId = currentSection.attributes.get("id");
@@ -185,34 +119,16 @@ function transformSectionTitleElement(doc: Document) {
if (c.name === "section") {
sectionLevel -= 1;
}
- if (c.name === "title") {
+ if (c.name === "h") {
c.name = `h${sectionLevel}`;
}
};
forEachChild(doc.root, g);
}
-function transformProgramListingElement(doc: Document) {
- forEachChildRecursively(doc.root, (n) => {
- if (n.kind !== "element" || n.name !== "programlisting") {
- return;
- }
-
- n.name = "pre";
- addClass(n, "highlight");
- const codeElement: Element = {
- kind: "element",
- name: "code",
- attributes: new Map(),
- children: n.children,
- };
- n.children = [codeElement];
- });
-}
-
-function transformLiteralLayoutElement(doc: Document) {
+function transformCodeBlockElement(doc: Document) {
forEachChildRecursively(doc.root, (n) => {
- if (n.kind !== "element" || n.name !== "literallayout") {
+ if (n.kind !== "element" || n.name !== "codeblock") {
return;
}
diff --git a/vhosts/blog/nuldoc-src/pages/post.ts b/vhosts/blog/nuldoc-src/pages/post.ts
index 24a6d5f5..ade0916a 100644
--- a/vhosts/blog/nuldoc-src/pages/post.ts
+++ b/vhosts/blog/nuldoc-src/pages/post.ts
@@ -4,13 +4,13 @@ import { globalHeader } from "../components/global_header.ts";
import { pageLayout } from "../components/page_layout.ts";
import { Config, getTagLabel } from "../config.ts";
import { el, Element, text } from "../dom.ts";
-import { Document } from "../docbook/document.ts";
+import { Document } from "../ndoc/document.ts";
import { Page } from "../page.ts";
import { Date, dateToString, Revision } from "../revision.ts";
export interface PostPage extends Page {
title: string;
- summary: string;
+ description: string;
tags: string[];
revisions: Revision[];
}
@@ -112,7 +112,7 @@ export async function generatePostPage(
const html = await pageLayout(
{
metaCopyrightYear: getPostCreatedDate(doc).year,
- metaDescription: doc.summary,
+ metaDescription: doc.description,
metaKeywords: doc.tags.map((slug) => getTagLabel(config, slug)),
metaTitle: `${doc.title} | ${config.blog.siteName}`,
requiresSyntaxHighlight: true,
@@ -124,7 +124,7 @@ export async function generatePostPage(
const cwd = Deno.cwd();
const contentDir = join(cwd, config.locations.contentDir);
const destFilePath = join(
- doc.sourceFilePath.replace(contentDir, "").replace(".xml", ""),
+ doc.sourceFilePath.replace(contentDir, "").replace(".ndoc", ""),
"index.html",
);
return {
@@ -133,7 +133,7 @@ export async function generatePostPage(
destFilePath: destFilePath,
href: destFilePath.replace("index.html", ""),
title: doc.title,
- summary: doc.summary,
+ description: doc.description,
tags: doc.tags,
revisions: doc.revisions,
};
diff --git a/vhosts/blog/nuldoc-src/pages/slide.ts b/vhosts/blog/nuldoc-src/pages/slide.ts
index a75aeb68..ad56fee3 100644
--- a/vhosts/blog/nuldoc-src/pages/slide.ts
+++ b/vhosts/blog/nuldoc-src/pages/slide.ts
@@ -122,7 +122,7 @@ export async function generateSlidePage(
const cwd = Deno.cwd();
const contentDir = join(cwd, config.locations.contentDir);
const destFilePath = join(
- slide.sourceFilePath.replace(contentDir, "").replace(".xml", ""),
+ slide.sourceFilePath.replace(contentDir, "").replace(".toml", ""),
"index.html",
);
return {
diff --git a/vhosts/blog/nuldoc-src/renderers/html.ts b/vhosts/blog/nuldoc-src/renderers/html.ts
index 3b6c6ebc..d3cd9893 100644
--- a/vhosts/blog/nuldoc-src/renderers/html.ts
+++ b/vhosts/blog/nuldoc-src/renderers/html.ts
@@ -87,6 +87,8 @@ function getDtd(name: string): Dtd {
return { type: "block" };
case "span":
return { type: "inline" };
+ case "strong":
+ return { type: "inline" };
case "sup":
return { type: "inline" };
case "table":
diff --git a/vhosts/blog/nuldoc-src/slide/parse.ts b/vhosts/blog/nuldoc-src/slide/parse.ts
index 00ff645f..45ac6388 100644
--- a/vhosts/blog/nuldoc-src/slide/parse.ts
+++ b/vhosts/blog/nuldoc-src/slide/parse.ts
@@ -1,19 +1,29 @@
+import { parse as parseToml } from "std/encoding/toml.ts";
import { Config } from "../config.ts";
-import { parseXmlFile } from "../xml.ts";
-import { SlideError, XmlParseError } from "../errors.ts";
-import { createNewSlideFromRootElement, Slide } from "./slide.ts";
+import { createNewSlideFromTomlRootObject, Slide } from "./slide.ts";
export async function parseSlideFile(
filePath: string,
config: Config,
): Promise<Slide> {
try {
- const root = await parseXmlFile(filePath);
- return createNewSlideFromRootElement(root, filePath, config);
+ // TODO runtime assertion
+ const root = parseToml(await Deno.readTextFile(filePath)) as {
+ slide: {
+ title: string;
+ event: string;
+ talkType: string;
+ link: string;
+ tags: string[];
+ revisions: {
+ date: string;
+ remark: string;
+ }[];
+ };
+ };
+ return createNewSlideFromTomlRootObject(root, filePath, config);
} catch (e) {
- if (e instanceof SlideError || e instanceof XmlParseError) {
- e.message = `${e.message} in ${filePath}`;
- }
+ e.message = `${e.message} in ${filePath}`;
throw e;
}
}
diff --git a/vhosts/blog/nuldoc-src/slide/slide.ts b/vhosts/blog/nuldoc-src/slide/slide.ts
index a982d4f2..5d5f30eb 100644
--- a/vhosts/blog/nuldoc-src/slide/slide.ts
+++ b/vhosts/blog/nuldoc-src/slide/slide.ts
@@ -1,12 +1,6 @@
import { Config } from "../config.ts";
import { SlideError } from "../errors.ts";
import { Revision, stringToDate } from "../revision.ts";
-import {
- Element,
- findChildElements,
- findFirstChildElement,
- innerText,
-} from "../dom.ts";
export type Slide = {
sourceFilePath: string;
@@ -18,105 +12,102 @@ export type Slide = {
revisions: Revision[];
};
-export function createNewSlideFromRootElement(
- root: Element,
+type Toml = {
+ slide: {
+ title: string;
+ event: string;
+ talkType: string;
+ link: string;
+ tags: string[];
+ revisions: {
+ date: string;
+ remark: string;
+ }[];
+ };
+};
+
+export function createNewSlideFromTomlRootObject(
+ root: Toml,
sourceFilePath: string,
_config: Config,
): Slide {
- const slide = findFirstChildElement(root, "slide");
- if (!slide) {
+ const slide = root.slide ?? null;
+ if (root.slide === undefined) {
throw new SlideError(
- `[slide.new] <slide> element not found`,
- );
- }
- const info = findFirstChildElement(slide, "info");
- if (!info) {
- throw new SlideError(
- `[slide.new] <info> element not found`,
+ `[slide.new] 'slide' field not found`,
);
}
- const titleElement = findFirstChildElement(info, "title");
- if (!titleElement) {
+ const title = slide.title ?? null;
+ if (!title) {
throw new SlideError(
- `[slide.new] <title> element not found`,
+ `[slide.new] 'slide.title' field not found`,
);
}
- const title = innerText(titleElement).trim();
- const eventElement = findFirstChildElement(info, "event");
- if (!eventElement) {
+ const event = slide.event ?? null;
+ if (!event) {
throw new SlideError(
- `[slide.new] <event> element not found`,
+ `[slide.new] 'slide.event' field not found`,
);
}
- const event = innerText(eventElement).trim();
- const talkTypeElement = findFirstChildElement(info, "talktype");
- if (!talkTypeElement) {
+ const talkType = slide.talkType ?? null;
+ if (!talkType) {
throw new SlideError(
- `[slide.new] <talktype> element not found`,
+ `[slide.new] 'slide.talkType' field not found`,
);
}
- const talkType = innerText(talkTypeElement).trim();
- const slideLinkElement = findFirstChildElement(info, "link");
- if (!slideLinkElement) {
+ const link = slide.link ?? null;
+ if (!link) {
throw new SlideError(
- `[slide.new] <link> element not found`,
+ `[slide.new] 'slide.link' field not found`,
);
}
- const slideLink = innerText(slideLinkElement).trim();
- const keywordsetElement = findFirstChildElement(info, "keywordset");
- let tags: string[];
- if (!keywordsetElement) {
- tags = [];
- } else {
- tags = findChildElements(keywordsetElement, "keyword").map((x) =>
- innerText(x).trim()
+ const tags = slide.tags ?? [];
+
+ const revisions = slide.revisions ?? null;
+ if (!revisions) {
+ throw new SlideError(
+ `[slide.new] 'slide.revisions' field not found`,
);
}
- const revhistoryElement = findFirstChildElement(info, "revhistory");
- if (!revhistoryElement) {
+ if (revisions.length === 0) {
throw new SlideError(
- `[slide.new] <revhistory> element not found`,
+ `[slide.new] 'slide.revisions' field not found`,
);
}
- const revisions = findChildElements(revhistoryElement, "revision").map(
- (x, i) => {
- const dateElement = findFirstChildElement(x, "date");
- if (!dateElement) {
+ const revisions_ = revisions.map(
+ (x: { date: string; remark: string }, i: number) => {
+ const date = x.date ?? null;
+ if (!date) {
throw new SlideError(
- `[slide.new] <date> element not found`,
+ `[slide.new] 'date' field not found`,
);
}
- const revremarkElement = findFirstChildElement(x, "revremark");
- if (!revremarkElement) {
+ const remark = x.remark ?? null;
+ if (!remark) {
throw new SlideError(
- `[slide.new] <revremark> element not found`,
+ `[slide.new] 'remark' field not found`,
);
}
return {
number: i + 1,
- date: stringToDate(innerText(dateElement).trim()),
- remark: innerText(revremarkElement).trim(),
+ date: stringToDate(date),
+ remark: remark,
};
},
);
- if (revisions.length === 0) {
- throw new SlideError(
- `[slide.new] <revision> element not found`,
- );
- }
return {
sourceFilePath: sourceFilePath,
title: title,
event: event,
talkType: talkType,
- slideLink: slideLink,
+ slideLink: link,
tags: tags,
- revisions: revisions,
+ revisions: revisions_,
};
}
diff --git a/vhosts/blog/nuldoc-src/xml.ts b/vhosts/blog/nuldoc-src/xml.ts
index 847b5e12..9f53ef8c 100644
--- a/vhosts/blog/nuldoc-src/xml.ts
+++ b/vhosts/blog/nuldoc-src/xml.ts
@@ -1,10 +1,6 @@
import { Element, Node, Text } from "./dom.ts";
import { XmlParseError } from "./errors.ts";
-export async function parseXmlFile(filePath: string): Promise<Element> {
- return parseXmlString(await Deno.readTextFile(filePath));
-}
-
export function parseXmlString(source: string): Element {
return parse({ source: source, index: 0 });
}