diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-03-17 00:48:07 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-03-18 21:02:54 +0900 |
| commit | 5208a0a0f7e5703af37c9adf6d60f6c8ef10b9ee (patch) | |
| tree | e2c3272f21e45acb377e70ce2d1c85811e3ab26b /nuldoc-src/pages/slide.ts | |
| parent | 7688362ad3b57b0cdd6f048d1e595f69748fc183 (diff) | |
| download | blog.nsfisis.dev-5208a0a0f7e5703af37c9adf6d60f6c8ef10b9ee.tar.gz blog.nsfisis.dev-5208a0a0f7e5703af37c9adf6d60f6c8ef10b9ee.tar.zst blog.nsfisis.dev-5208a0a0f7e5703af37c9adf6d60f6c8ef10b9ee.zip | |
feat(nuldoc): add /slides/ page
Diffstat (limited to 'nuldoc-src/pages/slide.ts')
| -rw-r--r-- | nuldoc-src/pages/slide.ts | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/nuldoc-src/pages/slide.ts b/nuldoc-src/pages/slide.ts new file mode 100644 index 0000000..fdfe868 --- /dev/null +++ b/nuldoc-src/pages/slide.ts @@ -0,0 +1,133 @@ +import { join } from "std/path/mod.ts"; +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 { Revision } from "../revision.ts"; +import { Slide } from "../slide/slide.ts"; +import { getPostCreatedDate } from "./post.ts"; + +export interface SlidePage extends Page { + title: string; + event: string; + talkType: string; + slideLink: string; + tags: string[]; + revisions: Revision[]; +} + +export async function generateSlidePage( + slide: Slide, + config: Config, +): Promise<SlidePage> { + const body = el( + "body", + [["class", "single"]], + globalHeader(config), + el( + "main", + [["class", "main"]], + el( + "article", + [["class", "post-single"]], + el( + "header", + [["class", "post-header"]], + el( + "h1", + [["class", "post-title"]], + text(slide.title), + ), + ...(slide.tags.length === 0 ? [] : [ + el( + "ul", + [["class", "post-tags"]], + ...slide.tags.map((slug) => + el( + "li", + [["class", "tag"]], + el( + "a", + [["href", `/tags/${slug}/`]], + text( + (config.blog.tagLabels as { + [key: string]: string; + })[slug], + ), + ), + ) + ), + ), + ]), + ), + el( + "div", + [["class", "post-content"]], + el( + "section", + [], + el( + "h2", + [["id", "changelog"]], + text("更新履歴"), + ), + el( + "ol", + [], + ...slide.revisions.map((rev) => + el( + "li", + [["class", "revision"]], + el( + "time", + [["datetime", rev.date]], + text(rev.date), + ), + text(`: ${rev.remark}`), + ) + ), + ), + ), + ), + ), + ), + globalFooter(config), + ); + + const html = await pageLayout( + { + metaCopyrightYear: parseInt( + getPostCreatedDate(slide).substring(0, 4), + ), + metaDescription: slide.title, + metaKeywords: slide.tags.map((slug) => + (config.blog.tagLabels as { [key: string]: string })[slug] + ), + metaTitle: `${slide.event} (${slide.talkType}) | ${config.blog.siteName}`, + requiresSyntaxHighlight: true, + }, + body, + config, + ); + + const cwd = Deno.cwd(); + const contentDir = join(cwd, config.locations.contentDir); + const destFilePath = join( + slide.sourceFilePath.replace(contentDir, "").replace(".xml", ""), + "index.html", + ); + return { + root: el("__root__", [], html), + renderer: "html", + destFilePath: destFilePath, + href: destFilePath.replace("index.html", ""), + title: slide.title, + event: slide.event, + talkType: slide.talkType, + slideLink: slide.slideLink, + tags: slide.tags, + revisions: slide.revisions, + }; +} |
