summaryrefslogtreecommitdiffhomepage
path: root/vhosts/blog/nuldoc-src/djot/document.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-04-09 22:24:50 +0900
committernsfisis <nsfisis@gmail.com>2025-04-09 22:24:50 +0900
commitd1b4bc44170196a4dcef5254d092fc387e73792e (patch)
treea6bbe0e61b73c99a815d730ae7956a5124200066 /vhosts/blog/nuldoc-src/djot/document.ts
parentbba1212ab46ed85c2ed3b646f2362bdbb1f45b63 (diff)
parent4f46d262e6967c9c638b40f3b0246d21b7a9b9dc (diff)
downloadnsfisis.dev-d1b4bc44170196a4dcef5254d092fc387e73792e.tar.gz
nsfisis.dev-d1b4bc44170196a4dcef5254d092fc387e73792e.tar.zst
nsfisis.dev-d1b4bc44170196a4dcef5254d092fc387e73792e.zip
Merge branch 'nuldoc-djot'
Diffstat (limited to 'vhosts/blog/nuldoc-src/djot/document.ts')
-rw-r--r--vhosts/blog/nuldoc-src/djot/document.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/vhosts/blog/nuldoc-src/djot/document.ts b/vhosts/blog/nuldoc-src/djot/document.ts
new file mode 100644
index 00000000..be9c08d5
--- /dev/null
+++ b/vhosts/blog/nuldoc-src/djot/document.ts
@@ -0,0 +1,60 @@
+import { Doc as DjotDoc } from "@djot/djot";
+import { join } from "@std/path";
+import { z } from "zod/mod.ts";
+import { Config } from "../config.ts";
+import { Element } from "../dom.ts";
+import { Revision, stringToDate } from "../revision.ts";
+import { djot2ndoc } from "./djot2ndoc.ts";
+
+export const PostMetadataSchema = z.object({
+ article: z.object({
+ uuid: z.string(),
+ title: z.string(),
+ description: z.string(),
+ tags: z.array(z.string()),
+ revisions: z.array(z.object({
+ date: z.string(),
+ remark: z.string(),
+ isInternal: z.boolean().optional(),
+ })),
+ }),
+});
+
+export type PostMetadata = z.infer<typeof PostMetadataSchema>;
+
+export type Document = {
+ root: Element;
+ sourceFilePath: string;
+ uuid: string;
+ link: string;
+ title: string;
+ description: string; // TODO: should it be markup text?
+ tags: string[];
+ revisions: Revision[];
+};
+
+export function createNewDocumentFromDjotDocument(
+ root: DjotDoc,
+ meta: PostMetadata,
+ sourceFilePath: string,
+ config: Config,
+): Document {
+ const cwd = Deno.cwd();
+ const contentDir = join(cwd, config.locations.contentDir);
+ const link = sourceFilePath.replace(contentDir, "").replace(".xml", "/");
+ return {
+ root: djot2ndoc(root),
+ sourceFilePath,
+ uuid: meta.article.uuid,
+ link: link,
+ title: meta.article.title,
+ description: meta.article.description,
+ tags: meta.article.tags,
+ revisions: meta.article.revisions.map((r, i) => ({
+ number: i,
+ date: stringToDate(r.date),
+ remark: r.remark,
+ isInternal: !!r.isInternal,
+ })),
+ };
+}