From 032dc3c5e6d0ef84a9f4ea6be10e19b7f43c53b8 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 18 Mar 2023 19:42:37 +0900 Subject: feat(content): add /tags/ page --- nuldoc-src/commands/build.ts | 19 +++++++++-- nuldoc-src/pages/tag.ts | 7 +++- nuldoc-src/pages/tag_list.ts | 76 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 nuldoc-src/pages/tag_list.ts (limited to 'nuldoc-src') diff --git a/nuldoc-src/commands/build.ts b/nuldoc-src/commands/build.ts index d523861..911ff50 100644 --- a/nuldoc-src/commands/build.ts +++ b/nuldoc-src/commands/build.ts @@ -13,12 +13,14 @@ import { PostPage, } from "../pages/post.ts"; import { generatePostListPage } from "../pages/post_list.ts"; -import { generateTagPage } from "../pages/tag.ts"; +import { generateTagPage, TagPage } from "../pages/tag.ts"; +import { generateTagListPage } from "../pages/tag_list.ts"; export async function runBuildCommand(config: Config) { const posts = await buildPostPages(config); await buildPostListPage(posts, config); - await buildTagPages(posts, config); + const tags = await buildTagPages(posts, config); + await buildTagListPage(tags, config); await buildAboutPage(config); await buildNotFoundPage(config); await copyStaticFiles(config); @@ -71,12 +73,23 @@ async function buildNotFoundPage(config: Config) { await writePage(notFoundPage, config); } -async function buildTagPages(posts: PostPage[], config: Config) { +async function buildTagPages( + posts: PostPage[], + config: Config, +): Promise { const tagsAndPosts = collectTags(posts); + const tags = []; for (const [tag, posts] of tagsAndPosts) { const tagPage = await generateTagPage(tag, posts, config); await writePage(tagPage, config); + tags.push(tagPage); } + return tags; +} + +async function buildTagListPage(tags: TagPage[], config: Config) { + const tagListPage = await generateTagListPage(tags, config); + await writePage(tagListPage, config); } function collectTags(posts: PostPage[]): [string, PostPage[]][] { diff --git a/nuldoc-src/pages/tag.ts b/nuldoc-src/pages/tag.ts index c9eaf7e..b6f136a 100644 --- a/nuldoc-src/pages/tag.ts +++ b/nuldoc-src/pages/tag.ts @@ -6,7 +6,10 @@ import { el, text } from "../dom.ts"; import { Page } from "../page.ts"; import { getPostCreatedDate, getPostUpdatedDate, PostPage } from "./post.ts"; -export type TagPage = Page; +export interface TagPage extends Page { + tagSlug: string; + tagLabel: string; +} export async function generateTagPage( tagSlug: string, @@ -87,5 +90,7 @@ export async function generateTagPage( renderer: "html", destFilePath: `/tags/${tagSlug}/index.html`, href: `/tags/${tagSlug}/`, + tagSlug: tagSlug, + tagLabel: tagLabel, }; } diff --git a/nuldoc-src/pages/tag_list.ts b/nuldoc-src/pages/tag_list.ts new file mode 100644 index 0000000..e4e53f0 --- /dev/null +++ b/nuldoc-src/pages/tag_list.ts @@ -0,0 +1,76 @@ +import { globalFooter } from "../components/global_footer.ts"; +import { globalHeader } from "../components/global_header.ts"; +import { pageLayout } from "../components/page_layout.ts"; +import { Config } from "../config.ts"; +import { el, text } from "../dom.ts"; +import { Page } from "../page.ts"; +import { TagPage } from "./tag.ts"; + +export type TagListPage = Page; + +export async function generateTagListPage( + tags: TagPage[], + config: Config, +): Promise { + const pageTitle = "タグ一覧"; + + const body = el( + "body", + [["class", "list"]], + globalHeader(config), + el( + "main", + [["class", "main"]], + el( + "header", + [["class", "page-header"]], + el( + "h1", + [], + text(pageTitle), + ), + ), + ...Array.from(tags).sort((a, b) => { + const ta = a.tagSlug; + const tb = b.tagSlug; + if (ta > tb) return -1; + if (ta < tb) return 1; + return 0; + }).map((tag) => + el( + "article", + [["class", "post-entry"]], + el( + "a", + [["href", tag.href]], + el( + "header", + [["class", "entry-header"]], + el("h2", [], text(tag.tagLabel)), + ), + ), + ) + ), + ), + globalFooter(config), + ); + + const html = await pageLayout( + { + metaCopyrightYear: config.blog.siteCopyrightYear, + metaDescription: "タグの一覧", + metaKeywords: [], + metaTitle: pageTitle, + requiresSyntaxHighlight: false, + }, + body, + config, + ); + + return { + root: el("__root__", [], html), + renderer: "html", + destFilePath: "/tags/index.html", + href: "/tags/", + }; +} -- cgit v1.2.3-70-g09d2