diff options
| author | nsfisis <nsfisis@gmail.com> | 2022-12-23 23:27:09 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-03-06 01:46:04 +0900 |
| commit | 88ba6cfe220216f371f8756921059fac51a21262 (patch) | |
| tree | f272db2a0a3340f103df6618f19a101e65941b37 /nuldoc-src/templates/tag.ts | |
| parent | 8f988a6e899aed678406ddfac1be4ef105439274 (diff) | |
| download | blog.nsfisis.dev-88ba6cfe220216f371f8756921059fac51a21262.tar.gz blog.nsfisis.dev-88ba6cfe220216f371f8756921059fac51a21262.tar.zst blog.nsfisis.dev-88ba6cfe220216f371f8756921059fac51a21262.zip | |
AsciiDoc to DocBook
Diffstat (limited to 'nuldoc-src/templates/tag.ts')
| -rw-r--r-- | nuldoc-src/templates/tag.ts | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/nuldoc-src/templates/tag.ts b/nuldoc-src/templates/tag.ts new file mode 100644 index 0000000..c3080e8 --- /dev/null +++ b/nuldoc-src/templates/tag.ts @@ -0,0 +1,137 @@ +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 convertTag( + tag: string, + posts: Document[], + config: Config, +): Promise<Document> { + const tagLabel = (config.blog.tagLabels as { [key: string]: string })[tag]; + + const doc = { + root: el("__root__", []), + sourceFilePath: `<tag:${tag}>`, + link: `/tags/${tag}/`, + title: tagLabel, + summary: `タグ「${tagLabel}」のついた記事一覧`, + tags: [], + revisions: [], + }; + + const headChildren = [ + 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", + `© ${ + posts[posts.length - 1].revisions[0].date.substring(0, 4) + } ${config.blog.author}`, + ]]), + metaElement([["name", "description"], [ + "content", + doc.summary, + ]]), + metaElement([["name", "keywords"], ["content", tagLabel]]), + linkElement("icon", "/favicon.svg", "image/svg+xml"), + el("title", [], text(`${doc.title} | ${config.blog.siteName}`)), + await stylesheetLinkElement("/hl.css", config), + await stylesheetLinkElement("/style.css", config), + await stylesheetLinkElement("/custom.css", config), + ]; + const head = el("head", [], ...headChildren); + const body = el( + "body", + [["class", "list"]], + el( + "header", + [["class", "header"]], + el( + "nav", + [["class", "nav"]], + el( + "p", + [["class", "logo"]], + el("a", [["href", "/"]], text(config.blog.siteName)), + ), + ), + ), + el( + "main", + [["class", "main"]], + el("header", [["class", "page-header"]], el("h1", [], text(tagLabel))), + ...posts.map((post) => + el( + "article", + [["class", "post-entry"]], + el( + "a", + [["href", post.link]], + el( + "header", + [["class", "entry-header"]], + el("h2", [], text(post.title)), + ), + el( + "section", + [["class", "entry-content"]], + el("p", [], text(post.summary)), + ), + el( + "footer", + [["class", "entry-footer"]], + text("Posted on"), + el( + "time", + [["datetime", post.revisions[0].date]], + text(post.revisions[0].date), + ), + ...(post.revisions.length > 1 + ? [ + text(", updated on "), + el("time", [[ + "datetime", + post.revisions[post.revisions.length - 1].date, + ]], text(post.revisions[post.revisions.length - 1].date)), + ] + : []), + ), + ), + ) + ), + ), + el( + "footer", + [["class", "footer"]], + text( + `© ${config.blog.siteCopyrightYear} ${config.blog.author}`, + ), + ), + ); + const html = el( + "html", + [["lang", "ja-JP"]], + head, + body, + ); + + doc.root.children = [html]; + return doc; +} |
