@mvarble/mesearch-cms 0.1.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/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/cms.d.ts +22 -0
- package/dist/cms.js +270 -0
- package/dist/cms.js.map +1 -0
- package/dist/core/bibtex.d.ts +6 -0
- package/dist/core/bibtex.js +129 -0
- package/dist/core/bibtex.js.map +1 -0
- package/dist/core/build.d.ts +29 -0
- package/dist/core/build.js +41 -0
- package/dist/core/build.js.map +1 -0
- package/dist/core/facts.d.ts +4 -0
- package/dist/core/facts.js +39 -0
- package/dist/core/facts.js.map +1 -0
- package/dist/core/frontmatter.d.ts +26 -0
- package/dist/core/frontmatter.js +134 -0
- package/dist/core/frontmatter.js.map +1 -0
- package/dist/core/paths.d.ts +4 -0
- package/dist/core/paths.js +17 -0
- package/dist/core/paths.js.map +1 -0
- package/dist/core/resolver.d.ts +33 -0
- package/dist/core/resolver.js +45 -0
- package/dist/core/resolver.js.map +1 -0
- package/dist/core/scopes.d.ts +9 -0
- package/dist/core/scopes.js +29 -0
- package/dist/core/scopes.js.map +1 -0
- package/dist/core/source.d.ts +15 -0
- package/dist/core/source.js +68 -0
- package/dist/core/source.js.map +1 -0
- package/dist/core/statements.d.ts +18 -0
- package/dist/core/statements.js +65 -0
- package/dist/core/statements.js.map +1 -0
- package/dist/core/store.d.ts +67 -0
- package/dist/core/store.js +115 -0
- package/dist/core/store.js.map +1 -0
- package/dist/core/walk.d.ts +19 -0
- package/dist/core/walk.js +122 -0
- package/dist/core/walk.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/model/build.d.ts +13 -0
- package/dist/model/build.js +67 -0
- package/dist/model/build.js.map +1 -0
- package/dist/model/index.d.ts +2 -0
- package/dist/model/index.js +3 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/outline.d.ts +11 -0
- package/dist/model/outline.js +51 -0
- package/dist/model/outline.js.map +1 -0
- package/dist/presets/blog/index.d.ts +9 -0
- package/dist/presets/blog/index.js +346 -0
- package/dist/presets/blog/index.js.map +1 -0
- package/dist/presets/blog/runtime.d.ts +60 -0
- package/dist/presets/blog/runtime.js +55 -0
- package/dist/presets/blog/runtime.js.map +1 -0
- package/dist/presets/blog/types.d.ts +48 -0
- package/dist/presets/blog/types.js +2 -0
- package/dist/presets/blog/types.js.map +1 -0
- package/dist/presets/mesearch/dates.d.ts +6 -0
- package/dist/presets/mesearch/dates.js +100 -0
- package/dist/presets/mesearch/dates.js.map +1 -0
- package/dist/presets/mesearch/index.d.ts +13 -0
- package/dist/presets/mesearch/index.js +407 -0
- package/dist/presets/mesearch/index.js.map +1 -0
- package/dist/presets/mesearch/runtime.d.ts +56 -0
- package/dist/presets/mesearch/runtime.js +57 -0
- package/dist/presets/mesearch/runtime.js.map +1 -0
- package/dist/presets/mesearch/types.d.ts +46 -0
- package/dist/presets/mesearch/types.js +8 -0
- package/dist/presets/mesearch/types.js.map +1 -0
- package/dist/resolvers/citation.d.ts +38 -0
- package/dist/resolvers/citation.js +60 -0
- package/dist/resolvers/citation.js.map +1 -0
- package/dist/resolvers/equation.d.ts +12 -0
- package/dist/resolvers/equation.js +52 -0
- package/dist/resolvers/equation.js.map +1 -0
- package/dist/resolvers/index.d.ts +4 -0
- package/dist/resolvers/index.js +5 -0
- package/dist/resolvers/index.js.map +1 -0
- package/dist/resolvers/page.d.ts +18 -0
- package/dist/resolvers/page.js +61 -0
- package/dist/resolvers/page.js.map +1 -0
- package/dist/resolvers/statement.d.ts +13 -0
- package/dist/resolvers/statement.js +45 -0
- package/dist/resolvers/statement.js.map +1 -0
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +20 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { SourceFile } from "./source.js";
|
|
2
|
+
const anchorKey = (kind, scope, slug) => `${kind}\0${scope}\0${slug}`;
|
|
3
|
+
const refKey = (resolver, written) => `${resolver}\0${written}`;
|
|
4
|
+
// Everything the content layer knows, rebuilt from scratch on every scan.
|
|
5
|
+
//
|
|
6
|
+
// Rebuilding is cheap and is the only way stale entries for renamed or deleted
|
|
7
|
+
// content disappear; it also makes the result independent of which file
|
|
8
|
+
// happened to change. Nothing here is incremental on purpose.
|
|
9
|
+
export class Store {
|
|
10
|
+
root;
|
|
11
|
+
siteMacros;
|
|
12
|
+
docs = new Map();
|
|
13
|
+
pages = new Map();
|
|
14
|
+
anchors = new Map();
|
|
15
|
+
diagnostics = [];
|
|
16
|
+
// Scope documents by the slug an author writes to reach into them, and the
|
|
17
|
+
// way an author would name them in an error message.
|
|
18
|
+
scopes = new Map();
|
|
19
|
+
scopeNames = new Map();
|
|
20
|
+
// Whatever a preset keeps that the generic tables do not cover: posts,
|
|
21
|
+
// sequences, citations, the graph. Insertion order is kept.
|
|
22
|
+
collections = new Map();
|
|
23
|
+
pageByDoc = new Map();
|
|
24
|
+
refs = new Map();
|
|
25
|
+
files = new Map();
|
|
26
|
+
injections = new Map();
|
|
27
|
+
constructor(root, siteMacros = {}) {
|
|
28
|
+
this.root = root;
|
|
29
|
+
this.siteMacros = siteMacros;
|
|
30
|
+
}
|
|
31
|
+
// The parsed file behind an id, read on first use.
|
|
32
|
+
file(id) {
|
|
33
|
+
let file = this.files.get(id);
|
|
34
|
+
if (!file) {
|
|
35
|
+
file = new SourceFile(this.root, id);
|
|
36
|
+
this.files.set(id, file);
|
|
37
|
+
const problem = file.frontmatterProblem;
|
|
38
|
+
if (problem)
|
|
39
|
+
this.error(id, problem);
|
|
40
|
+
}
|
|
41
|
+
return file;
|
|
42
|
+
}
|
|
43
|
+
hasFile(id) {
|
|
44
|
+
return this.files.has(id);
|
|
45
|
+
}
|
|
46
|
+
addDoc(doc) {
|
|
47
|
+
this.docs.set(doc.id, doc);
|
|
48
|
+
return doc;
|
|
49
|
+
}
|
|
50
|
+
addPage(page) {
|
|
51
|
+
this.pages.set(page.pathname, page);
|
|
52
|
+
this.pageByDoc.set(page.doc, page.pathname);
|
|
53
|
+
return page;
|
|
54
|
+
}
|
|
55
|
+
// The page a document is shown on: its own, or its host's.
|
|
56
|
+
pathnameOf(id) {
|
|
57
|
+
const own = this.pageByDoc.get(id);
|
|
58
|
+
if (own !== undefined)
|
|
59
|
+
return own;
|
|
60
|
+
const host = this.docs.get(id)?.host;
|
|
61
|
+
return host && host != id ? this.pathnameOf(host) : undefined;
|
|
62
|
+
}
|
|
63
|
+
ownPathname(id) {
|
|
64
|
+
return this.pageByDoc.get(id);
|
|
65
|
+
}
|
|
66
|
+
addAnchor(anchor) {
|
|
67
|
+
this.anchors.set(anchorKey(anchor.kind, anchor.scope, anchor.slug), anchor);
|
|
68
|
+
}
|
|
69
|
+
anchor(kind, scope, slug) {
|
|
70
|
+
return this.anchors.get(anchorKey(kind, scope, slug));
|
|
71
|
+
}
|
|
72
|
+
addRef(doc, ref) {
|
|
73
|
+
let refs = this.refs.get(doc);
|
|
74
|
+
if (!refs)
|
|
75
|
+
this.refs.set(doc, (refs = new Map()));
|
|
76
|
+
refs.set(refKey(ref.resolver, ref.written), ref);
|
|
77
|
+
}
|
|
78
|
+
ref(doc, resolver, written) {
|
|
79
|
+
return this.refs.get(doc)?.get(refKey(resolver, written));
|
|
80
|
+
}
|
|
81
|
+
refsOf(doc) {
|
|
82
|
+
return [...(this.refs.get(doc)?.values() ?? [])];
|
|
83
|
+
}
|
|
84
|
+
collection(name) {
|
|
85
|
+
let collection = this.collections.get(name);
|
|
86
|
+
if (!collection)
|
|
87
|
+
this.collections.set(name, (collection = new Map()));
|
|
88
|
+
return collection;
|
|
89
|
+
}
|
|
90
|
+
// What the Vite plugin appends to a document's compiled module as
|
|
91
|
+
// `export const cms = ...`.
|
|
92
|
+
inject(doc, value) {
|
|
93
|
+
this.injections.set(doc, value);
|
|
94
|
+
}
|
|
95
|
+
injection(doc) {
|
|
96
|
+
return this.injections.get(doc);
|
|
97
|
+
}
|
|
98
|
+
// The KaTeX macros a document renders with: the site's, then each ancestor
|
|
99
|
+
// along `macroParent` from the furthest down, then its own. The nearer
|
|
100
|
+
// definition of a name wins.
|
|
101
|
+
foldedMacros(id) {
|
|
102
|
+
const chain = [];
|
|
103
|
+
const seen = new Set();
|
|
104
|
+
for (let doc = this.docs.get(id); doc && !seen.has(doc.id);) {
|
|
105
|
+
seen.add(doc.id);
|
|
106
|
+
chain.unshift(doc.macros);
|
|
107
|
+
doc = doc.macroParent ? this.docs.get(doc.macroParent) : undefined;
|
|
108
|
+
}
|
|
109
|
+
return Object.assign({}, this.siteMacros, ...chain);
|
|
110
|
+
}
|
|
111
|
+
error(file, message) {
|
|
112
|
+
this.diagnostics.push({ file, message });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/core/store.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAwDzC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,IAAY,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,KAAK,KAAK,IAAI,EAAE,CAAC;AAC9F,MAAM,MAAM,GAAG,CAAC,QAAgB,EAAE,OAAe,EAAE,EAAE,CAAC,GAAG,QAAQ,KAAK,OAAO,EAAE,CAAC;AAEhF,0EAA0E;AAC1E,EAAE;AACF,+EAA+E;AAC/E,wEAAwE;AACxE,8DAA8D;AAC9D,MAAM,OAAO,KAAK;IACL,IAAI,CAAS;IACb,UAAU,CAAc;IACxB,IAAI,GAAG,IAAI,GAAG,EAAqB,CAAC;IACpC,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;IACtC,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IACpC,WAAW,GAAiB,EAAE,CAAC;IACxC,2EAA2E;IAC3E,qDAAq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;QAC/B,KAAK,IAAI,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC;YAC1D,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACjB,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAC1B,GAAG,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACvE,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,GAAG,KAAK,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,IAAY,EAAE,OAAe;QAC/B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAC7C,CAAC;CACJ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Heading } from '../model/outline.ts';
|
|
2
|
+
import type { SourceFile } from './source.ts';
|
|
3
|
+
export interface WalkTarget {
|
|
4
|
+
doc: string;
|
|
5
|
+
scope: string;
|
|
6
|
+
page: string;
|
|
7
|
+
host: string;
|
|
8
|
+
}
|
|
9
|
+
export interface WalkOptions {
|
|
10
|
+
onMath?(tex: string, target: WalkTarget): void;
|
|
11
|
+
onImport?(id: string, target: WalkTarget): void;
|
|
12
|
+
isComponent?(specifier: string, from: string): boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function walkDocument(file: SourceFile, target: WalkTarget, options: WalkOptions): void;
|
|
15
|
+
export interface HeadingOptions {
|
|
16
|
+
depth: number;
|
|
17
|
+
mathDelimiters?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function parseHeadings(file: SourceFile, options: HeadingOptions): Heading[];
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { unified } from 'unified';
|
|
2
|
+
import rehypeParse from 'rehype-parse';
|
|
3
|
+
import { visit } from 'unist-util-visit';
|
|
4
|
+
import { fromJs } from 'esast-util-from-js';
|
|
5
|
+
import { headingSlugs } from "../model/outline.js";
|
|
6
|
+
import { resolveId } from "./paths.js";
|
|
7
|
+
const rehype = unified().use(rehypeParse);
|
|
8
|
+
// `<Statement {...x} />`, which mdsvex leaves in the text of a paragraph rather
|
|
9
|
+
// than as HTML.
|
|
10
|
+
const componentRegex = /<(\w+)\s+\{\.\.\.(\w+)\}\s*(\/?)>/g;
|
|
11
|
+
// Walks a document in reading order --- through the markdown, into raw HTML,
|
|
12
|
+
// and down into the documents it renders --- so that anything numbered on the
|
|
13
|
+
// way is numbered in the order a reader meets it.
|
|
14
|
+
export function walkDocument(file, target, options) {
|
|
15
|
+
const nodes = [];
|
|
16
|
+
const imports = {};
|
|
17
|
+
const remarkNodes = (children) => children.toReversed().map((source) => ({ kind: 'remark', source }));
|
|
18
|
+
const rehypeNodes = (children) => children.toReversed().map((source) => ({ kind: 'rehype', source }));
|
|
19
|
+
nodes.push(...remarkNodes(file.mdast.children));
|
|
20
|
+
while (nodes.length > 0) {
|
|
21
|
+
const typed = nodes.pop();
|
|
22
|
+
if (typed.kind == 'remark') {
|
|
23
|
+
const node = typed.source;
|
|
24
|
+
if ('children' in node && Array.isArray(node.children) && node.children.length) {
|
|
25
|
+
nodes.push(...remarkNodes(node.children));
|
|
26
|
+
}
|
|
27
|
+
if (node.type == 'html') {
|
|
28
|
+
nodes.push(...rehypeNodes(rehype.parse(node.value).children));
|
|
29
|
+
}
|
|
30
|
+
if (node.type == 'math')
|
|
31
|
+
options.onMath?.(node.value, target);
|
|
32
|
+
// Components that mdsvex does not see as HTML. A spread of an
|
|
33
|
+
// imported document into the statement component renders it.
|
|
34
|
+
if (node.type == 'text') {
|
|
35
|
+
for (const [, component, prop] of node.value.matchAll(componentRegex)) {
|
|
36
|
+
const componentPath = imports[component];
|
|
37
|
+
const propPath = imports[prop];
|
|
38
|
+
if (componentPath &&
|
|
39
|
+
propPath &&
|
|
40
|
+
options.isComponent?.(componentPath, file.id)) {
|
|
41
|
+
options.onImport?.(resolveId(file.id, propPath), target);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const node = typed.source;
|
|
48
|
+
if ('children' in node && Array.isArray(node.children) && node.children.length) {
|
|
49
|
+
nodes.push(...rehypeNodes(node.children));
|
|
50
|
+
}
|
|
51
|
+
collectImports(node, imports);
|
|
52
|
+
if (node.type == 'element') {
|
|
53
|
+
const componentPath = imports[node.tagName];
|
|
54
|
+
if (componentPath && componentPath.endsWith('.svx')) {
|
|
55
|
+
options.onImport?.(resolveId(file.id, componentPath), target);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// The default and namespace imports of a `<script>` block that could name a
|
|
62
|
+
// document or a component, by local name.
|
|
63
|
+
function collectImports(node, imports) {
|
|
64
|
+
if (node.type != 'element' ||
|
|
65
|
+
node.tagName != 'script' ||
|
|
66
|
+
node.children.length != 1 ||
|
|
67
|
+
node.children[0].type != 'text') {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
let program;
|
|
71
|
+
try {
|
|
72
|
+
program = fromJs(node.children[0].value, { module: true });
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// TypeScript, or a script still being typed. Neither can import a
|
|
76
|
+
// document the content layer would need to number.
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
for (const statement of program.body) {
|
|
80
|
+
visit(statement, 'ImportDeclaration', (found) => {
|
|
81
|
+
const declaration = found;
|
|
82
|
+
const source = declaration.source.value;
|
|
83
|
+
const [specifier, ...rest] = declaration.specifiers;
|
|
84
|
+
if (typeof source == 'string' &&
|
|
85
|
+
source &&
|
|
86
|
+
specifier &&
|
|
87
|
+
rest.length == 0 &&
|
|
88
|
+
(specifier.type == 'ImportDefaultSpecifier' ||
|
|
89
|
+
specifier.type == 'ImportNamespaceSpecifier')) {
|
|
90
|
+
imports[specifier.local.name] = source;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// A document's own top-level headings, with the slugs their rendered `id`s get.
|
|
96
|
+
//
|
|
97
|
+
// Only the document's own: a statement it imports is a theorem or a remark,
|
|
98
|
+
// whose content belongs to the page's numbering rather than to its outline.
|
|
99
|
+
export function parseHeadings(file, options) {
|
|
100
|
+
const headings = [];
|
|
101
|
+
for (const node of file.mdast.children) {
|
|
102
|
+
if (node.type != 'heading' || node.depth > options.depth)
|
|
103
|
+
continue;
|
|
104
|
+
headings.push({ depth: node.depth, title: textOf(node, options.mathDelimiters ?? false) });
|
|
105
|
+
}
|
|
106
|
+
const slugs = headingSlugs(headings.map(({ title }) => title.replaceAll('$', '')));
|
|
107
|
+
return headings.map((heading, item) => ({ ...heading, slug: slugs[item] }));
|
|
108
|
+
}
|
|
109
|
+
// A heading's text as a reader sees it, near enough: inline markup contributes
|
|
110
|
+
// its own text, and anything without any --- an image, say --- contributes
|
|
111
|
+
// nothing. Math is left as its source.
|
|
112
|
+
function textOf(node, delimit) {
|
|
113
|
+
if (node.type == 'inlineMath')
|
|
114
|
+
return delimit ? `$${node.value}$` : node.value;
|
|
115
|
+
if (node.type == 'text' || node.type == 'inlineCode')
|
|
116
|
+
return node.value;
|
|
117
|
+
if ('children' in node && Array.isArray(node.children)) {
|
|
118
|
+
return node.children.map((child) => textOf(child, delimit)).join('');
|
|
119
|
+
}
|
|
120
|
+
return '';
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=walk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walk.js","sourceRoot":"","sources":["../../src/core/walk.ts"],"names":[],"mapp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AC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IACnF,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAE,EAAE,CAAC,CAAC,CAAC;AACjF,CAAC;AAED,+EAA+E;AAC/E,2EAA2E;AAC3E,uCAAuC;AACvC,SAAS,MAAM,CAAC,IAAmB,EAAE,OAAgB;IACjD,IAAI,IAAI,CAAC,IAAI,IAAI,YAAY;QAAE,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;IAC/E,IAAI,IAAI,CAAC,IAAI,IAAI,MAAM,IAAI,IAAI,CAAC,IAAI,IAAI,YAAY;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC;IACxE,IAAI,UAAU,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACrD,OAAQ,IAAI,CAAC,QAA4B,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9F,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { createCms, type Cms, type CmsOptions } from './cms.ts';
|
|
2
|
+
export { buildStore, defaultCrossReference, docRecord, type BuildOptions, type Doctype, type Preset, } from './core/build.ts';
|
|
3
|
+
export { allFacts, diffFacts, documentFacts } from './core/facts.ts';
|
|
4
|
+
export { Frontmatter, parseFrontmatter, stripFrontmatter } from './core/frontmatter.ts';
|
|
5
|
+
export { resolveId, slugFromFilename, toAbsolute, toId } from './core/paths.ts';
|
|
6
|
+
export { matchLink, resolveReferences, type LinkNode, type MathNode, type Resolver, } from './core/resolver.ts';
|
|
7
|
+
export { describeScope, parseReference, resolveReferenceScope, unresolvedReference, type ParsedReference, } from './core/scopes.ts';
|
|
8
|
+
export { scan, SourceFile } from './core/source.ts';
|
|
9
|
+
export { Store, type Anchor, type Diagnostic, type DocRecord, type PageRecord, type ResolvedRef, } from './core/store.ts';
|
|
10
|
+
export { parseHeadings, walkDocument, type HeadingOptions, type WalkOptions, type WalkTarget, } from './core/walk.ts';
|
|
11
|
+
export * from './model/index.ts';
|
|
12
|
+
export * from './resolvers/index.ts';
|
|
13
|
+
export { live } from './runtime.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { createCms } from "./cms.js";
|
|
2
|
+
export { buildStore, defaultCrossReference, docRecord, } from "./core/build.js";
|
|
3
|
+
export { allFacts, diffFacts, documentFacts } from "./core/facts.js";
|
|
4
|
+
export { Frontmatter, parseFrontmatter, stripFrontmatter } from "./core/frontmatter.js";
|
|
5
|
+
export { resolveId, slugFromFilename, toAbsolute, toId } from "./core/paths.js";
|
|
6
|
+
export { matchLink, resolveReferences, } from "./core/resolver.js";
|
|
7
|
+
export { describeScope, parseReference, resolveReferenceScope, unresolvedReference, } from "./core/scopes.js";
|
|
8
|
+
export { scan, SourceFile } from "./core/source.js";
|
|
9
|
+
export { Store, } from "./core/store.js";
|
|
10
|
+
export { parseHeadings, walkDocument, } from "./core/walk.js";
|
|
11
|
+
export * from "./model/index.js";
|
|
12
|
+
export * from "./resolvers/index.js";
|
|
13
|
+
export { live } from "./runtime.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA6B,MAAM,UAAU,CAAC;AAChE,OAAO,EACH,UAAU,EACV,qBAAqB,EACrB,SAAS,GAIZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACxF,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EACH,SAAS,EACT,iBAAiB,GAIpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACH,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,mBAAmB,GAEtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACH,KAAK,GAMR,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACH,aAAa,EACb,YAAY,GAIf,MAAM,gBAAgB,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface PageTree {
|
|
2
|
+
appendix: boolean;
|
|
3
|
+
children?: PageTree[];
|
|
4
|
+
}
|
|
5
|
+
export type PageLabels = ReadonlyMap<PageTree, string>;
|
|
6
|
+
export declare function labelPages(children: readonly PageTree[]): PageLabels;
|
|
7
|
+
export declare class Numbering {
|
|
8
|
+
private item;
|
|
9
|
+
private prefix;
|
|
10
|
+
constructor(prefix?: string);
|
|
11
|
+
enter(label: string | undefined): void;
|
|
12
|
+
next(): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Where every position-dependent label on the site is decided.
|
|
2
|
+
//
|
|
3
|
+
// Labels used to be computed in four places at once -- a running `item` and
|
|
4
|
+
// `itemPrefix` threaded through the markdown walk, a prefix-change reset in the
|
|
5
|
+
// sequence loop, an appendix-lettering block inside the sequence insert, and a
|
|
6
|
+
// `${label}.${i}` string built during the page-tree recursion. Nothing in that
|
|
7
|
+
// arrangement could be read, or tested, without a database underneath it.
|
|
8
|
+
//
|
|
9
|
+
// Both rules live here instead, as plain functions over plain data.
|
|
10
|
+
export function labelPages(children) {
|
|
11
|
+
const labels = new Map();
|
|
12
|
+
let appendixStart = undefined;
|
|
13
|
+
for (let i = 0; i < children.length; i++) {
|
|
14
|
+
const child = children[i];
|
|
15
|
+
if (child.appendix && appendixStart === undefined)
|
|
16
|
+
appendixStart = i;
|
|
17
|
+
const label = appendixStart === undefined
|
|
18
|
+
? String(i)
|
|
19
|
+
: String.fromCharCode('A'.charCodeAt(0) + i - appendixStart);
|
|
20
|
+
labelDescendants(labels, child, label);
|
|
21
|
+
}
|
|
22
|
+
return labels;
|
|
23
|
+
}
|
|
24
|
+
function labelDescendants(labels, node, label) {
|
|
25
|
+
labels.set(node, label);
|
|
26
|
+
(node.children ?? []).forEach((child, i) => labelDescendants(labels, child, `${label}.${i}`));
|
|
27
|
+
}
|
|
28
|
+
// The single counter behind every statement and equation label.
|
|
29
|
+
//
|
|
30
|
+
// Statements and equations share one run of numbers, in the order a reader
|
|
31
|
+
// meets them, so a page whose first two items are an equation and a statement
|
|
32
|
+
// labels them 0 and 1 -- not 0 and 0. Inside an enumerated sequence the page's
|
|
33
|
+
// own label prefixes that number, giving '3.0', '3.1', and so on.
|
|
34
|
+
export class Numbering {
|
|
35
|
+
item = 0;
|
|
36
|
+
prefix;
|
|
37
|
+
// `prefix` is the label of the first page to be numbered: the sequence root
|
|
38
|
+
// carries '0' when the sequence is enumerated, and a post carries none.
|
|
39
|
+
//
|
|
40
|
+
// Written out rather than as a constructor parameter property, which emits
|
|
41
|
+
// code and so cannot be stripped: keeping this file free of anything but
|
|
42
|
+
// types is what lets the tests import it without a build step.
|
|
43
|
+
constructor(prefix) {
|
|
44
|
+
this.prefix = prefix;
|
|
45
|
+
}
|
|
46
|
+
// Move on to the page labelled `label`, restarting the count if that is a
|
|
47
|
+
// different prefix from the page before.
|
|
48
|
+
//
|
|
49
|
+
// The reset is keyed on the prefix rather than on the page because of a
|
|
50
|
+
// quirk that is load-bearing for already-published content: an enumerated
|
|
51
|
+
// sequence's root and its first child both carry the label '0', so the
|
|
52
|
+
// child continues the root's run instead of restarting at '0.0'. A page
|
|
53
|
+
// with no label -- every page of an unenumerated sequence -- never resets,
|
|
54
|
+
// leaving one continuous count across the whole sequence.
|
|
55
|
+
enter(label) {
|
|
56
|
+
if (typeof label == 'string' && label != this.prefix) {
|
|
57
|
+
this.item = 0;
|
|
58
|
+
this.prefix = label;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// The label for the next statement or equation, consuming a number.
|
|
62
|
+
next() {
|
|
63
|
+
const item = this.item++;
|
|
64
|
+
return typeof this.prefix == 'string' ? `${this.prefix}.${item}` : `${item}`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/model/build.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,EAAE;AACF,4EAA4E;AAC5E,gFAAgF;AAChF,+EAA+E;AAC/E,+EAA+E;AAC/E,0EAA0E;AAC1E,EAAE;AACF,oEAAoE;AAiBpE,MAAM,UAAU,UAAU,CAAC,QAA6B;IACpD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC3C,IAAI,aAAa,GAAuB,SAAS,CAAC;IAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAE,CAAC;QAC3B,IAAI,KAAK,CAAC,QAAQ,IAAI,aAAa,K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ACnD,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;YACd,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACxB,CAAC;IACL,CAAC;IAED,oEAAoE;IACpE,IAAI;QACA,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACzB,OAAO,OAAO,IAAI,CAAC,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC;IACjF,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAkC,MAAM,YAAY,CAAC;AACnF,OAAO,EACH,YAAY,EACZ,YAAY,EACZ,cAAc,GAGjB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface Heading {
|
|
2
|
+
depth: number;
|
|
3
|
+
title: string;
|
|
4
|
+
slug: string;
|
|
5
|
+
}
|
|
6
|
+
export interface OutlineEntry extends Heading {
|
|
7
|
+
children: OutlineEntry[];
|
|
8
|
+
}
|
|
9
|
+
export declare function slugifyHeading(title: string): string;
|
|
10
|
+
export declare function headingSlugs(titles: readonly string[]): string[];
|
|
11
|
+
export declare function buildOutline(headings: readonly Heading[]): OutlineEntry[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// The rules for turning a document's headings into an outline.
|
|
2
|
+
//
|
|
3
|
+
// Kept free of anything but types so the tests can import it directly: the
|
|
4
|
+
// slugs decide what every section anchor on a site is called, so getting them
|
|
5
|
+
// wrong renames URLs people may have linked to.
|
|
6
|
+
// A URL fragment for a heading: lowercase, with any run of characters that has
|
|
7
|
+
// no business in a fragment collapsed to a single hyphen.
|
|
8
|
+
export function slugifyHeading(title) {
|
|
9
|
+
return title
|
|
10
|
+
.toLowerCase()
|
|
11
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
12
|
+
.replace(/^-+|-+$/g, '');
|
|
13
|
+
}
|
|
14
|
+
// Slugs for a document's headings, in order.
|
|
15
|
+
//
|
|
16
|
+
// Two headings can easily share a title -- 'Notation' under two different
|
|
17
|
+
// chapters of the same page -- so a repeat is suffixed. A heading whose title
|
|
18
|
+
// slugifies to nothing at all (one that is only math, say) falls back to its
|
|
19
|
+
// position, which is stable as long as the document above it does not change.
|
|
20
|
+
export function headingSlugs(titles) {
|
|
21
|
+
const used = new Map();
|
|
22
|
+
return titles.map((title, index) => {
|
|
23
|
+
const base = slugifyHeading(title) || `section-${index}`;
|
|
24
|
+
const seen = used.get(base) ?? 0;
|
|
25
|
+
used.set(base, seen + 1);
|
|
26
|
+
return seen == 0 ? base : `${base}-${seen + 1}`;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// Nests each heading under the nearest heading above it that is shallower.
|
|
30
|
+
//
|
|
31
|
+
// A heading with nothing shallower above it -- a `##` before any `#` -- stands
|
|
32
|
+
// on its own rather than being dropped: a document is free to be written that
|
|
33
|
+
// way, and silently losing a section from the table of contents would be worse
|
|
34
|
+
// than an uneven tree. Two such `##`s are siblings, not parent and child.
|
|
35
|
+
export function buildOutline(headings) {
|
|
36
|
+
const out = [];
|
|
37
|
+
const open = [];
|
|
38
|
+
for (const heading of headings) {
|
|
39
|
+
const entry = { ...heading, children: [] };
|
|
40
|
+
while (open.length > 0 && open.at(-1).depth >= heading.depth)
|
|
41
|
+
open.pop();
|
|
42
|
+
const parent = open.at(-1);
|
|
43
|
+
if (parent)
|
|
44
|
+
parent.children.push(entry);
|
|
45
|
+
else
|
|
46
|
+
out.push(entry);
|
|
47
|
+
open.push(entry);
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=outline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outline.js","sourceRo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AG,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK;YAAE,IAAI,CAAC,GAAG,EAAE,CAAC;QAC1E,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,MAAM;YAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;;YACnC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Preset } from '../../core/build.ts';
|
|
2
|
+
export type * from './types.ts';
|
|
3
|
+
export type { BlogCms } from './runtime.ts';
|
|
4
|
+
export interface BlogPresetOptions {
|
|
5
|
+
contentDir?: string;
|
|
6
|
+
statementComponent?: string;
|
|
7
|
+
statementComponentFile?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function blogPreset(options?: BlogPresetOptions): Preset;
|