summaryrefslogtreecommitdiffhomepage
path: root/vhosts/blog/nuldoc-src/pages/post.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-09-07 22:27:48 +0900
committernsfisis <nsfisis@gmail.com>2023-09-07 22:35:53 +0900
commit994e0114d76ae19768d5c303874a968cf6369fd0 (patch)
tree5fd3f8b169eea00084b24fbae820f75273864d2a /vhosts/blog/nuldoc-src/pages/post.ts
parent57f015992f678bfd7281f171fb9d71349c96a1a0 (diff)
downloadnsfisis.dev-994e0114d76ae19768d5c303874a968cf6369fd0.tar.gz
nsfisis.dev-994e0114d76ae19768d5c303874a968cf6369fd0.tar.zst
nsfisis.dev-994e0114d76ae19768d5c303874a968cf6369fd0.zip
meta: migrate to monorepo
Diffstat (limited to 'vhosts/blog/nuldoc-src/pages/post.ts')
-rw-r--r--vhosts/blog/nuldoc-src/pages/post.ts140
1 files changed, 140 insertions, 0 deletions
diff --git a/vhosts/blog/nuldoc-src/pages/post.ts b/vhosts/blog/nuldoc-src/pages/post.ts
new file mode 100644
index 00000000..24a6d5f5
--- /dev/null
+++ b/vhosts/blog/nuldoc-src/pages/post.ts
@@ -0,0 +1,140 @@
+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, getTagLabel } from "../config.ts";
+import { el, Element, text } from "../dom.ts";
+import { Document } from "../docbook/document.ts";
+import { Page } from "../page.ts";
+import { Date, dateToString, Revision } from "../revision.ts";
+
+export interface PostPage extends Page {
+ title: string;
+ summary: string;
+ tags: string[];
+ revisions: Revision[];
+}
+
+export function getPostCreatedDate(page: { revisions: Revision[] }): Date {
+ return page.revisions[0].date;
+}
+
+export function getPostUpdatedDate(page: { revisions: Revision[] }): Date {
+ return page.revisions[page.revisions.length - 1].date;
+}
+
+export async function generatePostPage(
+ doc: Document,
+ config: Config,
+): Promise<PostPage> {
+ 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(doc.title),
+ ),
+ ...(doc.tags.length === 0 ? [] : [
+ el(
+ "ul",
+ [["class", "post-tags"]],
+ ...doc.tags.map((slug) =>
+ el(
+ "li",
+ [["class", "tag"]],
+ el(
+ "a",
+ [["href", `/tags/${slug}/`]],
+ text(
+ getTagLabel(config, slug),
+ ),
+ ),
+ )
+ ),
+ ),
+ ]),
+ ),
+ el(
+ "div",
+ [["class", "post-content"]],
+ el(
+ "section",
+ [],
+ el(
+ "h2",
+ [["id", "changelog"]],
+ text("更新履歴"),
+ ),
+ el(
+ "ol",
+ [],
+ ...doc.revisions.map((rev) =>
+ el(
+ "li",
+ [["class", "revision"]],
+ el(
+ "time",
+ [["datetime", dateToString(rev.date)]],
+ text(dateToString(rev.date)),
+ ),
+ text(`: ${rev.remark}`),
+ )
+ ),
+ ),
+ ),
+ // TODO: refactor
+ ...(doc.root.children[0] as Element).children,
+ // TODO: footnotes
+ // <div id="footnotes">
+ // <% for footnote in footnotes %>
+ // <div class="footnote" id="_footnotedef_<%= footnote.index %>">
+ // <a href="#_footnoteref_<%= footnote.index %>"><%= footnote.index %></a>. <%= footnote.text %>
+ // </div>
+ // <% end %>
+ // </div>
+ ),
+ ),
+ ),
+ globalFooter(config),
+ );
+
+ const html = await pageLayout(
+ {
+ metaCopyrightYear: getPostCreatedDate(doc).year,
+ metaDescription: doc.summary,
+ metaKeywords: doc.tags.map((slug) => getTagLabel(config, slug)),
+ metaTitle: `${doc.title} | ${config.blog.siteName}`,
+ requiresSyntaxHighlight: true,
+ },
+ body,
+ config,
+ );
+
+ const cwd = Deno.cwd();
+ const contentDir = join(cwd, config.locations.contentDir);
+ const destFilePath = join(
+ doc.sourceFilePath.replace(contentDir, "").replace(".xml", ""),
+ "index.html",
+ );
+ return {
+ root: el("__root__", [], html),
+ renderer: "html",
+ destFilePath: destFilePath,
+ href: destFilePath.replace("index.html", ""),
+ title: doc.title,
+ summary: doc.summary,
+ tags: doc.tags,
+ revisions: doc.revisions,
+ };
+}