From ee72f8780cf3681e4202cc3a6358fb4038db1ec8 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 17 Mar 2023 01:03:59 +0900 Subject: feat(nuldoc): implement /about/ page (work in progress) --- nuldoc-src/command.ts | 15 ++++++ nuldoc-src/templates/about.ts | 123 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 nuldoc-src/templates/about.ts (limited to 'nuldoc-src') diff --git a/nuldoc-src/command.ts b/nuldoc-src/command.ts index 70532d4..57e4820 100644 --- a/nuldoc-src/command.ts +++ b/nuldoc-src/command.ts @@ -10,6 +10,7 @@ import { Document } from "./docbook/document.ts"; import convertPost from "./templates/post.ts"; import convertPostList from "./templates/post_list.ts"; import convertTag from "./templates/tag.ts"; +import generateAbout from "./templates/about.ts"; export async function run(command: string, config: Config) { if (command === "build") { @@ -25,6 +26,7 @@ async function cmdBuild(config: Config) { const posts = await generatePosts(config); await generateTags(posts, config); await generatePostList(posts, config); + await generateAboutPage(config); await copyStaticFiles(config); } @@ -110,6 +112,19 @@ async function outputPostList(postList: Document, config: Config) { await writeHtmlFile(postList, destFilePath); } +async function generateAboutPage(config: Config) { + const aboutDoc = await generateAbout(config); + await outputAboutPage(aboutDoc, config); +} + +async function outputAboutPage(about: Document, config: Config) { + const cwd = Deno.cwd(); + const destDir = join(cwd, config.locations.destDir); + const destFilePath = join(destDir, "about", "index.html"); + await ensureDir(dirname(destFilePath)); + await writeHtmlFile(about, destFilePath); +} + async function generateTags(posts: Document[], config: Config) { const tagsAndPosts = collectTags(posts); const tagDocs = await buildTagDocs(tagsAndPosts, config); diff --git a/nuldoc-src/templates/about.ts b/nuldoc-src/templates/about.ts new file mode 100644 index 0000000..c41418c --- /dev/null +++ b/nuldoc-src/templates/about.ts @@ -0,0 +1,123 @@ +import { Element } from "../dom.ts"; +import { Document } from "../docbook/document.ts"; +import { Config } from "../config.ts"; +import { el, stylesheetLinkElement, text } from "./utils.ts"; + +function metaElement(attrs: [string, string][]): Element { + return el("meta", attrs); +} + +function linkElement(rel: string, href: string, type: string | null): Element { + const attrs: [string, string][] = [["rel", rel], ["href", href]]; + if (type !== null) { + attrs.push(["type", type]); + } + return el("link", attrs); +} + +export default async function generateAbout( + config: Config, +): Promise { + const head = el( + "head", + [], + metaElement([["charset", "UTF-8"]]), + metaElement([["name", "viewport"], [ + "content", + "width=device-width, initial-scale=1.0", + ]]), + metaElement([["name", "author"], ["content", config.blog.author]]), + metaElement([["name", "copyright"], [ + "content", + `© ${config.blog.siteCopyrightYear} ${config.blog.author}`, + ]]), + metaElement([["name", "description"], [ + "content", + "このサイトの著者について", + ]]), + linkElement("icon", "/favicon.svg", "image/svg+xml"), + el("title", [], text(`About | ${config.blog.siteName}`)), + await stylesheetLinkElement("/style.css", config), + ); + const body = el( + "body", + [["class", "single"]], + el( + "header", + [["class", "header"]], + el( + "nav", + [["class", "nav"]], + el( + "ul", + [], + el( + "li", + [["class", "logo"]], + el("a", [["href", "/"]], text(config.blog.siteName)), + ), + el( + "li", + [], + el("a", [["href", "/about"]], text("About")), + ), + el( + "li", + [], + el("a", [["href", "/posts"]], text("Posts")), + ), + el( + "li", + [], + el("a", [["href", "/slides"]], text("Slides")), + ), + ), + ), + ), + el( + "main", + [["class", "main"]], + el( + "article", + [["class", "post-single"]], + el( + "header", + [["class", "post-header"]], + el( + "h1", + [["class", "post-title"]], + text("About"), + ), + ), + el( + "div", + [["class", "post-content"]], + text("WIP"), + ), + ), + ), + el( + "footer", + [["class", "footer"]], + text( + `© ${config.blog.siteCopyrightYear} ${config.blog.author}`, + ), + ), + ); + const html = el( + "html", + [["lang", "ja-JP"]], + head, + body, + ); + const doc = { + root: el("__root__", [], html), + sourceFilePath: "", + link: "/about/", + title: "About", + summary: "このサイトの著者について", + tags: [], + revisions: [], + }; + return doc; +} -- cgit v1.2.3-70-g09d2