Changes
10 changed files (+37/-71)
-
-
@@ -11,15 +11,6 @@## Document name An identifier for a document, unique among a directory the document belongs to. A *document name* appears in a generated URL, thus available characters are limited to: - Alphabet (`a-z`, `A-Z`) - Digit (`0-9`) - Percent symbol (`%`) - Hyphen (`-`) - Dot (`.`) - Underscore (`_`) - Tilde (`~`) ## Document title
-
-
-
@@ -10,15 +10,6 @@export interface DocumentMetadata { /** * An identifier for a document, unique among a directory the document belongs to. * A *document name* appears in a generated URL, thus available characters are limited to: * * - Alphabet (`a-z`, `A-Z`) * - Digit (`0-9`) * - Percent symbol (`%`) * - Hyphen (`-`) * - Dot (`.`) * - Underscore (`_`) * - Tilde (`~`) */ readonly name: string;
-
-
-
@@ -42,40 +42,6 @@ title: "bar",}); }); Deno.test("Should lowercase filename for name", async () => { const fs = new MemoryFsReader([ { path: "Foo.md", content: "", }, ]); const root = await fs.getRootDirectory(); const [file] = await root.read(); assertObjectMatch(await new VaultParser().parse(file), { name: "foo", title: "Foo", }); }); Deno.test("Should encode to URI-safe name", async () => { const fs = new MemoryFsReader([ { path: "My Awesome Document, Progress 75%.md", content: "", }, ]); const root = await fs.getRootDirectory(); const [file] = await root.read(); assertObjectMatch(await new VaultParser().parse(file), { name: "my%20awesome%20document%2C%20progress%2075%25", title: "My Awesome Document, Progress 75%", }); }); Deno.test("Should parse canvas file", async () => { const fs = new MemoryFsReader([ {
-
@@ -145,7 +111,7 @@assertObjectMatch( await new VaultParser({ readFrontMatter: true }).parse(file), { name: "foo%20bar", name: "Foo Bar", title: "Baz", }, );
-
@@ -167,7 +133,7 @@assertObjectMatch( await new VaultParser({ readFrontMatter: true }).parse(file), { name: "foo%20bar", name: "Foo Bar", title: "Foo Bar", language: "en", },
-
@@ -214,7 +180,7 @@assertObjectMatch( await new VaultParser().parse(file), { name: "foo%20bar", name: "Foo Bar", title: "Foo Bar", }, );
-
-
-
@@ -11,10 +11,6 @@ FileReader,} from "../filesystem_reader/interface.ts"; import type { DocumentMetadata, MetadataParser, Skip } from "./interface.ts"; function escapeNodeName(nodeName: string): string { return encodeURIComponent(nodeName.toLowerCase()); } function getFrontMatterValue( frontmatter: Record<string, unknown>, key: string,
-
@@ -76,7 +72,7 @@ const overrides = this.#override?.(node) || null;if (node.type === "directory") { return { name: overrides?.name || escapeNodeName(node.name), name: overrides?.name || node.name, title: overrides?.title || node.name, language: overrides?.language, };
-
@@ -88,7 +84,7 @@switch (ext) { case ".md": { const fromFileName: DocumentMetadata = { name: overrides?.name || escapeNodeName(basename), name: overrides?.name || basename, title: overrides?.title || basename, language: overrides?.language, };
-
@@ -107,7 +103,7 @@ return fromFileName;} case ".canvas": { return { name: overrides?.name || escapeNodeName(basename), name: overrides?.name || basename, title: overrides?.title || basename, language: overrides?.language, };
-
-
-
@@ -91,7 +91,7 @@ const enc = new TextEncoder();await fileSystemWriter.write([ ...pathPrefix, item.file.name.replace(/\.md$/, ""), item.metadata.name, "index.html", ], enc.encode(html)); return;
-
@@ -113,7 +113,7 @@ this.#build({item: entry, tree, parentLanguage: item.metadata.language || parentLanguage, pathPrefix: [...pathPrefix, item.directory.name], pathPrefix: [...pathPrefix, item.metadata.name], buildParameters, }) ));
-
-
-
@@ -16,6 +16,7 @@ import { toJsxRuntime } from "../../../deps/esm.sh/hast-util-to-jsx-runtime/mod.ts";import type { Document, DocumentDirectory, DocumentTree, } from "../../../tree_builder/interface.ts";
-
@@ -96,7 +97,7 @@ aside={toc.length > 0 && <Toc.View toc={toc} />}nav={ <DocumentTreeUI.View tree={tree} currentPath={document.file.path} currentPath={document.path} /> } footer={<Footer.View copyright={copyright} />}
-
-
-
@@ -66,8 +66,8 @@ const pathResolver = usePathResolver();if ("file" in value) { const path = pathResolver.resolve([ ...value.file.path.slice(0, -1), value.file.name.replace(/\.md$/, ""), ...value.path.map((segment) => encodeURIComponent(segment)), // For trailing slash "", ]);
-
-
-
@@ -23,7 +23,7 @@ const tree = await builder.build({ fileSystemReader, metadataParser });assertObjectMatch(tree.nodes[0], { metadata: { name: "foo%20bar", name: "Foo Bar", title: "Foo Bar", }, directory: {
-
@@ -32,7 +32,7 @@ },entries: [ { metadata: { name: "baz%20qux", name: "Baz Qux", title: "Baz Qux", }, file: {
-
@@ -44,7 +44,7 @@ });assertObjectMatch(tree.nodes[1], { metadata: { name: "foo", name: "Foo", title: "Foo", }, file: {
-
-
-
@@ -50,6 +50,7 @@ children.map((child) => this.#build(child, metadataParser)),); return { type: "tree", nodes: entries.filter((entry): entry is NonNullable<typeof entry> => !!entry ),
-
@@ -60,6 +61,7 @@async #build( node: FileReader | DirectoryReader, metadataParser: MetadataParser, parentPath: readonly string[] = [], ): Promise<DocumentDirectory | Document | null> { if (this.#ignore && this.#ignore(node)) { // TODO: Debug log
-
@@ -77,23 +79,29 @@ }if (node.type === "file") { return { type: "document", metadata, file: node, path: [...parentPath, metadata.name], }; } const children = await node.read(); const entries = await Promise.all( children.map((child) => this.#build(child, metadataParser)), children.map((child) => this.#build(child, metadataParser, [...parentPath, metadata.name]) ), ); return { type: "directory", metadata, directory: node, entries: entries.filter((child): child is NonNullable<typeof child> => !!child ), path: [...parentPath, metadata.name], }; } }
-
-
-
@@ -13,17 +13,30 @@ MetadataParser,} from "../metadata_parser/interface.ts"; export interface Document { readonly type: "document"; readonly metadata: DocumentMetadata; readonly file: FileReader; /** * Document path: list of names, not file paths. */ readonly path: readonly string[]; } export interface DocumentDirectory { readonly type: "directory"; readonly metadata: DocumentMetadata; readonly directory: DirectoryReader; readonly entries: ReadonlyArray<Document | DocumentDirectory>; /** * Document path: list of names, not file paths. */ readonly path: readonly string[]; } export interface DocumentTree { readonly type: "tree"; readonly nodes: ReadonlyArray<Document | DocumentDirectory>; readonly defaultLanguage: string;
-