aboutsummaryrefslogtreecommitdiffhomepage
path: root/vhosts/blog/nuldoc-src/ndoc/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/ndoc/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/ndoc/document.ts')
-rw-r--r--vhosts/blog/nuldoc-src/ndoc/document.ts66
1 files changed, 0 insertions, 66 deletions
diff --git a/vhosts/blog/nuldoc-src/ndoc/document.ts b/vhosts/blog/nuldoc-src/ndoc/document.ts
deleted file mode 100644
index dfb6d03..0000000
--- a/vhosts/blog/nuldoc-src/ndoc/document.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import { join } from "@std/path";
-import { Config } from "../config.ts";
-import { NuldocError } from "../errors.ts";
-import { Revision, stringToDate } from "../revision.ts";
-import { Element, findFirstChildElement } from "../dom.ts";
-import { z } from "zod/mod.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 createNewDocumentFromRootElement(
- root: Element,
- meta: PostMetadata,
- sourceFilePath: string,
- config: Config,
-): Document {
- const article = findFirstChildElement(root, "article");
- if (!article) {
- throw new NuldocError(
- `[nuldoc.new] <article> element not found`,
- );
- }
-
- const cwd = Deno.cwd();
- const contentDir = join(cwd, config.locations.contentDir);
- const link = sourceFilePath.replace(contentDir, "").replace(".xml", "/");
- return {
- root: root,
- sourceFilePath: 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,
- })),
- };
-}