@glw907/cairn-cms 0.18.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/DeleteDialog.svelte +81 -0
- package/dist/components/DeleteDialog.svelte.d.ts +21 -0
- package/dist/components/DeleteDialog.svelte.d.ts.map +1 -0
- package/dist/components/EditPage.svelte +127 -8
- package/dist/components/EditPage.svelte.d.ts +8 -0
- package/dist/components/EditPage.svelte.d.ts.map +1 -1
- package/dist/components/LinkPicker.svelte +109 -0
- package/dist/components/LinkPicker.svelte.d.ts +18 -0
- package/dist/components/LinkPicker.svelte.d.ts.map +1 -0
- package/dist/components/MarkdownEditor.svelte +33 -3
- package/dist/components/MarkdownEditor.svelte.d.ts +5 -0
- package/dist/components/MarkdownEditor.svelte.d.ts.map +1 -1
- package/dist/components/RenameDialog.svelte +72 -0
- package/dist/components/RenameDialog.svelte.d.ts +20 -0
- package/dist/components/RenameDialog.svelte.d.ts.map +1 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +3 -0
- package/dist/components/link-completion.d.ts +16 -0
- package/dist/components/link-completion.d.ts.map +1 -0
- package/dist/components/link-completion.js +48 -0
- package/dist/components/markdown-format.d.ts +25 -5
- package/dist/components/markdown-format.d.ts.map +1 -1
- package/dist/components/markdown-format.js +85 -0
- package/dist/content/concepts.d.ts.map +1 -1
- package/dist/content/concepts.js +7 -0
- package/dist/content/frontmatter.d.ts +8 -0
- package/dist/content/frontmatter.d.ts.map +1 -1
- package/dist/content/frontmatter.js +19 -0
- package/dist/content/ids.d.ts +7 -0
- package/dist/content/ids.d.ts.map +1 -1
- package/dist/content/ids.js +11 -0
- package/dist/content/links.d.ts +7 -0
- package/dist/content/links.d.ts.map +1 -1
- package/dist/content/links.js +11 -0
- package/dist/content/manifest.d.ts +15 -1
- package/dist/content/manifest.d.ts.map +1 -1
- package/dist/content/manifest.js +45 -3
- package/dist/content/types.d.ts +6 -0
- package/dist/content/types.d.ts.map +1 -1
- package/dist/content/validate.d.ts.map +1 -1
- package/dist/content/validate.js +8 -1
- package/dist/delivery/content-index.d.ts +7 -0
- package/dist/delivery/content-index.d.ts.map +1 -1
- package/dist/delivery/content-index.js +7 -0
- package/dist/delivery/head.d.ts +2 -0
- package/dist/delivery/head.d.ts.map +1 -0
- package/dist/delivery/head.js +4 -0
- package/dist/delivery/index.d.ts +0 -1
- package/dist/delivery/index.d.ts.map +1 -1
- package/dist/delivery/index.js +0 -1
- package/dist/delivery/manifest.d.ts.map +1 -1
- package/dist/delivery/manifest.js +7 -0
- package/dist/github/repo.d.ts.map +1 -1
- package/dist/github/repo.js +8 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/render/pipeline.d.ts +4 -0
- package/dist/render/pipeline.d.ts.map +1 -1
- package/dist/render/pipeline.js +3 -1
- package/dist/render/registry.d.ts +1 -1
- package/dist/render/registry.d.ts.map +1 -1
- package/dist/render/rehype-dispatch.d.ts +5 -0
- package/dist/render/rehype-dispatch.d.ts.map +1 -1
- package/dist/render/rehype-dispatch.js +12 -1
- package/dist/render/remark-directives.d.ts.map +1 -1
- package/dist/render/remark-directives.js +15 -6
- package/dist/render/sanitize-schema.d.ts +4 -3
- package/dist/render/sanitize-schema.d.ts.map +1 -1
- package/dist/render/sanitize-schema.js +6 -5
- package/dist/sveltekit/content-routes.d.ts +11 -2
- package/dist/sveltekit/content-routes.d.ts.map +1 -1
- package/dist/sveltekit/content-routes.js +157 -9
- package/dist/sveltekit/public-routes.d.ts +1 -0
- package/dist/sveltekit/public-routes.d.ts.map +1 -1
- package/dist/sveltekit/public-routes.js +1 -1
- package/package.json +7 -1
- package/src/lib/components/DeleteDialog.svelte +81 -0
- package/src/lib/components/EditPage.svelte +127 -8
- package/src/lib/components/LinkPicker.svelte +109 -0
- package/src/lib/components/MarkdownEditor.svelte +33 -3
- package/src/lib/components/RenameDialog.svelte +72 -0
- package/src/lib/components/index.ts +3 -0
- package/src/lib/components/link-completion.ts +57 -0
- package/src/lib/components/markdown-format.ts +82 -0
- package/src/lib/content/concepts.ts +9 -0
- package/src/lib/content/frontmatter.ts +21 -0
- package/src/lib/content/ids.ts +12 -0
- package/src/lib/content/links.ts +13 -0
- package/src/lib/content/manifest.ts +55 -3
- package/src/lib/content/types.ts +6 -0
- package/src/lib/content/validate.ts +6 -1
- package/src/lib/delivery/content-index.ts +13 -0
- package/src/lib/delivery/head.ts +4 -0
- package/src/lib/delivery/index.ts +0 -1
- package/src/lib/delivery/manifest.ts +6 -0
- package/src/lib/github/repo.ts +8 -1
- package/src/lib/index.ts +10 -2
- package/src/lib/render/pipeline.ts +6 -1
- package/src/lib/render/registry.ts +1 -1
- package/src/lib/render/rehype-dispatch.ts +12 -1
- package/src/lib/render/remark-directives.ts +16 -5
- package/src/lib/render/sanitize-schema.ts +6 -5
- package/src/lib/sveltekit/content-routes.ts +178 -11
- package/src/lib/sveltekit/public-routes.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/components/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/components/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/components/index.js
CHANGED
|
@@ -11,3 +11,6 @@ export { default as ComponentInsertDialog } from './ComponentInsertDialog.svelte
|
|
|
11
11
|
export { default as ComponentForm } from './ComponentForm.svelte';
|
|
12
12
|
export { default as IconPicker } from './IconPicker.svelte';
|
|
13
13
|
export { default as NavTree } from './NavTree.svelte';
|
|
14
|
+
export { default as LinkPicker } from './LinkPicker.svelte';
|
|
15
|
+
export { default as DeleteDialog } from './DeleteDialog.svelte';
|
|
16
|
+
export { default as RenameDialog } from './RenameDialog.svelte';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Completion, CompletionSource } from '@codemirror/autocomplete';
|
|
2
|
+
import type { LinkTarget } from '../content/manifest.js';
|
|
3
|
+
/** The open `[[query` before the cursor, or null. The query stops at a closing bracket or a newline,
|
|
4
|
+
* so a finished `[[x]]` link and ordinary prose never trigger. `from` is the index of the `[[`. */
|
|
5
|
+
export declare function matchCairnTrigger(before: string): {
|
|
6
|
+
query: string;
|
|
7
|
+
from: number;
|
|
8
|
+
} | null;
|
|
9
|
+
/** The completion options for a query: a case-insensitive title substring match, each option grouped
|
|
10
|
+
* by concept, a draft marked and a post date shown in the detail, and the apply text the full link. */
|
|
11
|
+
export declare function linkCompletions(targets: LinkTarget[], query: string): Completion[];
|
|
12
|
+
/** A CodeMirror CompletionSource over the site's link targets, triggered by `[[`. It replaces the
|
|
13
|
+
* whole `[[query` with the chosen link, and sets filter:false because linkCompletions already
|
|
14
|
+
* filtered by the query (CodeMirror would otherwise re-filter against the literal `[[query`). */
|
|
15
|
+
export declare function cairnLinkCompletionSource(targets: LinkTarget[]): CompletionSource;
|
|
16
|
+
//# sourceMappingURL=link-completion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link-completion.d.ts","sourceRoot":"","sources":["../../src/lib/components/link-completion.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAuC,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAElH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAazD;oGACoG;AACpG,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAGxF;AAED;wGACwG;AACxG,wBAAgB,eAAe,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,EAAE,CASlF;AAED;;kGAEkG;AAClG,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,gBAAgB,CAcjF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { syntaxTree } from '@codemirror/language';
|
|
2
|
+
import { formatCairnToken, escapeLinkText } from '../content/links.js';
|
|
3
|
+
/** The known concepts in display order; an unlisted concept sorts after these under its own name. */
|
|
4
|
+
const CONCEPT_SECTIONS = {
|
|
5
|
+
pages: { name: 'Pages', rank: 0 },
|
|
6
|
+
posts: { name: 'Posts', rank: 1 },
|
|
7
|
+
};
|
|
8
|
+
function sectionFor(concept) {
|
|
9
|
+
return CONCEPT_SECTIONS[concept] ?? { name: concept.charAt(0).toUpperCase() + concept.slice(1), rank: 2 };
|
|
10
|
+
}
|
|
11
|
+
/** The open `[[query` before the cursor, or null. The query stops at a closing bracket or a newline,
|
|
12
|
+
* so a finished `[[x]]` link and ordinary prose never trigger. `from` is the index of the `[[`. */
|
|
13
|
+
export function matchCairnTrigger(before) {
|
|
14
|
+
const match = /\[\[([^[\]\n]*)$/.exec(before);
|
|
15
|
+
return match ? { query: match[1], from: match.index } : null;
|
|
16
|
+
}
|
|
17
|
+
/** The completion options for a query: a case-insensitive title substring match, each option grouped
|
|
18
|
+
* by concept, a draft marked and a post date shown in the detail, and the apply text the full link. */
|
|
19
|
+
export function linkCompletions(targets, query) {
|
|
20
|
+
const q = query.trim().toLowerCase();
|
|
21
|
+
const matched = q ? targets.filter((t) => t.title.toLowerCase().includes(q)) : targets;
|
|
22
|
+
return matched.map((t) => ({
|
|
23
|
+
label: t.title,
|
|
24
|
+
section: sectionFor(t.concept),
|
|
25
|
+
detail: t.draft ? 'Draft' : t.date,
|
|
26
|
+
apply: `[${escapeLinkText(t.title)}](${formatCairnToken(t)})`,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
/** A CodeMirror CompletionSource over the site's link targets, triggered by `[[`. It replaces the
|
|
30
|
+
* whole `[[query` with the chosen link, and sets filter:false because linkCompletions already
|
|
31
|
+
* filtered by the query (CodeMirror would otherwise re-filter against the literal `[[query`). */
|
|
32
|
+
export function cairnLinkCompletionSource(targets) {
|
|
33
|
+
return (context) => {
|
|
34
|
+
const line = context.state.doc.lineAt(context.pos);
|
|
35
|
+
const before = context.state.sliceDoc(line.from, context.pos);
|
|
36
|
+
const trigger = matchCairnTrigger(before);
|
|
37
|
+
if (!trigger)
|
|
38
|
+
return null;
|
|
39
|
+
// Skip a [[ inside a fenced or inline code node: a cairn link there would be literal text, and
|
|
40
|
+
// the build resolver does not look inside code. The node name carries "Code" for both forms.
|
|
41
|
+
const node = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
42
|
+
for (let n = node; n; n = n.parent) {
|
|
43
|
+
if (/Code/.test(n.name))
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return { from: line.from + trigger.from, options: linkCompletions(targets, trigger.query), filter: false };
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure markdown selection transforms for the editor toolbar. Each call maps a document and a
|
|
3
|
-
* selection range to a new document and a new selection, with no DOM. The MarkdownEditor view
|
|
4
|
-
* dispatches the result; keeping the logic here lets it unit-test without a browser.
|
|
5
|
-
*/
|
|
6
1
|
export type FormatKind = 'bold' | 'italic' | 'code' | 'heading' | 'quote' | 'ul' | 'link';
|
|
7
2
|
export interface FormatResult {
|
|
8
3
|
doc: string;
|
|
@@ -10,4 +5,29 @@ export interface FormatResult {
|
|
|
10
5
|
to: number;
|
|
11
6
|
}
|
|
12
7
|
export declare function applyMarkdownFormat(doc: string, from: number, to: number, kind: FormatKind): FormatResult;
|
|
8
|
+
/**
|
|
9
|
+
* Insert an inline markdown link at the selection. With a non-empty selection the selected text
|
|
10
|
+
* becomes the display text; with an empty selection the title is the display text. The cursor
|
|
11
|
+
* collapses just after the inserted link. Unlike the block insert, this adds no surrounding
|
|
12
|
+
* blank lines, since a link is inline. Pure, so the editor dispatches the result.
|
|
13
|
+
*/
|
|
14
|
+
export declare function insertInlineLink(doc: string, from: number, to: number, href: string, title: string): FormatResult;
|
|
15
|
+
/**
|
|
16
|
+
* Unwrap every cairn: link whose href is exactly `href`, replacing it with its plain display text.
|
|
17
|
+
* The save guard's one-click fix calls this to drop a broken link while keeping the words. The
|
|
18
|
+
* document is parsed with the same remark pipeline extractCairnLinks uses, so the two agree on what
|
|
19
|
+
* a link is. Each matching link node is located by its source offsets and spliced out from last to
|
|
20
|
+
* first, which leaves the rest of the document exact and unescapes the display text. A token inside
|
|
21
|
+
* a code span or fence is not a link node, so it is never touched, and a link with a different url
|
|
22
|
+
* is left in place.
|
|
23
|
+
*/
|
|
24
|
+
export declare function unwrapCairnLink(doc: string, href: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Rewrite every cairn: link whose href is exactly `oldHref` so its href becomes `newHref`, keeping
|
|
27
|
+
* the display text and any link title byte-for-byte. Rename calls this to repoint a renamed entry's
|
|
28
|
+
* inbound tokens. Parsed with the same remark pipeline as extractCairnLinks, so a token inside a code
|
|
29
|
+
* span is not a link node and is never touched. Each matching node's source span is rewritten from
|
|
30
|
+
* last to first, replacing only the `](oldHref` run so the label and title stay exact.
|
|
31
|
+
*/
|
|
32
|
+
export declare function rewriteCairnLink(doc: string, oldHref: string, newHref: string): string;
|
|
13
33
|
//# sourceMappingURL=markdown-format.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-format.d.ts","sourceRoot":"","sources":["../../src/lib/components/markdown-format.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markdown-format.d.ts","sourceRoot":"","sources":["../../src/lib/components/markdown-format.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,CAAC;AAE1F,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAKD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,YAAY,CAsBzG;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAKjH;AAUD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAgBjE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAkBtF"}
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure markdown selection transforms for the editor toolbar. Each call maps a document and a
|
|
3
|
+
* selection range to a new document and a new selection, with no DOM. The MarkdownEditor view
|
|
4
|
+
* dispatches the result; keeping the logic here lets it unit-test without a browser.
|
|
5
|
+
*/
|
|
6
|
+
import { unified } from 'unified';
|
|
7
|
+
import remarkParse from 'remark-parse';
|
|
8
|
+
import remarkGfm from 'remark-gfm';
|
|
9
|
+
import { visit } from 'unist-util-visit';
|
|
10
|
+
import { escapeLinkText } from '../content/links.js';
|
|
1
11
|
const WRAP = { bold: '**', italic: '_', code: '`' };
|
|
2
12
|
const LINE_PREFIX = { heading: '# ', quote: '> ', ul: '- ' };
|
|
3
13
|
export function applyMarkdownFormat(doc, from, to, kind) {
|
|
@@ -21,3 +31,78 @@ export function applyMarkdownFormat(doc, from, to, kind) {
|
|
|
21
31
|
const added = prefixed.length - region.length;
|
|
22
32
|
return { doc: doc.slice(0, lineStart) + prefixed + doc.slice(to), from: from + prefix.length, to: to + added };
|
|
23
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Insert an inline markdown link at the selection. With a non-empty selection the selected text
|
|
36
|
+
* becomes the display text; with an empty selection the title is the display text. The cursor
|
|
37
|
+
* collapses just after the inserted link. Unlike the block insert, this adds no surrounding
|
|
38
|
+
* blank lines, since a link is inline. Pure, so the editor dispatches the result.
|
|
39
|
+
*/
|
|
40
|
+
export function insertInlineLink(doc, from, to, href, title) {
|
|
41
|
+
const text = from < to ? doc.slice(from, to) : escapeLinkText(title);
|
|
42
|
+
const inserted = `[${text}](${href})`;
|
|
43
|
+
const end = from + inserted.length;
|
|
44
|
+
return { doc: doc.slice(0, from) + inserted + doc.slice(to), from: end, to: end };
|
|
45
|
+
}
|
|
46
|
+
/** Concatenate a link node's text-child values. The parser has already unescaped them, so a source
|
|
47
|
+
* `Notes \[draft\]` yields `Notes [draft]`. Used instead of mdast-util-to-string, which is not a
|
|
48
|
+
* direct dependency. Non-text children (a nested emphasis, say) contribute no value, which is fine
|
|
49
|
+
* for the picker-produced links this fix targets. */
|
|
50
|
+
function linkText(node) {
|
|
51
|
+
return node.children.map((c) => ('value' in c ? c.value : '')).join('');
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Unwrap every cairn: link whose href is exactly `href`, replacing it with its plain display text.
|
|
55
|
+
* The save guard's one-click fix calls this to drop a broken link while keeping the words. The
|
|
56
|
+
* document is parsed with the same remark pipeline extractCairnLinks uses, so the two agree on what
|
|
57
|
+
* a link is. Each matching link node is located by its source offsets and spliced out from last to
|
|
58
|
+
* first, which leaves the rest of the document exact and unescapes the display text. A token inside
|
|
59
|
+
* a code span or fence is not a link node, so it is never touched, and a link with a different url
|
|
60
|
+
* is left in place.
|
|
61
|
+
*/
|
|
62
|
+
export function unwrapCairnLink(doc, href) {
|
|
63
|
+
const tree = unified().use(remarkParse).use(remarkGfm).parse(doc);
|
|
64
|
+
const spans = [];
|
|
65
|
+
visit(tree, 'link', (node) => {
|
|
66
|
+
if (node.url !== href)
|
|
67
|
+
return;
|
|
68
|
+
const start = node.position?.start?.offset;
|
|
69
|
+
const end = node.position?.end?.offset;
|
|
70
|
+
if (start == null || end == null)
|
|
71
|
+
return;
|
|
72
|
+
spans.push({ start, end, text: linkText(node) });
|
|
73
|
+
});
|
|
74
|
+
spans.sort((a, b) => b.start - a.start);
|
|
75
|
+
let out = doc;
|
|
76
|
+
for (const span of spans) {
|
|
77
|
+
out = out.slice(0, span.start) + span.text + out.slice(span.end);
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Rewrite every cairn: link whose href is exactly `oldHref` so its href becomes `newHref`, keeping
|
|
83
|
+
* the display text and any link title byte-for-byte. Rename calls this to repoint a renamed entry's
|
|
84
|
+
* inbound tokens. Parsed with the same remark pipeline as extractCairnLinks, so a token inside a code
|
|
85
|
+
* span is not a link node and is never touched. Each matching node's source span is rewritten from
|
|
86
|
+
* last to first, replacing only the `](oldHref` run so the label and title stay exact.
|
|
87
|
+
*/
|
|
88
|
+
export function rewriteCairnLink(doc, oldHref, newHref) {
|
|
89
|
+
const tree = unified().use(remarkParse).use(remarkGfm).parse(doc);
|
|
90
|
+
const spans = [];
|
|
91
|
+
visit(tree, 'link', (node) => {
|
|
92
|
+
if (node.url !== oldHref)
|
|
93
|
+
return;
|
|
94
|
+
const start = node.position?.start?.offset;
|
|
95
|
+
const end = node.position?.end?.offset;
|
|
96
|
+
if (start == null || end == null)
|
|
97
|
+
return;
|
|
98
|
+
spans.push({ start, end });
|
|
99
|
+
});
|
|
100
|
+
spans.sort((a, b) => b.start - a.start);
|
|
101
|
+
let out = doc;
|
|
102
|
+
for (const span of spans) {
|
|
103
|
+
const src = out.slice(span.start, span.end);
|
|
104
|
+
const rewritten = src.replace(`](${oldHref}`, `](${newHref}`);
|
|
105
|
+
out = out.slice(0, span.start) + rewritten + out.slice(span.end);
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"concepts.d.ts","sourceRoot":"","sources":["../../src/lib/content/concepts.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAElG;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAGjE,CAAC;AAeF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,CAAC,EAClD,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAAM,EAC5D,OAAO,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAmB,GAC/D,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"concepts.d.ts","sourceRoot":"","sources":["../../src/lib/content/concepts.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAElG;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAGjE,CAAC;AAeF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,CAAC,EAClD,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAAM,EAC5D,OAAO,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAmB,GAC/D,iBAAiB,EAAE,CA0BrB;AAED,yFAAyF;AACzF,wBAAgB,WAAW,CACzB,QAAQ,EAAE,iBAAiB,EAAE,EAC7B,EAAE,EAAE,MAAM,GACT,iBAAiB,GAAG,SAAS,CAE/B"}
|
package/dist/content/concepts.js
CHANGED
|
@@ -29,6 +29,12 @@ export function normalizeConcepts(content, urlPolicy = {}, routing = CONCEPT_ROU
|
|
|
29
29
|
for (const [id, config] of Object.entries(content)) {
|
|
30
30
|
if (!config)
|
|
31
31
|
continue;
|
|
32
|
+
const summaryFields = config.summaryFields ?? [];
|
|
33
|
+
const declared = new Set(config.schema.fields.map((field) => field.name));
|
|
34
|
+
const undeclared = summaryFields.find((key) => !declared.has(key));
|
|
35
|
+
if (undeclared !== undefined) {
|
|
36
|
+
throw new Error(`cairn: concept "${id}" summaryFields key "${undeclared}" is not a declared field`);
|
|
37
|
+
}
|
|
32
38
|
const policy = urlPolicy[id] ?? {};
|
|
33
39
|
descriptors.push({
|
|
34
40
|
id,
|
|
@@ -38,6 +44,7 @@ export function normalizeConcepts(content, urlPolicy = {}, routing = CONCEPT_ROU
|
|
|
38
44
|
permalink: policy.permalink ?? defaultPermalink(id),
|
|
39
45
|
datePrefix: policy.datePrefix ?? 'day',
|
|
40
46
|
fields: config.schema.fields,
|
|
47
|
+
summaryFields,
|
|
41
48
|
validate: config.schema.validate,
|
|
42
49
|
});
|
|
43
50
|
}
|
|
@@ -8,6 +8,14 @@ export declare function frontmatterFromForm(fields: FrontmatterField[], form: Fo
|
|
|
8
8
|
* slicing the ISO string avoids a local-timezone shift.
|
|
9
9
|
*/
|
|
10
10
|
export declare function dateInputValue(value: unknown): string;
|
|
11
|
+
/**
|
|
12
|
+
* True when `s` is a canonical zero-padded `YYYY-MM-DD` string naming a real calendar date.
|
|
13
|
+
* Rejects a wrong format, an impossible month or day, and a JS date-rollover such as
|
|
14
|
+
* `2026-02-30` (which `Date` would silently roll forward to March 2). The committed form a
|
|
15
|
+
* date field carries is exactly this canonical shape, which is what the form and
|
|
16
|
+
* `dateInputValue` emit, so a value outside it is a hand-edit or odd-YAML error.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isCalendarDate(s: string): boolean;
|
|
11
19
|
/** Reassemble a markdown file from frontmatter and body for committing. */
|
|
12
20
|
export declare function serializeMarkdown(frontmatter: object, body: string): string;
|
|
13
21
|
/** Parse a markdown file into its frontmatter and body: the read-side inverse of serialize. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../../src/lib/content/frontmatter.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,gFAAgF;AAChF,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,gBAAgB,EAAE,EAC1B,IAAI,EAAE,QAAQ,GACb,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA4BzB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASrD;AAED,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3E;AAED,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG;IAC7C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC;CACd,CAGA"}
|
|
1
|
+
{"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../../src/lib/content/frontmatter.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,gFAAgF;AAChF,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,gBAAgB,EAAE,EAC1B,IAAI,EAAE,QAAQ,GACb,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA4BzB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASrD;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAYjD;AAED,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3E;AAED,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG;IAC7C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC;CACd,CAGA"}
|
|
@@ -47,6 +47,25 @@ export function dateInputValue(value) {
|
|
|
47
47
|
}
|
|
48
48
|
return '';
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* True when `s` is a canonical zero-padded `YYYY-MM-DD` string naming a real calendar date.
|
|
52
|
+
* Rejects a wrong format, an impossible month or day, and a JS date-rollover such as
|
|
53
|
+
* `2026-02-30` (which `Date` would silently roll forward to March 2). The committed form a
|
|
54
|
+
* date field carries is exactly this canonical shape, which is what the form and
|
|
55
|
+
* `dateInputValue` emit, so a value outside it is a hand-edit or odd-YAML error.
|
|
56
|
+
*/
|
|
57
|
+
export function isCalendarDate(s) {
|
|
58
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
|
|
59
|
+
if (!match)
|
|
60
|
+
return false;
|
|
61
|
+
const year = Number(match[1]);
|
|
62
|
+
const month = Number(match[2]);
|
|
63
|
+
const day = Number(match[3]);
|
|
64
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
65
|
+
return (date.getUTCFullYear() === year &&
|
|
66
|
+
date.getUTCMonth() === month - 1 &&
|
|
67
|
+
date.getUTCDate() === day);
|
|
68
|
+
}
|
|
50
69
|
/** Reassemble a markdown file from frontmatter and body for committing. */
|
|
51
70
|
export function serializeMarkdown(frontmatter, body) {
|
|
52
71
|
return matter.stringify(body, frontmatter);
|
package/dist/content/ids.d.ts
CHANGED
|
@@ -28,4 +28,11 @@ export declare function slugFromId(id: string, datePrefix: DatePrefix | null): s
|
|
|
28
28
|
* malformed date so a bad create fails before touching git.
|
|
29
29
|
*/
|
|
30
30
|
export declare function composeDatedId(date: string, slug: string, datePrefix: DatePrefix): string;
|
|
31
|
+
/**
|
|
32
|
+
* Rename an id by swapping its slug, keeping any date prefix. slugFromId strips only the leading
|
|
33
|
+
* date prefix, so the id is exactly its prefix followed by its slug; this replaces the slug suffix
|
|
34
|
+
* with newSlug. A non-dated concept passes null, so the whole id is the slug and the id becomes
|
|
35
|
+
* newSlug. The caller validates newSlug with isValidId first.
|
|
36
|
+
*/
|
|
37
|
+
export declare function renameId(oldId: string, newSlug: string, datePrefix: DatePrefix | null): string;
|
|
31
38
|
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../src/lib/content/ids.ts"],"names":[],"mappings":"AAOA,qGAAqG;AACrG,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAE7C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,yDAAyD;AACzD,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM7C;AAED,uGAAuG;AACvG,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AASlD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI,GAAG,MAAM,CAG5E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,MAAM,CAiBzF"}
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../src/lib/content/ids.ts"],"names":[],"mappings":"AAOA,qGAAqG;AACrG,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAE7C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,yDAAyD;AACzD,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM7C;AAED,uGAAuG;AACvG,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AASlD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI,GAAG,MAAM,CAG5E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,MAAM,CAiBzF;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI,GAAG,MAAM,CAI9F"}
|
package/dist/content/ids.js
CHANGED
|
@@ -71,3 +71,14 @@ export function composeDatedId(date, slug, datePrefix) {
|
|
|
71
71
|
}
|
|
72
72
|
return `${prefix}-${slug}`;
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Rename an id by swapping its slug, keeping any date prefix. slugFromId strips only the leading
|
|
76
|
+
* date prefix, so the id is exactly its prefix followed by its slug; this replaces the slug suffix
|
|
77
|
+
* with newSlug. A non-dated concept passes null, so the whole id is the slug and the id becomes
|
|
78
|
+
* newSlug. The caller validates newSlug with isValidId first.
|
|
79
|
+
*/
|
|
80
|
+
export function renameId(oldId, newSlug, datePrefix) {
|
|
81
|
+
const oldSlug = slugFromId(oldId, datePrefix);
|
|
82
|
+
const prefix = oldId.slice(0, oldId.length - oldSlug.length);
|
|
83
|
+
return prefix + newSlug;
|
|
84
|
+
}
|
package/dist/content/links.d.ts
CHANGED
|
@@ -8,6 +8,13 @@ export interface CairnRef {
|
|
|
8
8
|
export type LinkResolve = (ref: CairnRef) => string | undefined;
|
|
9
9
|
/** Parse a `cairn:<concept>/<id>` href, or null for any other href or a malformed token. */
|
|
10
10
|
export declare function parseCairnToken(href: string): CairnRef | null;
|
|
11
|
+
/** Write the `cairn:<concept>/<id>` token for a ref. The inverse of parseCairnToken, so the editor
|
|
12
|
+
* link picker and the autocomplete write exactly the form the resolver reads back. */
|
|
13
|
+
export declare function formatCairnToken(ref: CairnRef): string;
|
|
14
|
+
/** Escape the characters that would break a markdown link's display text: a backslash and the
|
|
15
|
+
* square brackets that delimit the text. Used where a content title becomes link display text,
|
|
16
|
+
* so an unbalanced bracket in a title cannot truncate the generated link. */
|
|
17
|
+
export declare function escapeLinkText(text: string): string;
|
|
11
18
|
/** The cairn links a markdown body points at, in first-occurrence order, deduped by concept/id.
|
|
12
19
|
* Parses the body as mdast, so a token inside a code span or fence is never matched. */
|
|
13
20
|
export declare function extractCairnLinks(body: string): CairnRef[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../src/lib/content/links.ts"],"names":[],"mappings":"AAUA,+EAA+E;AAC/E,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;iGACiG;AACjG,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,QAAQ,KAAK,MAAM,GAAG,SAAS,CAAC;AAEhE,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAS7D;AAED;yFACyF;AACzF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,CAa1D"}
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../src/lib/content/links.ts"],"names":[],"mappings":"AAUA,+EAA+E;AAC/E,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;iGACiG;AACjG,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,QAAQ,KAAK,MAAM,GAAG,SAAS,CAAC;AAEhE,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAS7D;AAED;uFACuF;AACvF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAEtD;AAED;;8EAE8E;AAC9E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;yFACyF;AACzF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,CAa1D"}
|
package/dist/content/links.js
CHANGED
|
@@ -21,6 +21,17 @@ export function parseCairnToken(href) {
|
|
|
21
21
|
return null;
|
|
22
22
|
return { concept, id };
|
|
23
23
|
}
|
|
24
|
+
/** Write the `cairn:<concept>/<id>` token for a ref. The inverse of parseCairnToken, so the editor
|
|
25
|
+
* link picker and the autocomplete write exactly the form the resolver reads back. */
|
|
26
|
+
export function formatCairnToken(ref) {
|
|
27
|
+
return `cairn:${ref.concept}/${ref.id}`;
|
|
28
|
+
}
|
|
29
|
+
/** Escape the characters that would break a markdown link's display text: a backslash and the
|
|
30
|
+
* square brackets that delimit the text. Used where a content title becomes link display text,
|
|
31
|
+
* so an unbalanced bracket in a title cannot truncate the generated link. */
|
|
32
|
+
export function escapeLinkText(text) {
|
|
33
|
+
return text.replace(/[\\[\]]/g, (ch) => `\\${ch}`);
|
|
34
|
+
}
|
|
24
35
|
/** The cairn links a markdown body points at, in first-occurrence order, deduped by concept/id.
|
|
25
36
|
* Parses the body as mdast, so a token inside a code span or fence is never matched. */
|
|
26
37
|
export function extractCairnLinks(body) {
|
|
@@ -34,7 +34,10 @@ export declare function emptyManifest(): Manifest;
|
|
|
34
34
|
/** Serialize canonically: entries sorted by concept then id, links sorted and deduped, a fixed key
|
|
35
35
|
* order, two-space pretty, and a trailing newline, so the committed file diffs cleanly in a PR. */
|
|
36
36
|
export declare function serializeManifest(manifest: Manifest): string;
|
|
37
|
-
/** Parse a committed manifest. Throws on malformed JSON or
|
|
37
|
+
/** Parse a committed manifest. Throws on malformed JSON, a wrong version, or a malformed entry, so
|
|
38
|
+
* every reader (the save guard, the delete path, the preview) sees a well-formed graph or a clear
|
|
39
|
+
* error. The build regenerates the manifest, so a real file is always canonical; this guards a
|
|
40
|
+
* hand-edited or truncated one. */
|
|
38
41
|
export declare function parseManifest(raw: string): Manifest;
|
|
39
42
|
/** Throw if the committed manifest drifts from what the corpus says. Both sides are compared in the
|
|
40
43
|
* canonical serialized form, so semantic equality never spuriously fails. The build calls this so a
|
|
@@ -45,6 +48,17 @@ export declare function verifyManifest(built: Manifest, committedRaw: string): v
|
|
|
45
48
|
export declare function upsertEntry(manifest: Manifest, entry: ManifestEntry): Manifest;
|
|
46
49
|
/** Drop the entry with the given concept and id, if present. The delete path's patch. */
|
|
47
50
|
export declare function removeEntry(manifest: Manifest, concept: string, id: string): Manifest;
|
|
51
|
+
/** One inbound linker: enough to name it and link to its edit page in the delete guard. */
|
|
52
|
+
export interface InboundLink {
|
|
53
|
+
concept: string;
|
|
54
|
+
id: string;
|
|
55
|
+
title: string;
|
|
56
|
+
permalink: string;
|
|
57
|
+
}
|
|
58
|
+
/** Every entry whose outbound edges point at the target, excluding the target itself. The delete
|
|
59
|
+
* guard reads this to name "what links here"; the backlinks panel will reuse it. Pure over the
|
|
60
|
+
* manifest, so the request-time delete path and a unit test call it the same way. */
|
|
61
|
+
export declare function inboundLinks(manifest: Manifest, concept: string, id: string): InboundLink[];
|
|
48
62
|
/** A resolver backed by manifest targets, for the admin preview. A miss returns undefined, so the
|
|
49
63
|
* render step marks the link broken rather than throwing. The build resolver throws instead. */
|
|
50
64
|
export declare function manifestLinkResolver(targets: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/lib/content/manifest.ts"],"names":[],"mappings":"AAQA,OAAO,EAAqB,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,4FAA4F;AAC5F,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB;AAED,yFAAyF;AACzF,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,CAAC,CAAC;IACX,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED,+EAA+E;AAC/E,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,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|
|
63
63
|
}));
|
|
64
64
|
return `${JSON.stringify({ version: 1, entries }, null, 2)}\n`;
|
|
65
65
|
}
|
|
66
|
-
/** Parse a committed manifest. Throws on malformed JSON or
|
|
66
|
+
/** Parse a committed manifest. Throws on malformed JSON, a wrong version, or a malformed entry, so
|
|
67
|
+
* every reader (the save guard, the delete path, the preview) sees a well-formed graph or a clear
|
|
68
|
+
* error. The build regenerates the manifest, so a real file is always canonical; this guards a
|
|
69
|
+
* hand-edited or truncated one. */
|
|
67
70
|
export function parseManifest(raw) {
|
|
68
71
|
const data = JSON.parse(raw);
|
|
69
|
-
if (!data || typeof data !== 'object'
|
|
72
|
+
if (!data || typeof data !== 'object') {
|
|
70
73
|
throw new Error('content manifest: malformed file, expected { version, entries: [] }');
|
|
71
74
|
}
|
|
72
|
-
|
|
75
|
+
const obj = data;
|
|
76
|
+
if (obj.version !== 1) {
|
|
77
|
+
throw new Error(`content manifest: unsupported version ${String(obj.version)}, expected 1`);
|
|
78
|
+
}
|
|
79
|
+
if (!Array.isArray(obj.entries)) {
|
|
80
|
+
throw new Error('content manifest: malformed file, expected { version, entries: [] }');
|
|
81
|
+
}
|
|
82
|
+
for (const entry of obj.entries) {
|
|
83
|
+
const e = entry;
|
|
84
|
+
const ok = e &&
|
|
85
|
+
typeof e.id === 'string' &&
|
|
86
|
+
typeof e.concept === 'string' &&
|
|
87
|
+
typeof e.title === 'string' &&
|
|
88
|
+
typeof e.permalink === 'string' &&
|
|
89
|
+
typeof e.draft === 'boolean' &&
|
|
90
|
+
(e.date === undefined || typeof e.date === 'string') &&
|
|
91
|
+
Array.isArray(e.links);
|
|
92
|
+
if (!ok) {
|
|
93
|
+
throw new Error(`content manifest: malformed entry ${JSON.stringify(e)}`);
|
|
94
|
+
}
|
|
95
|
+
// Validate each link element's shape, not just that links is an array. inboundLinks and the
|
|
96
|
+
// delete guard read l.concept and l.id, so a string, null, or id-less element would read as
|
|
97
|
+
// undefined and silently drop a real inbound linker. Reject it here instead.
|
|
98
|
+
for (const link of e.links) {
|
|
99
|
+
const l = link;
|
|
100
|
+
if (!l || typeof l !== 'object' || typeof l.concept !== 'string' || typeof l.id !== 'string') {
|
|
101
|
+
throw new Error(`content manifest: malformed link ${JSON.stringify(link)} in entry ${JSON.stringify(e)}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return { version: 1, entries: obj.entries };
|
|
73
106
|
}
|
|
74
107
|
/** Throw if the committed manifest drifts from what the corpus says. Both sides are compared in the
|
|
75
108
|
* canonical serialized form, so semantic equality never spuriously fails. The build calls this so a
|
|
@@ -90,6 +123,15 @@ export function upsertEntry(manifest, entry) {
|
|
|
90
123
|
export function removeEntry(manifest, concept, id) {
|
|
91
124
|
return { version: 1, entries: manifest.entries.filter((e) => !(e.concept === concept && e.id === id)) };
|
|
92
125
|
}
|
|
126
|
+
/** Every entry whose outbound edges point at the target, excluding the target itself. The delete
|
|
127
|
+
* guard reads this to name "what links here"; the backlinks panel will reuse it. Pure over the
|
|
128
|
+
* manifest, so the request-time delete path and a unit test call it the same way. */
|
|
129
|
+
export function inboundLinks(manifest, concept, id) {
|
|
130
|
+
return manifest.entries
|
|
131
|
+
.filter((e) => !(e.concept === concept && e.id === id))
|
|
132
|
+
.filter((e) => e.links.some((l) => l.concept === concept && l.id === id))
|
|
133
|
+
.map((e) => ({ concept: e.concept, id: e.id, title: e.title, permalink: e.permalink }));
|
|
134
|
+
}
|
|
93
135
|
/** A resolver backed by manifest targets, for the admin preview. A miss returns undefined, so the
|
|
94
136
|
* render step marks the link broken rather than throwing. The build resolver throws instead. */
|
|
95
137
|
export function manifestLinkResolver(targets) {
|
package/dist/content/types.d.ts
CHANGED
|
@@ -94,6 +94,9 @@ export interface ConceptConfig<S extends ConceptSchema = ConceptSchema> {
|
|
|
94
94
|
label?: string;
|
|
95
95
|
/** The concept's schema: the form projection, the generated validator, and the inferred type. */
|
|
96
96
|
schema: S;
|
|
97
|
+
/** Frontmatter keys to surface on each `ContentSummary.fields`, so a list card reads an authored
|
|
98
|
+
* field without a per-entry detail read. Each key should also be declared in `schema`. */
|
|
99
|
+
summaryFields?: string[];
|
|
97
100
|
}
|
|
98
101
|
/**
|
|
99
102
|
* A concept's URL policy, set per concept in the YAML site-config (not the adapter). `permalink` is
|
|
@@ -194,6 +197,9 @@ export interface ConceptDescriptor {
|
|
|
194
197
|
/** Filename date-prefix granularity for a dated concept; resolved by `normalizeConcepts`. */
|
|
195
198
|
datePrefix: DatePrefix;
|
|
196
199
|
fields: FrontmatterField[];
|
|
200
|
+
/** Frontmatter keys the index copies onto each summary's `fields` record. `normalizeConcepts`
|
|
201
|
+
* resolves it to `[]` when a concept omits `summaryFields`. */
|
|
202
|
+
summaryFields: string[];
|
|
197
203
|
validate(frontmatter: Record<string, unknown>, body: string): ValidationResult;
|
|
198
204
|
}
|
|
199
205
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/content/types.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,0GAA0G;AAC1G,UAAU,SAAS;IACjB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,gCAAgC;AAChC,MAAM,WAAW,SAAU,SAAQ,SAAS;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,GAAG,CAAC,EAAE,MAAM,CAAC;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AAE,aAAa,CAAC;IACxB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,qGAAqG;IACrG,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,mGAAmG;IACnG,UAAU,CAAC,EAAE,YAAY,EAAE,CAAC;CAC7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/lib/content/validate.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGrE;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,gBAAgB,EAAE,EAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACnC,gBAAgB,
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/lib/content/validate.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGrE;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,gBAAgB,EAAE,EAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACnC,gBAAgB,CAoClB"}
|
package/dist/content/validate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dateInputValue } from './frontmatter.js';
|
|
1
|
+
import { dateInputValue, isCalendarDate } from './frontmatter.js';
|
|
2
2
|
/**
|
|
3
3
|
* Validate raw frontmatter against a field list. Required text and date fields must be
|
|
4
4
|
* non-empty; required tag fields must be non-empty lists. A present boolean coerces to `true`
|
|
@@ -27,6 +27,11 @@ export function validateFields(fields, frontmatter) {
|
|
|
27
27
|
const list = Array.isArray(value) ? value.map(String) : [];
|
|
28
28
|
if (field.required && list.length === 0)
|
|
29
29
|
errors[field.name] = `${field.label} is required`;
|
|
30
|
+
else if (field.type === 'tags') {
|
|
31
|
+
const unknown = list.find((tag) => !field.options.includes(tag));
|
|
32
|
+
if (unknown !== undefined)
|
|
33
|
+
errors[field.name] = `${field.label} contains an unknown value: ${unknown}`;
|
|
34
|
+
}
|
|
30
35
|
if (list.length > 0)
|
|
31
36
|
data[field.name] = list;
|
|
32
37
|
break;
|
|
@@ -35,6 +40,8 @@ export function validateFields(fields, frontmatter) {
|
|
|
35
40
|
const text = value instanceof Date ? dateInputValue(value) : typeof value === 'string' ? value.trim() : '';
|
|
36
41
|
if (field.required && text === '')
|
|
37
42
|
errors[field.name] = `${field.label} is required`;
|
|
43
|
+
else if (text !== '' && !isCalendarDate(text))
|
|
44
|
+
errors[field.name] = `${field.label} must be a valid date (YYYY-MM-DD)`;
|
|
38
45
|
if (text !== '')
|
|
39
46
|
data[field.name] = text;
|
|
40
47
|
break;
|
|
@@ -6,6 +6,9 @@ export interface RawFile {
|
|
|
6
6
|
}
|
|
7
7
|
/** The cheap, plain-data view of one entry, for lists, feeds, and the sitemap. */
|
|
8
8
|
export interface ContentSummary {
|
|
9
|
+
/** The descriptor id this entry belongs to, e.g. "posts". Lets a list or page branch per
|
|
10
|
+
* concept without re-deriving it from a proxy like `entry.date`. */
|
|
11
|
+
concept: string;
|
|
9
12
|
id: string;
|
|
10
13
|
slug: string;
|
|
11
14
|
permalink: string;
|
|
@@ -16,6 +19,10 @@ export interface ContentSummary {
|
|
|
16
19
|
excerpt: string;
|
|
17
20
|
wordCount: number;
|
|
18
21
|
draft: boolean;
|
|
22
|
+
/** The frontmatter keys the descriptor nominated via `summaryFields`, read off the validated,
|
|
23
|
+
* normalized frontmatter. Held in a separate record so a nominated key cannot collide with a
|
|
24
|
+
* typed summary field. Empty when the concept declares no `summaryFields`. */
|
|
25
|
+
fields: Record<string, unknown>;
|
|
19
26
|
}
|
|
20
27
|
/** The detail view: a summary plus the frontmatter and the body to render. The frontmatter
|
|
21
28
|
* type defaults to `Record<string, unknown>`; the typed-reads pass infers it from the concept
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-index.d.ts","sourceRoot":"","sources":["../../src/lib/delivery/content-index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,yFAAyF;AACzF,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AAED,kFAAkF;AAClF,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"content-index.d.ts","sourceRoot":"","sources":["../../src/lib/delivery/content-index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,yFAAyF;AACzF,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AAED,kFAAkF;AAClF,MAAM,WAAW,cAAc;IAC7B;yEACqE;IACrE,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,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OAAO,EAAE,CAElE;AAqBD,4EAA4E;AAC5E,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5D,KAAK,EAAE,OAAO,EAAE,EAChB,UAAU,EAAE,iBAAiB,GAC5B,YAAY,CAAC,CAAC,CAAC,CA4EjB"}
|
|
@@ -44,7 +44,13 @@ export function createContentIndex(files, descriptor) {
|
|
|
44
44
|
problems.push({ id, draft, errors: result.errors });
|
|
45
45
|
continue;
|
|
46
46
|
}
|
|
47
|
+
const summaryFieldValues = {};
|
|
48
|
+
for (const key of descriptor.summaryFields) {
|
|
49
|
+
if (key in result.data)
|
|
50
|
+
summaryFieldValues[key] = result.data[key];
|
|
51
|
+
}
|
|
47
52
|
entries.push({
|
|
53
|
+
concept: descriptor.id,
|
|
48
54
|
id,
|
|
49
55
|
slug,
|
|
50
56
|
permalink: permalink(descriptor, { id, slug, date }),
|
|
@@ -55,6 +61,7 @@ export function createContentIndex(files, descriptor) {
|
|
|
55
61
|
excerpt: deriveExcerpt(body, { description: asString(raw.description) }),
|
|
56
62
|
wordCount: wordCount(body),
|
|
57
63
|
draft,
|
|
64
|
+
fields: summaryFieldValues,
|
|
58
65
|
frontmatter: result.data,
|
|
59
66
|
body,
|
|
60
67
|
});
|