From 940eae61767214eb1ee573284dc8b5876d536fb3 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 12 Jan 2025 19:44:19 +0900 Subject: refactor(blog/nuldoc): convert pages/*.ts to TSX --- vhosts/blog/nuldoc-src/pages/post.tsx | 123 ++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 vhosts/blog/nuldoc-src/pages/post.tsx (limited to 'vhosts/blog/nuldoc-src/pages/post.tsx') diff --git a/vhosts/blog/nuldoc-src/pages/post.tsx b/vhosts/blog/nuldoc-src/pages/post.tsx new file mode 100644 index 00000000..529d6738 --- /dev/null +++ b/vhosts/blog/nuldoc-src/pages/post.tsx @@ -0,0 +1,123 @@ +import { join } from "std/path/mod.ts"; +import { renderToDOM } from "../jsx/render.ts"; +import GlobalFooter from "../components/GlobalFooter.tsx"; +import GlobalHeader from "../components/GlobalHeader.tsx"; +import PageLayout from "../components/PageLayout.tsx"; +import { Config, getTagLabel } from "../config.ts"; +import { el, Element } from "../dom.ts"; +import { Document } from "../ndoc/document.ts"; +import { Page } from "../page.ts"; +import { Date, dateToString, Revision } from "../revision.ts"; + +export interface PostPage extends Page { + title: string; + description: string; + tags: string[]; + revisions: Revision[]; + published: Date; + updated: Date; + uuid: string; +} + +export function getPostPublishedDate(page: { revisions: Revision[] }): Date { + for (const rev of page.revisions) { + if (!rev.isInternal) { + return rev.date; + } + } + return page.revisions[0].date; +} + +export function getPostUpdatedDate(page: { revisions: Revision[] }): Date { + return page.revisions[page.revisions.length - 1].date; +} + +export function postHasAnyUpdates(page: { revisions: Revision[] }): boolean { + return 2 <= page.revisions.filter((rev) => !rev.isInternal).length; +} + +export async function generatePostPage( + doc: Document, + config: Config, +): Promise { + const html = await renderToDOM( + getTagLabel(config, slug))} + metaTitle={`${doc.title}|${config.blog.siteName}`} + requiresSyntaxHighlight + config={config} + > + + +
+
+
+

{doc.title}

+ {doc.tags.length !== 0 && ( + + )} +
+
+
+

更新履歴

+
    + {doc.revisions.map((rev) => ( +
  1. + + {`: ${rev.remark}`} +
  2. + ))} +
+
+ { + // TODO: refactor + (doc.root.children[0] as Element).children + } + { + // TODO: footnotes + //
+ // <% for footnote in footnotes %> + //
+ // <%= footnote.index %>. <%= footnote.text %> + //
+ // <% end %> + //
+ } +
+
+
+ + +
, + ); + + const cwd = Deno.cwd(); + const contentDir = join(cwd, config.locations.contentDir); + const destFilePath = join( + doc.sourceFilePath.replace(contentDir, "").replace(".ndoc", ""), + "index.html", + ); + return { + root: el("__root__", {}, html), + renderer: "html", + destFilePath: destFilePath, + href: destFilePath.replace("index.html", ""), + title: doc.title, + description: doc.description, + tags: doc.tags, + revisions: doc.revisions, + published: getPostPublishedDate(doc), + updated: getPostUpdatedDate(doc), + uuid: doc.uuid, + }; +} -- cgit v1.2.3-70-g09d2