diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-03-18 18:09:50 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-03-18 18:12:23 +0900 |
| commit | 12035272d44d92cd2360aeff88d499db67fe1949 (patch) | |
| tree | b9366110badb650b7d0af84330dd69df4bd71bcf /nuldoc-src/pages/tag.ts | |
| parent | b98d324fe7eb37e7004926843feede7e636c3301 (diff) | |
| download | blog.nsfisis.dev-12035272d44d92cd2360aeff88d499db67fe1949.tar.gz blog.nsfisis.dev-12035272d44d92cd2360aeff88d499db67fe1949.tar.zst blog.nsfisis.dev-12035272d44d92cd2360aeff88d499db67fe1949.zip | |
refactor: use Page instead of Document
Diffstat (limited to 'nuldoc-src/pages/tag.ts')
| -rw-r--r-- | nuldoc-src/pages/tag.ts | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/nuldoc-src/pages/tag.ts b/nuldoc-src/pages/tag.ts new file mode 100644 index 0000000..51aedcd --- /dev/null +++ b/nuldoc-src/pages/tag.ts @@ -0,0 +1,146 @@ +import { Config } from "../config.ts"; +import { Page } from "../page.ts"; +import { getPostCreatedDate, getPostUpdatedDate, PostPage } from "./post.ts"; +import { + el, + linkElement, + metaElement, + stylesheetLinkElement, + text, +} from "./utils.ts"; + +export type TagPage = Page; + +export async function generateTagPage( + tagSlug: string, + posts: PostPage[], + config: Config, +): Promise<TagPage> { + const tagLabel = + (config.blog.tagLabels as { [key: string]: string })[tagSlug]; + const pageTitle = `タグ「${tagLabel}」一覧`; + + 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", + `© ${ + getPostCreatedDate(posts[posts.length - 1]).substring(0, 4) + } ${config.blog.author}`, + ]]), + metaElement([["name", "description"], [ + "content", + `タグ「${tagLabel}」のついた記事一覧`, + ]]), + metaElement([["name", "keywords"], ["content", tagLabel]]), + linkElement("icon", "/favicon.svg", "image/svg+xml"), + el("title", [], text(`${pageTitle} | ${config.blog.siteName}`)), + await stylesheetLinkElement("/style.css", config), + ]; + const head = el("head", [], ...headChildren); + const body = el( + "body", + [["class", "list"]], + 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("header", [["class", "page-header"]], el("h1", [], text(pageTitle))), + ...posts.map((post) => + el( + "article", + [["class", "post-entry"]], + el( + "a", + [["href", post.href]], + 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", getPostCreatedDate(post)]], + text(getPostCreatedDate(post)), + ), + ...(post.revisions.length > 1 + ? [ + text(", updated on "), + el("time", [[ + "datetime", + getPostUpdatedDate(post), + ]], text(getPostUpdatedDate(post))), + ] + : []), + ), + ), + ) + ), + ), + el( + "footer", + [["class", "footer"]], + text( + `© ${config.blog.siteCopyrightYear} ${config.blog.author}`, + ), + ), + ); + const html = el( + "html", + [["lang", "ja-JP"]], + head, + body, + ); + + return { + root: el("__root__", [], html), + renderer: "html", + destFilePath: `/tags/${tagSlug}/index.html`, + href: `/tags/${tagSlug}/`, + }; +} |
