blodemd 0.0.13 → 0.0.15
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/README.md +1 -1
- package/dev-server/lib/local-runtime.tsx +12 -15
- package/dev-server/package.json +5 -1
- package/dist/cli.mjs +1211 -983
- package/dist/cli.mjs.map +1 -1
- package/docs/app/globals.css +1 -1
- package/docs/components/api/api-playground.tsx +2 -5
- package/docs/components/api/api-reference.tsx +29 -3
- package/docs/components/docs/contextual-menu.tsx +37 -33
- package/docs/components/docs/copy-page-menu.tsx +18 -0
- package/docs/components/docs/doc-header.tsx +4 -1
- package/docs/components/docs/doc-shell.tsx +48 -18
- package/docs/components/docs/doc-sidebar.tsx +131 -89
- package/docs/components/docs/doc-toc.tsx +1 -0
- package/docs/components/docs/mobile-nav.tsx +72 -68
- package/docs/components/docs/sidebar-active-highlight.tsx +34 -0
- package/docs/components/docs/sidebar-scroll-area.tsx +9 -4
- package/docs/components/git/repo-picker.tsx +5 -2
- package/docs/components/mdx/index.tsx +31 -21
- package/docs/components/posthog-provider.tsx +42 -0
- package/docs/components/tenant-analytics.tsx +49 -0
- package/docs/components/third-parties.tsx +4 -1
- package/docs/components/ui/copy-button.tsx +16 -2
- package/docs/components/ui/search-dialog.tsx +431 -0
- package/docs/components/ui/search.tsx +44 -427
- package/docs/components/web-mcp.tsx +115 -0
- package/docs/lib/agent-skills.ts +48 -0
- package/docs/lib/config.ts +4 -5
- package/docs/lib/docs-collection.ts +7 -22
- package/docs/lib/docs-runtime.tsx +160 -10
- package/docs/lib/llms-full.ts +82 -0
- package/docs/lib/marketing-markdown.ts +79 -0
- package/docs/lib/marketing-site.ts +31 -0
- package/docs/lib/mdx.ts +17 -6
- package/docs/lib/routes.ts +19 -3
- package/docs/lib/shiki.ts +4 -0
- package/docs/lib/tenancy.ts +15 -2
- package/docs/lib/tenant-headers.ts +29 -0
- package/docs/lib/tenant-static.ts +73 -99
- package/package.json +8 -5
- package/packages/@repo/common/package.json +1 -1
- package/packages/@repo/contracts/dist/analytics.d.ts +21 -0
- package/packages/@repo/contracts/dist/analytics.d.ts.map +1 -0
- package/packages/@repo/contracts/dist/analytics.js +18 -0
- package/packages/@repo/contracts/dist/deployment.js +1 -1
- package/packages/@repo/contracts/dist/git.js +2 -2
- package/packages/@repo/contracts/dist/ids.d.ts.map +1 -1
- package/packages/@repo/contracts/dist/ids.js +2 -1
- package/packages/@repo/contracts/dist/index.d.ts +1 -0
- package/packages/@repo/contracts/dist/index.d.ts.map +1 -1
- package/packages/@repo/contracts/dist/index.js +1 -0
- package/packages/@repo/contracts/dist/project.d.ts +18 -1
- package/packages/@repo/contracts/dist/project.d.ts.map +1 -1
- package/packages/@repo/contracts/dist/project.js +3 -1
- package/packages/@repo/contracts/dist/tenant.d.ts +36 -0
- package/packages/@repo/contracts/dist/tenant.d.ts.map +1 -1
- package/packages/@repo/contracts/dist/tenant.js +2 -0
- package/packages/@repo/contracts/package.json +1 -1
- package/packages/@repo/contracts/src/analytics.ts +33 -0
- package/packages/@repo/contracts/src/deployment.ts +1 -1
- package/packages/@repo/contracts/src/git.ts +2 -2
- package/packages/@repo/contracts/src/ids.ts +2 -1
- package/packages/@repo/contracts/src/index.ts +1 -0
- package/packages/@repo/contracts/src/project.ts +3 -1
- package/packages/@repo/contracts/src/tenant.ts +2 -0
- package/packages/@repo/models/dist/docs-config.d.ts +0 -198
- package/packages/@repo/models/dist/docs-config.d.ts.map +1 -1
- package/packages/@repo/models/dist/docs-config.js +3 -2
- package/packages/@repo/models/dist/tenant.d.ts +12 -0
- package/packages/@repo/models/dist/tenant.d.ts.map +1 -1
- package/packages/@repo/models/package.json +1 -1
- package/packages/@repo/models/src/docs-config.ts +3 -3
- package/packages/@repo/models/src/tenant.ts +15 -0
- package/packages/@repo/prebuild/dist/openapi.d.ts.map +1 -1
- package/packages/@repo/prebuild/dist/openapi.js +32 -4
- package/packages/@repo/prebuild/package.json +1 -1
- package/packages/@repo/prebuild/src/openapi.ts +42 -4
- package/packages/@repo/previewing/dist/blob-source.d.ts.map +1 -1
- package/packages/@repo/previewing/dist/blob-source.js +18 -5
- package/packages/@repo/previewing/dist/config-loader.d.ts +134 -0
- package/packages/@repo/previewing/dist/config-loader.d.ts.map +1 -0
- package/packages/@repo/previewing/dist/config-loader.js +231 -0
- package/packages/@repo/previewing/dist/constants.d.ts +15 -0
- package/packages/@repo/previewing/dist/constants.d.ts.map +1 -0
- package/packages/@repo/previewing/dist/constants.js +14 -0
- package/packages/@repo/previewing/dist/content-index.d.ts +7 -0
- package/packages/@repo/previewing/dist/content-index.d.ts.map +1 -0
- package/packages/@repo/previewing/dist/content-index.js +291 -0
- package/packages/@repo/previewing/dist/index.d.ts +13 -121
- package/packages/@repo/previewing/dist/index.d.ts.map +1 -1
- package/packages/@repo/previewing/dist/index.js +11 -1003
- package/packages/@repo/previewing/dist/markdown/agent-markdown.d.ts +3 -0
- package/packages/@repo/previewing/dist/markdown/agent-markdown.d.ts.map +1 -0
- package/packages/@repo/previewing/dist/markdown/agent-markdown.js +176 -0
- package/packages/@repo/previewing/dist/markdown/format.d.ts +8 -0
- package/packages/@repo/previewing/dist/markdown/format.d.ts.map +1 -0
- package/packages/@repo/previewing/dist/markdown/format.js +43 -0
- package/packages/@repo/previewing/dist/markdown/links.d.ts +3 -0
- package/packages/@repo/previewing/dist/markdown/links.d.ts.map +1 -0
- package/packages/@repo/previewing/dist/markdown/links.js +31 -0
- package/packages/@repo/previewing/dist/openapi-pages.d.ts +7 -0
- package/packages/@repo/previewing/dist/openapi-pages.d.ts.map +1 -0
- package/packages/@repo/previewing/dist/openapi-pages.js +200 -0
- package/packages/@repo/previewing/dist/search-index.d.ts +4 -0
- package/packages/@repo/previewing/dist/search-index.d.ts.map +1 -0
- package/packages/@repo/previewing/dist/search-index.js +23 -0
- package/packages/@repo/previewing/dist/serialization.d.ts +13 -0
- package/packages/@repo/previewing/dist/serialization.d.ts.map +1 -0
- package/packages/@repo/previewing/dist/serialization.js +108 -0
- package/packages/@repo/previewing/dist/toc-index.d.ts +5 -0
- package/packages/@repo/previewing/dist/toc-index.d.ts.map +1 -0
- package/packages/@repo/previewing/dist/toc-index.js +53 -0
- package/packages/@repo/previewing/dist/types.d.ts +92 -0
- package/packages/@repo/previewing/dist/types.d.ts.map +1 -0
- package/packages/@repo/previewing/dist/types.js +1 -0
- package/packages/@repo/previewing/dist/utility-index.d.ts +7 -0
- package/packages/@repo/previewing/dist/utility-index.d.ts.map +1 -0
- package/packages/@repo/previewing/dist/utility-index.js +201 -0
- package/packages/@repo/previewing/package.json +1 -1
- package/packages/@repo/previewing/src/blob-source.ts +20 -5
- package/packages/@repo/previewing/src/config-loader.ts +316 -0
- package/packages/@repo/previewing/src/constants.ts +16 -0
- package/packages/@repo/previewing/src/content-index.ts +384 -0
- package/packages/@repo/previewing/src/index.ts +69 -1515
- package/packages/@repo/previewing/src/markdown/agent-markdown.ts +254 -0
- package/packages/@repo/previewing/src/markdown/format.ts +63 -0
- package/packages/@repo/previewing/src/markdown/links.ts +46 -0
- package/packages/@repo/previewing/src/openapi-pages.ts +319 -0
- package/packages/@repo/previewing/src/search-index.ts +38 -0
- package/packages/@repo/previewing/src/serialization.ts +191 -0
- package/packages/@repo/previewing/src/toc-index.ts +72 -0
- package/packages/@repo/previewing/src/types.ts +105 -0
- package/packages/@repo/previewing/src/utility-index.ts +304 -0
- package/packages/@repo/validation/package.json +1 -1
- package/scripts/repo-packages.mjs +8 -0
- package/docs/components/ui/site-footer.tsx +0 -41
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-markdown.d.ts","sourceRoot":"","sources":["../../src/markdown/agent-markdown.ts"],"names":[],"mappings":"AA4OA,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,MAMhD,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,UAAU,MAAM,WAMf,CAAC"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { NEWLINE_REGEX } from "../constants.js";
|
|
2
|
+
import { absolutiseInternalLinks, sanitizePlaceholderUrls } from "./links.js";
|
|
3
|
+
const FENCED_CODE_BLOCK_REGEX = /(^|\n)(`{3,}|~{3,})[^\n]*\n[\s\S]*?\n\2(?=\n|$)/g;
|
|
4
|
+
const TYPE_TABLE_REGEX = /<TypeTable\s+type=\{\{([\s\S]*?)\}\}\s*\/>/g;
|
|
5
|
+
const TYPE_TABLE_ROW_HEADER_REGEX = /^\s*(["']?[\w$./<>|{}\-\s]+["']?)\s*:\s*\{\s*$/;
|
|
6
|
+
const STRING_FIELD_REGEX = (field) => new RegExp(`${field}:\\s*(?:"([^"]*)"|'([^']*)'|\`([^\`]*)\`)`, "s");
|
|
7
|
+
const BOOLEAN_FIELD_REGEX = (field) => new RegExp(`${field}:\\s*(true|false)`, "s");
|
|
8
|
+
const getStringProp = (attributes, name) => {
|
|
9
|
+
const match = new RegExp(`${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|\\{\\s*"([^"]*)"\\s*\\}|\\{\\s*'([^']*)'\\s*\\})`).exec(attributes);
|
|
10
|
+
return match?.slice(1).find((value) => typeof value === "string");
|
|
11
|
+
};
|
|
12
|
+
const protectFencedCodeBlocks = (source) => {
|
|
13
|
+
const blocks = [];
|
|
14
|
+
const text = source.replace(FENCED_CODE_BLOCK_REGEX, (match) => {
|
|
15
|
+
const placeholder = `\n@@BLODEMD_CODE_BLOCK_${blocks.length}@@\n`;
|
|
16
|
+
blocks.push(match.trim());
|
|
17
|
+
return placeholder;
|
|
18
|
+
});
|
|
19
|
+
return { blocks, text };
|
|
20
|
+
};
|
|
21
|
+
const restoreFencedCodeBlocks = (source, blocks) => {
|
|
22
|
+
let restored = source;
|
|
23
|
+
for (const [index, block] of blocks.entries()) {
|
|
24
|
+
// Function replacer: code may contain `$&`, `$1`, `` $` `` etc. which a
|
|
25
|
+
// string replacement would interpret as substitution patterns.
|
|
26
|
+
restored = restored.replace(`@@BLODEMD_CODE_BLOCK_${index}@@`, () => block);
|
|
27
|
+
}
|
|
28
|
+
return restored;
|
|
29
|
+
};
|
|
30
|
+
const INLINE_CODE_REGEX = /(?<![\\`])`([^`\n]+)`(?!`)/g;
|
|
31
|
+
const protectInlineCode = (source) => {
|
|
32
|
+
const spans = [];
|
|
33
|
+
const text = source.replace(INLINE_CODE_REGEX, (match) => {
|
|
34
|
+
const placeholder = `@@BLODEMD_INLINE_CODE_${spans.length}@@`;
|
|
35
|
+
spans.push(match);
|
|
36
|
+
return placeholder;
|
|
37
|
+
});
|
|
38
|
+
return { spans, text };
|
|
39
|
+
};
|
|
40
|
+
const restoreInlineCode = (source, spans) => {
|
|
41
|
+
let restored = source;
|
|
42
|
+
for (const [index, span] of spans.entries()) {
|
|
43
|
+
restored = restored.replace(`@@BLODEMD_INLINE_CODE_${index}@@`, () => span);
|
|
44
|
+
}
|
|
45
|
+
return restored;
|
|
46
|
+
};
|
|
47
|
+
const compactMarkdown = (source) => source
|
|
48
|
+
.replaceAll(/[ \t]+\n/g, "\n")
|
|
49
|
+
.replaceAll(/\n{3,}/g, "\n\n")
|
|
50
|
+
.trim();
|
|
51
|
+
const getFieldStringValue = (block, field) => {
|
|
52
|
+
const match = STRING_FIELD_REGEX(field).exec(block);
|
|
53
|
+
return match?.slice(1).find((value) => typeof value === "string");
|
|
54
|
+
};
|
|
55
|
+
const getFieldBooleanValue = (block, field) => {
|
|
56
|
+
const match = BOOLEAN_FIELD_REGEX(field).exec(block);
|
|
57
|
+
return match?.[1];
|
|
58
|
+
};
|
|
59
|
+
const renderTypeTable = (_match, body) => {
|
|
60
|
+
const rows = [];
|
|
61
|
+
const lines = body.split(NEWLINE_REGEX);
|
|
62
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
63
|
+
const header = TYPE_TABLE_ROW_HEADER_REGEX.exec(lines[index] ?? "");
|
|
64
|
+
if (!header) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const name = (header[1] ?? "").replaceAll(/^["']|["']$/g, "").trim();
|
|
68
|
+
const blockLines = [];
|
|
69
|
+
index += 1;
|
|
70
|
+
while (index < lines.length) {
|
|
71
|
+
const line = lines[index] ?? "";
|
|
72
|
+
if (/^\s*\},?\s*$/.test(line)) {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
blockLines.push(line);
|
|
76
|
+
index += 1;
|
|
77
|
+
}
|
|
78
|
+
const block = blockLines.join("\n");
|
|
79
|
+
const type = getFieldStringValue(block, "type") ?? "";
|
|
80
|
+
const description = getFieldStringValue(block, "description") ?? "";
|
|
81
|
+
const required = getFieldBooleanValue(block, "required") ?? "";
|
|
82
|
+
const defaultValue = getFieldStringValue(block, "default") ?? "";
|
|
83
|
+
const meta = [
|
|
84
|
+
type ? `type: ${type}` : null,
|
|
85
|
+
required ? `required: ${required}` : null,
|
|
86
|
+
defaultValue ? `default: ${defaultValue}` : null,
|
|
87
|
+
]
|
|
88
|
+
.filter(Boolean)
|
|
89
|
+
.join(", ");
|
|
90
|
+
rows.push(`- \`${name}\`${meta ? ` (${meta})` : ""}: ${description}`);
|
|
91
|
+
}
|
|
92
|
+
return rows.length ? rows.join("\n") : "";
|
|
93
|
+
};
|
|
94
|
+
const transformMdxComponents = (source) => {
|
|
95
|
+
let output = source;
|
|
96
|
+
output = output.replaceAll(TYPE_TABLE_REGEX, renderTypeTable);
|
|
97
|
+
output = output.replaceAll(/<Installer\s+([^>]*)\/>/g, (_match, attributes) => {
|
|
98
|
+
const command = getStringProp(attributes, "command");
|
|
99
|
+
return command ? `\`\`\`bash\n${command}\n\`\`\`` : "";
|
|
100
|
+
});
|
|
101
|
+
output = output.replaceAll(/<Tree\.Folder\s+([^>]*)>/g, (_match, attributes) => {
|
|
102
|
+
const name = getStringProp(attributes, "name") ?? "folder";
|
|
103
|
+
return `- ${name}/`;
|
|
104
|
+
});
|
|
105
|
+
output = output.replaceAll(/<Tree\.File\s+([^>]*)\/>/g, (_match, attributes) => {
|
|
106
|
+
const name = getStringProp(attributes, "name") ?? "file";
|
|
107
|
+
return `- ${name}`;
|
|
108
|
+
});
|
|
109
|
+
output = output.replaceAll("</Tree.Folder>", "");
|
|
110
|
+
output = output.replaceAll(/<\/?Tree[^>]*>/g, "");
|
|
111
|
+
output = output.replaceAll(/<Frame(?=[\s>])\s*([^>]*)>([\s\S]*?)<\/Frame>/g, (_match, attributes, children) => {
|
|
112
|
+
const caption = getStringProp(attributes, "caption");
|
|
113
|
+
const hint = getStringProp(attributes, "hint");
|
|
114
|
+
return compactMarkdown([hint, children.trim(), caption ? `Caption: ${caption}` : null]
|
|
115
|
+
.filter(Boolean)
|
|
116
|
+
.join("\n\n"));
|
|
117
|
+
});
|
|
118
|
+
output = output.replaceAll(/<Callout(?=[\s>])\s*([^>]*)>([\s\S]*?)<\/Callout>/g, (_match, attributes, children) => {
|
|
119
|
+
const type = (getStringProp(attributes, "type") ?? "note").toUpperCase();
|
|
120
|
+
return `> [!${type}]\n${children
|
|
121
|
+
.trim()
|
|
122
|
+
.split(NEWLINE_REGEX)
|
|
123
|
+
.map((line) => `> ${line}`)
|
|
124
|
+
.join("\n")}`;
|
|
125
|
+
});
|
|
126
|
+
for (const [tag, type] of [
|
|
127
|
+
["Note", "NOTE"],
|
|
128
|
+
["Warning", "WARNING"],
|
|
129
|
+
["Info", "INFO"],
|
|
130
|
+
["Tip", "TIP"],
|
|
131
|
+
["Check", "CHECK"],
|
|
132
|
+
["Danger", "DANGER"],
|
|
133
|
+
]) {
|
|
134
|
+
output = output.replaceAll(new RegExp(`<${tag}(?=[\\s>])\\s*[^>]*>([\\s\\S]*?)</${tag}>`, "g"), (_match, children) => `> [!${type}]\n${children
|
|
135
|
+
.trim()
|
|
136
|
+
.split(NEWLINE_REGEX)
|
|
137
|
+
.map((line) => `> ${line}`)
|
|
138
|
+
.join("\n")}`);
|
|
139
|
+
}
|
|
140
|
+
output = output.replaceAll(/<Accordion(?=[\s>])\s*([^>]*)>([\s\S]*?)<\/Accordion>/g, (_match, attributes, children) => {
|
|
141
|
+
const title = getStringProp(attributes, "title") ?? "Details";
|
|
142
|
+
return `### ${title}\n\n${children.trim()}`;
|
|
143
|
+
});
|
|
144
|
+
output = output.replaceAll(/<Tab\s+([^>]*)>([\s\S]*?)<\/Tab>/g, (_match, attributes, children) => {
|
|
145
|
+
const title = getStringProp(attributes, "title") ??
|
|
146
|
+
getStringProp(attributes, "label") ??
|
|
147
|
+
"Tab";
|
|
148
|
+
return `### ${title}\n\n${children.trim()}`;
|
|
149
|
+
});
|
|
150
|
+
output = output.replaceAll(/<Step\s+([^>]*)>([\s\S]*?)<\/Step>/g, (_match, attributes, children) => {
|
|
151
|
+
const title = getStringProp(attributes, "title") ?? "Step";
|
|
152
|
+
return `1. **${title}**\n\n${children.trim()}`;
|
|
153
|
+
});
|
|
154
|
+
output = output.replaceAll(/<Expandable(?=[\s>])\s*([^>]*)>([\s\S]*?)<\/Expandable>/g, (_match, attributes, children) => {
|
|
155
|
+
const title = getStringProp(attributes, "title") ?? "Details";
|
|
156
|
+
return `### ${title}\n\n${children.trim()}`;
|
|
157
|
+
});
|
|
158
|
+
output = output.replaceAll(/<Card(?=[\s>])\s*([^>]*)>([\s\S]*?)<\/Card>/g, (_match, attributes, children) => {
|
|
159
|
+
const title = getStringProp(attributes, "title");
|
|
160
|
+
const href = getStringProp(attributes, "href");
|
|
161
|
+
const heading = title
|
|
162
|
+
? `### ${href ? `[${title}](${href})` : title}`
|
|
163
|
+
: "";
|
|
164
|
+
return compactMarkdown([heading, children.trim()].filter(Boolean).join("\n\n"));
|
|
165
|
+
});
|
|
166
|
+
output = output.replaceAll(/<\/?(?:Columns|Column|CodeGroup|Tabs|Steps|AccordionGroup|CardGroup)[^>]*>/g, "");
|
|
167
|
+
return compactMarkdown(output);
|
|
168
|
+
};
|
|
169
|
+
export const toAgentMarkdown = (source) => {
|
|
170
|
+
const { blocks, text: codeProtected } = protectFencedCodeBlocks(source);
|
|
171
|
+
const { spans, text: inlineProtected } = protectInlineCode(codeProtected);
|
|
172
|
+
const transformed = transformMdxComponents(inlineProtected);
|
|
173
|
+
const inlineRestored = restoreInlineCode(transformed, spans);
|
|
174
|
+
return compactMarkdown(restoreFencedCodeBlocks(inlineRestored, blocks));
|
|
175
|
+
};
|
|
176
|
+
export const prepareLlmsFullContent = (source, origin, basePath) => absolutiseInternalLinks(sanitizePlaceholderUrls(toAgentMarkdown(source)), origin, basePath);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const parseFrontmatter: (source: string) => {
|
|
2
|
+
body: string;
|
|
3
|
+
frontmatter: any;
|
|
4
|
+
};
|
|
5
|
+
export declare const stripFrontmatter: (source: string) => string;
|
|
6
|
+
export declare const formatMarkdownPage: (title: string, source: string, description?: string) => string;
|
|
7
|
+
export declare const formatMarkdownPageSection: (title: string, url: string, source: string, description?: string) => string;
|
|
8
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/markdown/format.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM;;;CAS9C,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,WACT,CAAC;AAiBvC,eAAO,MAAM,kBAAkB,GAC7B,OAAO,MAAM,EACb,QAAQ,MAAM,EACd,cAAc,MAAM,WASrB,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,OAAO,MAAM,EACb,KAAK,MAAM,EACX,QAAQ,MAAM,EACd,cAAc,MAAM,WASrB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { slugify } from "@repo/common";
|
|
2
|
+
import YAML from "yaml";
|
|
3
|
+
const FRONTMATTER_REGEX = /^---\s*\n([\s\S]*?)\n---\s*\n?/;
|
|
4
|
+
const LEADING_H1_REGEX = /^#\s+([^\r\n]+)(?:\r?\n(?:\r?\n)?)?/;
|
|
5
|
+
export const parseFrontmatter = (source) => {
|
|
6
|
+
const match = FRONTMATTER_REGEX.exec(source);
|
|
7
|
+
if (!match) {
|
|
8
|
+
return { body: source, frontmatter: {} };
|
|
9
|
+
}
|
|
10
|
+
const raw = match[1] ?? "";
|
|
11
|
+
const data = YAML.parse(raw) ?? {};
|
|
12
|
+
const body = source.slice(match[0].length);
|
|
13
|
+
return { body, frontmatter: data };
|
|
14
|
+
};
|
|
15
|
+
export const stripFrontmatter = (source) => parseFrontmatter(source).body.trim();
|
|
16
|
+
const stripMatchingLeadingH1 = (source, title) => {
|
|
17
|
+
const trimmed = source.trimStart();
|
|
18
|
+
const match = LEADING_H1_REGEX.exec(trimmed);
|
|
19
|
+
if (!match) {
|
|
20
|
+
return trimmed.trim();
|
|
21
|
+
}
|
|
22
|
+
const [headingLine = "", headingTitle = ""] = match;
|
|
23
|
+
if (slugify(headingTitle) !== slugify(title)) {
|
|
24
|
+
return trimmed.trim();
|
|
25
|
+
}
|
|
26
|
+
return trimmed.slice(headingLine.length).trim();
|
|
27
|
+
};
|
|
28
|
+
export const formatMarkdownPage = (title, source, description) => {
|
|
29
|
+
const content = stripMatchingLeadingH1(source, title);
|
|
30
|
+
const descriptionBlock = description ? `\n\n${description}` : "";
|
|
31
|
+
if (!content) {
|
|
32
|
+
return `# ${title}${descriptionBlock}`;
|
|
33
|
+
}
|
|
34
|
+
return `# ${title}${descriptionBlock}\n\n${content}`;
|
|
35
|
+
};
|
|
36
|
+
export const formatMarkdownPageSection = (title, url, source, description) => {
|
|
37
|
+
const content = stripMatchingLeadingH1(source, title);
|
|
38
|
+
const descriptionBlock = description ? `\n\n${description}` : "";
|
|
39
|
+
if (!content) {
|
|
40
|
+
return `# ${title} (${url})${descriptionBlock}`;
|
|
41
|
+
}
|
|
42
|
+
return `# ${title} (${url})${descriptionBlock}\n\n${content}`;
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../src/markdown/links.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,uBAAuB,GAAI,MAAM,MAAM,KAAG,MAGe,CAAC;AAEvE,eAAO,MAAM,uBAAuB,GAClC,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,UAAU,MAAM,KACf,MAiBF,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const PLACEHOLDER_URL_PATTERN = [
|
|
2
|
+
"https?://(?:[a-z0-9-]+\\.)*example\\.(?:com|org|net)\\b[^\\s)\\]\"'<>]*",
|
|
3
|
+
"https?://discord\\.gg/example\\b[^\\s)\\]\"'<>]*",
|
|
4
|
+
"https?://(?:[a-z0-9-]+\\.)+(?:test|invalid)(?:[/?#:][^\\s)\\]\"'<>]*)?",
|
|
5
|
+
"https?://localhost(?::\\d+)?[^\\s)\\]\"'<>]*",
|
|
6
|
+
"https?://(?:[a-z0-9-]+\\.)*your[-_]?domain\\.[a-z]+\\b[^\\s)\\]\"'<>]*",
|
|
7
|
+
"https?://acme\\.blode\\.md\\b[^\\s)\\]\"'<>]*",
|
|
8
|
+
"https?://github\\.com/example/[^\\s)\\]\"'<>]*",
|
|
9
|
+
"https?://(?:us|eu)\\.i\\.posthog\\.com\\b[^\\s)\\]\"'<>]*",
|
|
10
|
+
].join("|");
|
|
11
|
+
const PLACEHOLDER_URL_RE = new RegExp(PLACEHOLDER_URL_PATTERN, "gi");
|
|
12
|
+
const PLACEHOLDER_MARKDOWN_LINK_RE = new RegExp(`\\[([^\\]]+)\\]\\((?:${PLACEHOLDER_URL_PATTERN})\\)`, "gi");
|
|
13
|
+
const INTERNAL_MARKDOWN_LINK_RE = /(!?\[[^\]]+\])\((\/[^)\s]*)\)/g;
|
|
14
|
+
const defangUrl = (value) => value.replace(/^https?:\/\//i, "");
|
|
15
|
+
export const sanitizePlaceholderUrls = (text) => text
|
|
16
|
+
.replace(PLACEHOLDER_MARKDOWN_LINK_RE, "$1")
|
|
17
|
+
.replace(PLACEHOLDER_URL_RE, (match) => `\`${defangUrl(match)}\``);
|
|
18
|
+
export const absolutiseInternalLinks = (source, origin, basePath) => {
|
|
19
|
+
const normalizedBase = basePath
|
|
20
|
+
? `/${basePath}`.replaceAll(/\/+/g, "/").replace(/\/$/, "")
|
|
21
|
+
: "";
|
|
22
|
+
return source.replaceAll(INTERNAL_MARKDOWN_LINK_RE, (_match, label, linkPath) => {
|
|
23
|
+
const alreadyPrefixed = normalizedBase &&
|
|
24
|
+
(linkPath === normalizedBase ||
|
|
25
|
+
linkPath.startsWith(`${normalizedBase}/`));
|
|
26
|
+
const absolutePath = alreadyPrefixed
|
|
27
|
+
? linkPath
|
|
28
|
+
: `${normalizedBase}${linkPath}`.replaceAll(/\/+/g, "/");
|
|
29
|
+
return `${label}(${origin}${absolutePath})`;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CollectionConfig, SiteConfig } from "@repo/models";
|
|
2
|
+
import type { OpenApiOperation } from "@repo/prebuild";
|
|
3
|
+
import type { ContentSource } from "./content-source.js";
|
|
4
|
+
import type { UtilityPage } from "./types.js";
|
|
5
|
+
export declare const formatOpenApiPageContent: (operation: OpenApiOperation) => string;
|
|
6
|
+
export declare const buildUtilityOpenApiPages: (config: SiteConfig, collection: CollectionConfig | undefined, source: ContentSource) => Promise<UtilityPage[]>;
|
|
7
|
+
//# sourceMappingURL=openapi-pages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-pages.d.ts","sourceRoot":"","sources":["../src/openapi-pages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAEhB,UAAU,EACX,MAAM,cAAc,CAAC;AAOtB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAwH9C,eAAO,MAAM,wBAAwB,GACnC,WAAW,gBAAgB,KAC1B,MA0BF,CAAC;AA6EF,eAAO,MAAM,wBAAwB,GACnC,QAAQ,UAAU,EAClB,YAAY,gBAAgB,GAAG,SAAS,EACxC,QAAQ,aAAa,2BA0EtB,CAAC"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { ensureArray, normalizePath } from "@repo/common";
|
|
2
|
+
import { extractOpenApiOperations, openApiIdentifier, openApiSlug, parseOpenApiSpec, } from "@repo/prebuild";
|
|
3
|
+
import { getDocsNavigation } from "./config-loader.js";
|
|
4
|
+
const getOpenApiSourceKey = (source) => `${source.source}::${source.directory ?? ""}::${(source.include ?? []).join("|")}`;
|
|
5
|
+
const toOpenApiSourceObject = (value) => {
|
|
6
|
+
if (typeof value === "string") {
|
|
7
|
+
return { source: value };
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
const collectOpenApiSources = (collection) => {
|
|
12
|
+
const sources = [];
|
|
13
|
+
for (const item of ensureArray(collection?.openapi)) {
|
|
14
|
+
if (!item) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
sources.push(toOpenApiSourceObject(item));
|
|
18
|
+
}
|
|
19
|
+
const groups = collection?.navigation?.groups ?? [];
|
|
20
|
+
for (const group of groups) {
|
|
21
|
+
if (!group.openapi) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
sources.push(toOpenApiSourceObject(group.openapi));
|
|
25
|
+
}
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
return sources.filter((source) => {
|
|
28
|
+
const key = getOpenApiSourceKey(source);
|
|
29
|
+
if (seen.has(key)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
seen.add(key);
|
|
33
|
+
return true;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const getSchemaTypeLabel = (schema) => {
|
|
37
|
+
if (!schema || typeof schema !== "object") {
|
|
38
|
+
return "any";
|
|
39
|
+
}
|
|
40
|
+
const record = schema;
|
|
41
|
+
if (typeof record.$ref === "string") {
|
|
42
|
+
const last = record.$ref.split("/").pop();
|
|
43
|
+
return last ?? "object";
|
|
44
|
+
}
|
|
45
|
+
if (typeof record.type === "string") {
|
|
46
|
+
if (record.type === "array" && record.items) {
|
|
47
|
+
return `${getSchemaTypeLabel(record.items)}[]`;
|
|
48
|
+
}
|
|
49
|
+
return record.type;
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(record.oneOf) || Array.isArray(record.anyOf)) {
|
|
52
|
+
const variants = (record.oneOf ?? record.anyOf);
|
|
53
|
+
return variants.map(getSchemaTypeLabel).join(" | ");
|
|
54
|
+
}
|
|
55
|
+
return "object";
|
|
56
|
+
};
|
|
57
|
+
const formatParameterLine = (parameter) => {
|
|
58
|
+
const name = String(parameter.name ?? "");
|
|
59
|
+
const location = parameter.in ? ` (${parameter.in})` : "";
|
|
60
|
+
const required = parameter.required ? "required" : "optional";
|
|
61
|
+
const type = getSchemaTypeLabel(parameter.schema);
|
|
62
|
+
const description = typeof parameter.description === "string" && parameter.description
|
|
63
|
+
? ` - ${parameter.description.split("\n")[0]}`
|
|
64
|
+
: "";
|
|
65
|
+
return `- \`${name}\`${location}: ${type}, ${required}${description}`;
|
|
66
|
+
};
|
|
67
|
+
const formatRequestBody = (body) => {
|
|
68
|
+
const required = body.required ? "required" : "optional";
|
|
69
|
+
const content = body.content ?? {};
|
|
70
|
+
const mediaTypes = Object.keys(content);
|
|
71
|
+
if (mediaTypes.length === 0) {
|
|
72
|
+
return `${required} body`;
|
|
73
|
+
}
|
|
74
|
+
return mediaTypes
|
|
75
|
+
.map((mediaType) => {
|
|
76
|
+
const mediaEntry = content[mediaType];
|
|
77
|
+
const schemaLabel = getSchemaTypeLabel(mediaEntry?.schema);
|
|
78
|
+
return `- ${mediaType} (${required}): ${schemaLabel}`;
|
|
79
|
+
})
|
|
80
|
+
.join("\n");
|
|
81
|
+
};
|
|
82
|
+
const formatResponses = (responses) => Object.entries(responses)
|
|
83
|
+
.map(([status, value]) => {
|
|
84
|
+
const response = value ?? {};
|
|
85
|
+
const description = typeof response.description === "string" && response.description
|
|
86
|
+
? response.description.split("\n")[0]
|
|
87
|
+
: "";
|
|
88
|
+
const content = response.content ?? {};
|
|
89
|
+
const mediaTypes = Object.keys(content);
|
|
90
|
+
const mediaSuffix = mediaTypes.length
|
|
91
|
+
? ` [${mediaTypes.join(", ")}]`
|
|
92
|
+
: "";
|
|
93
|
+
return `- ${status}${mediaSuffix}${description ? ` - ${description}` : ""}`;
|
|
94
|
+
})
|
|
95
|
+
.join("\n");
|
|
96
|
+
export const formatOpenApiPageContent = (operation) => {
|
|
97
|
+
const parts = [`Method: ${operation.method}`, `Path: ${operation.path}`];
|
|
98
|
+
if (operation.description) {
|
|
99
|
+
parts.push(operation.description);
|
|
100
|
+
}
|
|
101
|
+
if (operation.tags.length) {
|
|
102
|
+
parts.push(`Tags: ${operation.tags.join(", ")}`);
|
|
103
|
+
}
|
|
104
|
+
if (operation.parameters.length) {
|
|
105
|
+
parts.push(`## Parameters\n\n${operation.parameters
|
|
106
|
+
.map(formatParameterLine)
|
|
107
|
+
.join("\n")}`);
|
|
108
|
+
}
|
|
109
|
+
if (operation.requestBody) {
|
|
110
|
+
parts.push(`## Request body\n\n${formatRequestBody(operation.requestBody)}`);
|
|
111
|
+
}
|
|
112
|
+
if (operation.responses) {
|
|
113
|
+
parts.push(`## Responses\n\n${formatResponses(operation.responses)}`);
|
|
114
|
+
}
|
|
115
|
+
return parts.join("\n\n");
|
|
116
|
+
};
|
|
117
|
+
const getGroupedOpenApiSourceKey = (source) => getOpenApiSourceKey(toOpenApiSourceObject(source));
|
|
118
|
+
const collectUtilityOpenApiPages = (pagesByIdentifier, pagesBySource, operations, directory, openApiSource, slugPrefix) => {
|
|
119
|
+
const sourceKey = getOpenApiSourceKey(openApiSource);
|
|
120
|
+
const includeIdentifiers = openApiSource.include?.length
|
|
121
|
+
? new Set(openApiSource.include)
|
|
122
|
+
: null;
|
|
123
|
+
for (const operation of operations) {
|
|
124
|
+
const identifier = openApiIdentifier(operation.method, operation.path);
|
|
125
|
+
if (includeIdentifiers && !includeIdentifiers.has(identifier)) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const baseSlug = normalizePath(openApiSlug(operation.method, operation.path, directory));
|
|
129
|
+
const slug = slugPrefix
|
|
130
|
+
? normalizePath(`${slugPrefix}/${baseSlug}`)
|
|
131
|
+
: baseSlug;
|
|
132
|
+
const page = {
|
|
133
|
+
content: formatOpenApiPageContent(operation),
|
|
134
|
+
description: operation.description,
|
|
135
|
+
identifier,
|
|
136
|
+
slug,
|
|
137
|
+
sourceKey,
|
|
138
|
+
title: operation.summary ?? identifier,
|
|
139
|
+
};
|
|
140
|
+
pagesByIdentifier.set(identifier, page);
|
|
141
|
+
if (!pagesBySource.has(sourceKey)) {
|
|
142
|
+
pagesBySource.set(sourceKey, []);
|
|
143
|
+
}
|
|
144
|
+
pagesBySource.get(sourceKey)?.push(page);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const addUtilityPagesFromSourceKey = (pages, pagesBySource, sourceKey) => {
|
|
148
|
+
for (const page of pagesBySource.get(sourceKey) ?? []) {
|
|
149
|
+
pages.set(page.slug, page);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const addReferencedUtilityPages = (pages, pagesByIdentifier, pageReferences, hiddenPages, groupHidden = false) => {
|
|
153
|
+
for (const pageReference of pageReferences ?? []) {
|
|
154
|
+
if (groupHidden || hiddenPages.has(pageReference)) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const page = pagesByIdentifier.get(pageReference);
|
|
158
|
+
if (page) {
|
|
159
|
+
pages.set(page.slug, page);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
export const buildUtilityOpenApiPages = async (config, collection, source) => {
|
|
164
|
+
if (!collection || collection.type !== "docs") {
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
const docsNavigation = getDocsNavigation(config);
|
|
168
|
+
const hiddenPages = new Set(docsNavigation?.hidden);
|
|
169
|
+
const slugPrefix = normalizePath(collection.slugPrefix ?? "");
|
|
170
|
+
const byIdentifier = new Map();
|
|
171
|
+
const bySource = new Map();
|
|
172
|
+
const pages = new Map();
|
|
173
|
+
const sources = collectOpenApiSources(collection);
|
|
174
|
+
const resolved = await Promise.all(sources.map(async (item) => {
|
|
175
|
+
const rawSpec = await source.readFile(item.source);
|
|
176
|
+
const spec = parseOpenApiSpec(rawSpec, item.source);
|
|
177
|
+
const directory = item.directory ?? "api";
|
|
178
|
+
const { operations } = extractOpenApiOperations(spec, directory);
|
|
179
|
+
return { directory, operations, source: item };
|
|
180
|
+
}));
|
|
181
|
+
for (const { directory, operations, source: openApiSource } of resolved) {
|
|
182
|
+
collectUtilityOpenApiPages(byIdentifier, bySource, operations, directory, openApiSource, slugPrefix);
|
|
183
|
+
}
|
|
184
|
+
for (const openApiSource of ensureArray(collection.openapi)) {
|
|
185
|
+
if (!openApiSource) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
addUtilityPagesFromSourceKey(pages, bySource, getGroupedOpenApiSourceKey(openApiSource));
|
|
189
|
+
}
|
|
190
|
+
for (const group of docsNavigation?.groups ?? []) {
|
|
191
|
+
const groupHidden = group.hidden === true;
|
|
192
|
+
addReferencedUtilityPages(pages, byIdentifier, group.pages, hiddenPages, groupHidden);
|
|
193
|
+
if (groupHidden || !group.openapi) {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
addUtilityPagesFromSourceKey(pages, bySource, getGroupedOpenApiSourceKey(group.openapi));
|
|
197
|
+
}
|
|
198
|
+
addReferencedUtilityPages(pages, byIdentifier, docsNavigation?.pages, hiddenPages);
|
|
199
|
+
return [...pages.values()];
|
|
200
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SiteConfig } from "@repo/models";
|
|
2
|
+
import type { ContentIndex, SearchIndexItem, UtilityIndex } from "./types.js";
|
|
3
|
+
export declare const buildSearchIndex: (index: ContentIndex, config: SiteConfig, utilityIndex?: UtilityIndex) => SearchIndexItem[];
|
|
4
|
+
//# sourceMappingURL=search-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-index.d.ts","sourceRoot":"","sources":["../src/search-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAM/C,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9E,eAAO,MAAM,gBAAgB,GAC3B,OAAO,YAAY,EACnB,QAAQ,UAAU,EAClB,eAAe,YAAY,KAC1B,eAAe,EAyBjB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { buildPageMetadataMap, shouldIncludeSearchEntry, } from "./content-index.js";
|
|
2
|
+
export const buildSearchIndex = (index, config, utilityIndex) => {
|
|
3
|
+
const pageMetadataMap = buildPageMetadataMap(index);
|
|
4
|
+
const items = new Map();
|
|
5
|
+
for (const page of utilityIndex?.pages ?? []) {
|
|
6
|
+
items.set(page.slug, {
|
|
7
|
+
path: page.slug,
|
|
8
|
+
title: page.title,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
for (const entry of index.entries) {
|
|
12
|
+
if (!shouldIncludeSearchEntry(entry, pageMetadataMap, config)) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const pageMeta = pageMetadataMap.get(entry.slug);
|
|
16
|
+
items.set(entry.slug, {
|
|
17
|
+
href: pageMeta?.url,
|
|
18
|
+
path: entry.slug,
|
|
19
|
+
title: pageMeta?.sidebarTitle ?? entry.title,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return [...items.values()];
|
|
23
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ContentSource } from "./content-source.js";
|
|
2
|
+
import type { ContentIndex, PrebuiltOpenApiEntry, SearchIndexItem, TocItem, UtilityIndex } from "./types.js";
|
|
3
|
+
export declare const serializeContentIndex: (index: ContentIndex) => string;
|
|
4
|
+
export declare const serializeOpenApiIndex: (entries: PrebuiltOpenApiEntry[]) => string;
|
|
5
|
+
export declare const loadPrebuiltContentIndex: (source: ContentSource) => Promise<ContentIndex | null>;
|
|
6
|
+
export declare const loadPrebuiltOpenApiIndex: (source: ContentSource) => Promise<PrebuiltOpenApiEntry[] | null>;
|
|
7
|
+
export declare const serializeSearchIndex: (items: SearchIndexItem[]) => string;
|
|
8
|
+
export declare const loadPrebuiltSearchIndex: (source: ContentSource) => Promise<SearchIndexItem[] | null>;
|
|
9
|
+
export declare const serializeTocIndex: (itemsBySlug: Map<string, TocItem[]>) => string;
|
|
10
|
+
export declare const loadPrebuiltTocIndex: (source: ContentSource) => Promise<Map<string, TocItem[]> | null>;
|
|
11
|
+
export declare const serializeUtilityIndex: (index: UtilityIndex) => string;
|
|
12
|
+
export declare const loadPrebuiltUtilityIndex: (source: ContentSource) => Promise<UtilityIndex | null>;
|
|
13
|
+
//# sourceMappingURL=serialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAEV,YAAY,EACZ,oBAAoB,EACpB,eAAe,EACf,OAAO,EACP,YAAY,EAGb,MAAM,YAAY,CAAC;AAgCpB,eAAO,MAAM,qBAAqB,GAAI,OAAO,YAAY,KAAG,MAKvB,CAAC;AAEtC,eAAO,MAAM,qBAAqB,GAChC,SAAS,oBAAoB,EAAE,KAC9B,MAIkC,CAAC;AAEtC,eAAO,MAAM,wBAAwB,GACnC,QAAQ,aAAa,KACpB,OAAO,CAAC,YAAY,GAAG,IAAI,CA8B7B,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,QAAQ,aAAa,KACpB,OAAO,CAAC,oBAAoB,EAAE,GAAG,IAAI,CAYvC,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,OAAO,eAAe,EAAE,KAAG,MAI5B,CAAC;AAErC,eAAO,MAAM,uBAAuB,GAClC,QAAQ,aAAa,KACpB,OAAO,CAAC,eAAe,EAAE,GAAG,IAAI,CAYlC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,aAAa,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,KAClC,MAI8B,CAAC;AAElC,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,aAAa,KACpB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAYvC,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,OAAO,YAAY,KAAG,MAIvB,CAAC;AAEtC,eAAO,MAAM,wBAAwB,GACnC,QAAQ,aAAa,KACpB,OAAO,CAAC,YAAY,GAAG,IAAI,CAsB7B,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { PREBUILT_INDEX_PATH, PREBUILT_OPENAPI_INDEX_PATH, PREBUILT_SEARCH_INDEX_PATH, PREBUILT_TOC_INDEX_PATH, PREBUILT_UTILITY_INDEX_PATH, } from "./constants.js";
|
|
2
|
+
export const serializeContentIndex = (index) => JSON.stringify({
|
|
3
|
+
collections: Object.fromEntries(index.byCollection),
|
|
4
|
+
entries: index.entries,
|
|
5
|
+
version: 1,
|
|
6
|
+
});
|
|
7
|
+
export const serializeOpenApiIndex = (entries) => JSON.stringify({
|
|
8
|
+
entries,
|
|
9
|
+
version: 1,
|
|
10
|
+
});
|
|
11
|
+
export const loadPrebuiltContentIndex = async (source) => {
|
|
12
|
+
try {
|
|
13
|
+
const raw = await source.readFile(PREBUILT_INDEX_PATH);
|
|
14
|
+
const data = JSON.parse(raw);
|
|
15
|
+
if (data.version !== 1 || !Array.isArray(data.entries)) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const bySlug = new Map();
|
|
19
|
+
const byCollection = new Map();
|
|
20
|
+
for (const entry of data.entries) {
|
|
21
|
+
bySlug.set(entry.slug, entry);
|
|
22
|
+
}
|
|
23
|
+
for (const [collectionId, entries] of Object.entries(data.collections ?? {})) {
|
|
24
|
+
byCollection.set(collectionId, entries);
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
byCollection,
|
|
28
|
+
bySlug,
|
|
29
|
+
entries: data.entries,
|
|
30
|
+
errors: [],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export const loadPrebuiltOpenApiIndex = async (source) => {
|
|
38
|
+
try {
|
|
39
|
+
const raw = await source.readFile(PREBUILT_OPENAPI_INDEX_PATH);
|
|
40
|
+
const data = JSON.parse(raw);
|
|
41
|
+
if (data.version !== 1 || !Array.isArray(data.entries)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return data.entries;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
export const serializeSearchIndex = (items) => JSON.stringify({
|
|
51
|
+
items,
|
|
52
|
+
version: 1,
|
|
53
|
+
});
|
|
54
|
+
export const loadPrebuiltSearchIndex = async (source) => {
|
|
55
|
+
try {
|
|
56
|
+
const raw = await source.readFile(PREBUILT_SEARCH_INDEX_PATH);
|
|
57
|
+
const data = JSON.parse(raw);
|
|
58
|
+
if (data.version !== 1 || !Array.isArray(data.items)) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return data.items;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
export const serializeTocIndex = (itemsBySlug) => JSON.stringify({
|
|
68
|
+
itemsBySlug: Object.fromEntries(itemsBySlug),
|
|
69
|
+
version: 1,
|
|
70
|
+
});
|
|
71
|
+
export const loadPrebuiltTocIndex = async (source) => {
|
|
72
|
+
try {
|
|
73
|
+
const raw = await source.readFile(PREBUILT_TOC_INDEX_PATH);
|
|
74
|
+
const data = JSON.parse(raw);
|
|
75
|
+
if (data.version !== 1 || typeof data.itemsBySlug !== "object") {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return new Map(Object.entries(data.itemsBySlug ?? {}));
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
export const serializeUtilityIndex = (index) => JSON.stringify({
|
|
85
|
+
...index,
|
|
86
|
+
version: 1,
|
|
87
|
+
});
|
|
88
|
+
export const loadPrebuiltUtilityIndex = async (source) => {
|
|
89
|
+
try {
|
|
90
|
+
const raw = await source.readFile(PREBUILT_UTILITY_INDEX_PATH);
|
|
91
|
+
const data = JSON.parse(raw);
|
|
92
|
+
if (data.version !== 1 ||
|
|
93
|
+
typeof data.name !== "string" ||
|
|
94
|
+
!Array.isArray(data.pages)) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
description: data.description,
|
|
99
|
+
name: data.name,
|
|
100
|
+
pages: data.pages,
|
|
101
|
+
segments: Array.isArray(data.segments) ? data.segments : undefined,
|
|
102
|
+
slug: data.slug,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ContentSource } from "./content-source.js";
|
|
2
|
+
import type { ContentIndex, TocItem } from "./types.js";
|
|
3
|
+
export declare const extractToc: (source: string) => TocItem[];
|
|
4
|
+
export declare const buildTocIndex: (index: ContentIndex, source: ContentSource) => Promise<Map<string, TocItem[]>>;
|
|
5
|
+
//# sourceMappingURL=toc-index.d.ts.map
|