aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src/commands/build.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-03-18 15:54:53 +0900
committernsfisis <nsfisis@gmail.com>2023-03-18 16:17:21 +0900
commit2428ea512cdbac4b86189c654814c5eeca54a704 (patch)
tree70fb4eab0d0b87155112f4370853dbde387fd021 /nuldoc-src/commands/build.ts
parent2b50e1778b164e641c03c2e77176b6f47ca1e278 (diff)
downloadblog.nsfisis.dev-2428ea512cdbac4b86189c654814c5eeca54a704.tar.gz
blog.nsfisis.dev-2428ea512cdbac4b86189c654814c5eeca54a704.tar.zst
blog.nsfisis.dev-2428ea512cdbac4b86189c654814c5eeca54a704.zip
refactor: add Page type to represent single web page
Diffstat (limited to 'nuldoc-src/commands/build.ts')
-rw-r--r--nuldoc-src/commands/build.ts23
1 files changed, 18 insertions, 5 deletions
diff --git a/nuldoc-src/commands/build.ts b/nuldoc-src/commands/build.ts
index 8765802..90aaab9 100644
--- a/nuldoc-src/commands/build.ts
+++ b/nuldoc-src/commands/build.ts
@@ -3,8 +3,9 @@ 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 { writeHtmlFile } from "../html.ts";
import { Document } from "../docbook/document.ts";
+import { Page } from "../page.ts";
+import { render } from "../render.ts";
import convertPost from "../templates/post.ts";
import convertPostList from "../templates/post_list.ts";
import convertTag from "../templates/tag.ts";
@@ -58,7 +59,7 @@ async function outputPosts(posts: Document[], config: Config) {
"index.html",
);
await ensureDir(dirname(destFilePath));
- await writeHtmlFile(post, destFilePath);
+ await writePage(docToPage(post, destFilePath));
}
}
@@ -79,7 +80,7 @@ async function outputPostList(postList: Document, config: Config) {
const destDir = join(cwd, config.locations.destDir);
const destFilePath = join(destDir, "posts", "index.html");
await ensureDir(dirname(destFilePath));
- await writeHtmlFile(postList, destFilePath);
+ await writePage(docToPage(postList, destFilePath));
}
async function generateAboutPage(config: Config) {
@@ -92,7 +93,7 @@ async function outputAboutPage(about: Document, config: Config) {
const destDir = join(cwd, config.locations.destDir);
const destFilePath = join(destDir, "about", "index.html");
await ensureDir(dirname(destFilePath));
- await writeHtmlFile(about, destFilePath);
+ await writePage(docToPage(about, destFilePath));
}
async function generateTags(posts: Document[], config: Config) {
@@ -153,7 +154,7 @@ async function outputTags(tagDocs: [string, Document][], config: Config) {
for (const [tag, tagDoc] of tagDocs) {
const destFilePath = join(destDir, "tags", tag, "index.html");
await ensureDir(dirname(destFilePath));
- await writeHtmlFile(tagDoc, destFilePath);
+ await writePage(docToPage(tagDoc, destFilePath));
}
}
@@ -168,3 +169,15 @@ async function copyStaticFiles(config: Config) {
await Deno.copyFile(src, dst);
}
}
+
+async function writePage(page: Page) {
+ await Deno.writeTextFile(page.destFilePath, render(page.root, page.renderer));
+}
+
+function docToPage(d: Document, p: string): Page {
+ return {
+ root: d.root,
+ renderer: "html",
+ destFilePath: p,
+ };
+}