From 2ee549f5f3b1a05f2a769a4e0daa5507997a3159 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 18 Mar 2023 21:27:42 +0900 Subject: feat(nuldoc): include slides in tag pages --- nuldoc-src/commands/build.ts | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'nuldoc-src/commands') diff --git a/nuldoc-src/commands/build.ts b/nuldoc-src/commands/build.ts index 8091938..8961da9 100644 --- a/nuldoc-src/commands/build.ts +++ b/nuldoc-src/commands/build.ts @@ -17,6 +17,7 @@ import { generatePostListPage } from "../pages/post_list.ts"; import { generateSlidePage, SlidePage } from "../pages/slide.ts"; import { generateSlideListPage } from "../pages/slide_list.ts"; import { generateTagPage, TagPage } from "../pages/tag.ts"; +import { TaggedPage } from "../pages/tagged_page.ts"; import { generateTagListPage } from "../pages/tag_list.ts"; import { parseSlideFile } from "../slide/parse.ts"; @@ -25,7 +26,7 @@ export async function runBuildCommand(config: Config) { await buildPostListPage(posts, config); const slides = await buildSlidePages(config); await buildSlideListPage(slides, config); - const tags = await buildTagPages(posts, config); + const tags = await buildTagPages(posts, slides, config); await buildTagListPage(tags, config); await buildHomePage(config); await buildAboutPage(config); @@ -124,12 +125,13 @@ async function buildNotFoundPage(config: Config) { async function buildTagPages( posts: PostPage[], + slides: SlidePage[], config: Config, ): Promise { - const tagsAndPosts = collectTags(posts); + const tagsAndPages = collectTags([...posts, ...slides]); const tags = []; - for (const [tag, posts] of tagsAndPosts) { - const tagPage = await generateTagPage(tag, posts, config); + for (const [tag, pages] of tagsAndPages) { + const tagPage = await generateTagPage(tag, pages, config); await writePage(tagPage, config); tags.push(tagPage); } @@ -141,22 +143,22 @@ async function buildTagListPage(tags: TagPage[], config: Config) { await writePage(tagListPage, config); } -function collectTags(posts: PostPage[]): [string, PostPage[]][] { - const tagsAndPosts = new Map(); - for (const post of posts) { - for (const tag of post.tags) { - if (!tagsAndPosts.has(tag)) { - tagsAndPosts.set(tag, []); +function collectTags(taggedPages: TaggedPage[]): [string, TaggedPage[]][] { + const tagsAndPages = new Map(); + for (const page of taggedPages) { + for (const tag of page.tags) { + if (!tagsAndPages.has(tag)) { + tagsAndPages.set(tag, []); } - tagsAndPosts.get(tag).push(post); + tagsAndPages.get(tag).push(page); } } - const result: [string, PostPage[]][] = []; - for (const tag of Array.from(tagsAndPosts.keys()).sort()) { + const result: [string, TaggedPage[]][] = []; + for (const tag of Array.from(tagsAndPages.keys()).sort()) { result.push([ tag, - tagsAndPosts.get(tag).sort((a: PostPage, b: PostPage) => { + tagsAndPages.get(tag).sort((a: TaggedPage, b: TaggedPage) => { const ta = getPostCreatedDate(a); const tb = getPostCreatedDate(b); if (ta > tb) return -1; -- cgit v1.2.3-70-g09d2