@wrksz/docs 0.0.0-stage → 0.1.1
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 +157 -2
- package/dist/agents.d.ts +30 -0
- package/dist/agents.js +70 -0
- package/dist/components/agent-logos.js +90 -0
- package/dist/components/agent-prompt.d.ts +29 -0
- package/dist/components/agent-prompt.js +100 -0
- package/dist/components/badge.d.ts +16 -0
- package/dist/components/badge.js +26 -0
- package/dist/components/brand.js +32 -0
- package/dist/components/callout.d.ts +24 -0
- package/dist/components/callout.js +58 -0
- package/dist/components/cards.d.ts +26 -0
- package/dist/components/cards.js +48 -0
- package/dist/components/code-body.js +18 -0
- package/dist/components/code-group.d.ts +20 -0
- package/dist/components/code-group.js +41 -0
- package/dist/components/code-tabs.d.ts +30 -0
- package/dist/components/code-tabs.js +49 -0
- package/dist/components/content-tabs.d.ts +14 -0
- package/dist/components/content-tabs.js +27 -0
- package/dist/components/copy-code.js +41 -0
- package/dist/components/deferred-analytics.js +5 -0
- package/dist/components/details.d.ts +20 -0
- package/dist/components/details.js +29 -0
- package/dist/components/heading-link.js +23 -0
- package/dist/components/heading.d.ts +5 -0
- package/dist/components/heading.js +22 -0
- package/dist/components/icons.js +362 -0
- package/dist/components/image.d.ts +27 -0
- package/dist/components/image.js +204 -0
- package/dist/components/inline-text.js +14 -0
- package/dist/components/install.d.ts +22 -0
- package/dist/components/install.js +62 -0
- package/dist/components/mdx-tabs.d.ts +22 -0
- package/dist/components/mdx-tabs.js +30 -0
- package/dist/components/practice.d.ts +41 -0
- package/dist/components/practice.js +99 -0
- package/dist/components/props.d.ts +37 -0
- package/dist/components/props.js +70 -0
- package/dist/components/status.js +35 -0
- package/dist/components/steps.d.ts +18 -0
- package/dist/components/steps.js +23 -0
- package/dist/components/theme-switch.js +31 -0
- package/dist/components/ui/kbd.js +410 -0
- package/dist/components/ui/scroll-area.js +169 -0
- package/dist/components/ui/table.d.ts +33 -0
- package/dist/components/ui/table.js +103 -0
- package/dist/components/ui/tabs.js +69 -0
- package/dist/components/ui/toast.js +629 -0
- package/dist/components/ui/tooltip.js +31 -0
- package/dist/components/wrksz-mark.js +12 -0
- package/dist/docs/index.d.ts +8 -0
- package/dist/docs/index.js +8 -0
- package/dist/docs/layout.d.ts +6 -0
- package/dist/docs/layout.js +10 -0
- package/dist/docs/page-actions.d.ts +36 -0
- package/dist/docs/page-actions.js +136 -0
- package/dist/docs/page-footer.d.ts +14 -0
- package/dist/docs/page-footer.js +68 -0
- package/dist/docs/page-header.d.ts +13 -0
- package/dist/docs/page-header.js +57 -0
- package/dist/docs/page.d.ts +16 -0
- package/dist/docs/page.js +38 -0
- package/dist/docs/reading.js +64 -0
- package/dist/docs/shell.js +101 -0
- package/dist/docs/sidebar.js +161 -0
- package/dist/docs/toc-bar.d.ts +12 -0
- package/dist/docs/toc-bar.js +132 -0
- package/dist/docs/toc.d.ts +11 -0
- package/dist/docs/toc.js +127 -0
- package/dist/fonts/Inter-Italic.woff2 +0 -0
- package/dist/fonts/Inter-LICENSE.txt +92 -0
- package/dist/fonts/Inter.woff2 +0 -0
- package/dist/fonts/IoskeleyMono-Bold.woff2 +0 -0
- package/dist/fonts/IoskeleyMono-Italic.woff2 +0 -0
- package/dist/fonts/IoskeleyMono-LICENSE.txt +92 -0
- package/dist/fonts/IoskeleyMono-Regular.woff2 +0 -0
- package/dist/fonts.d.ts +1 -0
- package/dist/fonts.js +38 -0
- package/dist/home/features.d.ts +39 -0
- package/dist/home/features.js +75 -0
- package/dist/home/footer.d.ts +4 -0
- package/dist/home/footer.js +79 -0
- package/dist/home/hero-content.js +102 -0
- package/dist/home/hero-install.js +128 -0
- package/dist/home/hero-stage.d.ts +4 -0
- package/dist/home/hero-stage.js +9 -0
- package/dist/home/hero.d.ts +6 -0
- package/dist/home/hero.js +16 -0
- package/dist/home/home-header.d.ts +1 -0
- package/dist/home/home-header.js +173 -0
- package/dist/home/index.d.ts +7 -0
- package/dist/home/index.js +7 -0
- package/dist/home/layout.d.ts +6 -0
- package/dist/home/layout.js +15 -0
- package/dist/home/reveal.js +31 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/lib/clipboard.js +55 -0
- package/dist/lib/cn.js +1 -0
- package/dist/lib/format.js +9 -0
- package/dist/lib/package-manager-script.js +12 -0
- package/dist/lib/package-manager.js +54 -0
- package/dist/lib/theme-config.js +10 -0
- package/dist/llms.d.ts +34 -0
- package/dist/llms.js +111 -0
- package/dist/next.d.ts +18 -0
- package/dist/next.js +45 -0
- package/dist/node_modules/.pnpm/@types_mdast@4.0.4/node_modules/@types/mdast/index.d.ts +930 -0
- package/dist/node_modules/.pnpm/@types_mdx@2.0.14/node_modules/@types/mdx/types.d.ts +81 -0
- package/dist/node_modules/.pnpm/@types_unist@3.0.3/node_modules/@types/unist/index.d.ts +80 -0
- package/dist/registry.d.ts +61 -0
- package/dist/registry.js +113 -0
- package/dist/root.d.ts +9 -0
- package/dist/root.js +34 -0
- package/dist/search.d.ts +5 -0
- package/dist/search.js +43 -0
- package/dist/seo/index.d.ts +6 -0
- package/dist/seo/index.js +6 -0
- package/dist/seo/json-ld.d.ts +17 -0
- package/dist/seo/json-ld.js +88 -0
- package/dist/seo/metadata.d.ts +21 -0
- package/dist/seo/metadata.js +75 -0
- package/dist/seo/robots.d.ts +14 -0
- package/dist/seo/robots.js +18 -0
- package/dist/seo/sitemap.d.ts +16 -0
- package/dist/seo/sitemap.js +26 -0
- package/dist/seo/url.d.ts +6 -0
- package/dist/seo/url.js +11 -0
- package/dist/server.js +63 -0
- package/dist/site-context.js +17 -0
- package/dist/site.d.ts +41 -0
- package/dist/site.js +13 -0
- package/dist/source/compile.d.ts +6 -0
- package/dist/source/compile.js +32 -0
- package/dist/source/errors.d.ts +4 -0
- package/dist/source/errors.js +10 -0
- package/dist/source/frontmatter.d.ts +13 -0
- package/dist/source/frontmatter.js +102 -0
- package/dist/source/highlight.js +102 -0
- package/dist/source/index.d.ts +36 -0
- package/dist/source/index.js +102 -0
- package/dist/source/markdown.d.ts +48 -0
- package/dist/source/markdown.js +393 -0
- package/dist/source/prompt.js +33 -0
- package/dist/source/scan.d.ts +8 -0
- package/dist/source/scan.js +64 -0
- package/dist/source/toc.d.ts +5 -0
- package/dist/source/toc.js +28 -0
- package/dist/source/tree.d.ts +29 -0
- package/dist/source/tree.js +91 -0
- package/dist/styles.css +879 -0
- package/dist/typography.d.ts +101 -0
- package/dist/typography.js +232 -0
- package/package.json +84 -4
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import remarkGfm from "remark-gfm";
|
|
2
|
+
import remarkMdx from "remark-mdx";
|
|
3
|
+
import remarkParse from "remark-parse";
|
|
4
|
+
import remarkStringify from "remark-stringify";
|
|
5
|
+
import { unified } from "unified";
|
|
6
|
+
import { fillPrompt } from "../agents.js";
|
|
7
|
+
import { installCommands, npm } from "../registry.js";
|
|
8
|
+
import { promptOf } from "./prompt.js";
|
|
9
|
+
// src/source/markdown.ts
|
|
10
|
+
const text = (value) => ({
|
|
11
|
+
type: "text",
|
|
12
|
+
value
|
|
13
|
+
});
|
|
14
|
+
const strong = (...children) => ({
|
|
15
|
+
type: "strong",
|
|
16
|
+
children
|
|
17
|
+
});
|
|
18
|
+
const paragraph = (...children) => ({
|
|
19
|
+
type: "paragraph",
|
|
20
|
+
children
|
|
21
|
+
});
|
|
22
|
+
const cell = (children) => ({
|
|
23
|
+
type: "tableCell",
|
|
24
|
+
children
|
|
25
|
+
});
|
|
26
|
+
const row = (cells) => ({
|
|
27
|
+
type: "tableRow",
|
|
28
|
+
children: cells.map(cell)
|
|
29
|
+
});
|
|
30
|
+
function table(header, rows) {
|
|
31
|
+
return {
|
|
32
|
+
type: "table",
|
|
33
|
+
align: header.map(() => null),
|
|
34
|
+
children: [row(header.map((label) => [text(label)])), ...rows.map(row)]
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function isJsx(node) {
|
|
38
|
+
const type = node.type;
|
|
39
|
+
return type === "mdxJsxFlowElement" || type === "mdxJsxTextElement";
|
|
40
|
+
}
|
|
41
|
+
function attribute(element, name) {
|
|
42
|
+
for (const item of element.attributes) {
|
|
43
|
+
if (item.type !== "mdxJsxAttribute" || item.name !== name) continue;
|
|
44
|
+
if (item.value === null || item.value === void 0) return true;
|
|
45
|
+
if (typeof item.value === "string") return item.value;
|
|
46
|
+
const raw = item.value.value.trim();
|
|
47
|
+
if (raw === "true") return true;
|
|
48
|
+
if (/^(["'`]).*\1$/.test(raw)) return raw.slice(1, -1);
|
|
49
|
+
if (/^-?\d+(\.\d+)?$/.test(raw)) return raw;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const string = (value) => typeof value === "string" ? value : "";
|
|
54
|
+
/**
|
|
55
|
+
* Elements named `name` inside `element`. A child written on one line, like
|
|
56
|
+
* `<Card …>text</Card>`, sits inside a paragraph, so plain Markdown nodes are searched too;
|
|
57
|
+
* other components are not, so nested lists stay separate.
|
|
58
|
+
*/
|
|
59
|
+
function children(element, name) {
|
|
60
|
+
return element.children.flatMap((child) => {
|
|
61
|
+
if (isJsx(child)) return child.name === name ? [child] : [];
|
|
62
|
+
return "children" in child ? children(child, name) : [];
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const CALLOUTS = {
|
|
66
|
+
note: "Note",
|
|
67
|
+
info: "Info",
|
|
68
|
+
tip: "Tip",
|
|
69
|
+
warning: "Warning",
|
|
70
|
+
danger: "Danger"
|
|
71
|
+
};
|
|
72
|
+
/** How each built-in component reads as plain Markdown. */
|
|
73
|
+
const builtInLowerings = {
|
|
74
|
+
Callout(element, { attr, children, inline }) {
|
|
75
|
+
const label = CALLOUTS[string(attr("type"))] ?? "Note";
|
|
76
|
+
const title = string(attr("title"));
|
|
77
|
+
const heading = strong(text(title ? `${label}: ` : label), ...title ? inline(title) : []);
|
|
78
|
+
return [{
|
|
79
|
+
type: "blockquote",
|
|
80
|
+
children: [paragraph(heading), ...children]
|
|
81
|
+
}];
|
|
82
|
+
},
|
|
83
|
+
AgentPrompt(element, { attr, children: nodes, inline, options }) {
|
|
84
|
+
const { prompt, code } = promptOf(element);
|
|
85
|
+
const origin = (options.origin ?? "").replace(/\/$/, "");
|
|
86
|
+
const filled = fillPrompt(prompt, {
|
|
87
|
+
origin,
|
|
88
|
+
page: `${origin}${(options.pageUrl ?? "").replace(/\/$/, "")}.md`
|
|
89
|
+
});
|
|
90
|
+
const rest = code ? nodes.filter((node) => !(node.type === "code" && node.value === code.value)) : nodes;
|
|
91
|
+
return [{
|
|
92
|
+
type: "blockquote",
|
|
93
|
+
children: [
|
|
94
|
+
paragraph(strong(text("Prompt for an AI agent: "), ...inline(string(attr("title"))))),
|
|
95
|
+
...rest,
|
|
96
|
+
{
|
|
97
|
+
type: "code",
|
|
98
|
+
lang: "text",
|
|
99
|
+
value: filled
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}];
|
|
103
|
+
},
|
|
104
|
+
Badge: () => void 0,
|
|
105
|
+
CodeGroup: () => void 0,
|
|
106
|
+
Install(element, { attr, options }) {
|
|
107
|
+
const id = string(attr("registry"));
|
|
108
|
+
const registry = (id ? options.registries?.[id] ?? (options.registry?.id === id ? options.registry : void 0) : options.registry) ?? npm;
|
|
109
|
+
return [{
|
|
110
|
+
type: "code",
|
|
111
|
+
lang: "bash",
|
|
112
|
+
value: installCommands(registry, string(attr("package")), { dev: attr("dev") === true || attr("dev") === "true" }).map((item) => item.command).join("\n")
|
|
113
|
+
}];
|
|
114
|
+
},
|
|
115
|
+
Tabs(element, context) {
|
|
116
|
+
return children(element, "Tab").flatMap((tab) => [paragraph(strong(...context.inline(string(attribute(tab, "title"))))), ...lowerChildren(tab, context.options)]);
|
|
117
|
+
},
|
|
118
|
+
Steps(_element, { children: nodes }) {
|
|
119
|
+
let step = 0;
|
|
120
|
+
return nodes.map((node) => {
|
|
121
|
+
if (node.type !== "heading" || node.depth !== 3) return node;
|
|
122
|
+
step += 1;
|
|
123
|
+
return {
|
|
124
|
+
...node,
|
|
125
|
+
children: [text(`${step}. `), ...node.children]
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
Props(element, context) {
|
|
130
|
+
return [table([
|
|
131
|
+
"Name",
|
|
132
|
+
"Type",
|
|
133
|
+
"Default",
|
|
134
|
+
"Description"
|
|
135
|
+
], [...children(element, "Prop")].map((prop) => {
|
|
136
|
+
const flags = [
|
|
137
|
+
attribute(prop, "required") ? "Required." : "",
|
|
138
|
+
attribute(prop, "deprecated") ? "Deprecated." : "",
|
|
139
|
+
attribute(prop, "since") ? `Since ${string(attribute(prop, "since"))}.` : ""
|
|
140
|
+
].filter(Boolean);
|
|
141
|
+
const description = context.phrasing(lowerChildren(prop, context.options));
|
|
142
|
+
const fallback = string(attribute(prop, "default"));
|
|
143
|
+
return [
|
|
144
|
+
[{
|
|
145
|
+
type: "inlineCode",
|
|
146
|
+
value: string(attribute(prop, "name"))
|
|
147
|
+
}],
|
|
148
|
+
string(attribute(prop, "type")) ? [{
|
|
149
|
+
type: "inlineCode",
|
|
150
|
+
value: string(attribute(prop, "type"))
|
|
151
|
+
}] : [],
|
|
152
|
+
fallback ? [{
|
|
153
|
+
type: "inlineCode",
|
|
154
|
+
value: fallback
|
|
155
|
+
}] : [],
|
|
156
|
+
[...flags.length ? [text(`${flags.join(" ")} `)] : [], ...description]
|
|
157
|
+
];
|
|
158
|
+
}))];
|
|
159
|
+
},
|
|
160
|
+
Do: (element, context) => practice("Do", element, context),
|
|
161
|
+
Dont: (element, context) => practice("Don't", element, context),
|
|
162
|
+
Pairs(element, context) {
|
|
163
|
+
const rows = children(element, "Pair").map((pair) => [context.inline(string(attribute(pair, "label"))), context.phrasing(lowerChildren(pair, context.options))]);
|
|
164
|
+
return [table([string(context.attr("left")) || "Avoid", string(context.attr("right")) || "Use instead"], rows)];
|
|
165
|
+
},
|
|
166
|
+
Details(_element, { attr, children: nodes, inline }) {
|
|
167
|
+
return [paragraph(strong(...inline(string(attr("title"))))), ...nodes];
|
|
168
|
+
},
|
|
169
|
+
Cards(element, context) {
|
|
170
|
+
return [{
|
|
171
|
+
type: "list",
|
|
172
|
+
ordered: false,
|
|
173
|
+
spread: false,
|
|
174
|
+
children: children(element, "Card").map((card) => {
|
|
175
|
+
const description = context.phrasing(lowerChildren(card, context.options));
|
|
176
|
+
return {
|
|
177
|
+
type: "listItem",
|
|
178
|
+
spread: false,
|
|
179
|
+
children: [{
|
|
180
|
+
type: "paragraph",
|
|
181
|
+
children: [{
|
|
182
|
+
type: "link",
|
|
183
|
+
url: context.href(string(attribute(card, "href"))),
|
|
184
|
+
children: context.inline(string(attribute(card, "title")))
|
|
185
|
+
}, ...description.length ? [text(": "), ...description] : []]
|
|
186
|
+
}]
|
|
187
|
+
};
|
|
188
|
+
})
|
|
189
|
+
}];
|
|
190
|
+
},
|
|
191
|
+
Image(_element, { attr, inline, options }) {
|
|
192
|
+
const src = absolute(string(attr("src")), options);
|
|
193
|
+
const caption = string(attr("caption"));
|
|
194
|
+
return [paragraph({
|
|
195
|
+
type: "image",
|
|
196
|
+
url: src,
|
|
197
|
+
alt: string(attr("alt"))
|
|
198
|
+
}), ...caption ? [paragraph({
|
|
199
|
+
type: "emphasis",
|
|
200
|
+
children: inline(caption)
|
|
201
|
+
})] : []];
|
|
202
|
+
},
|
|
203
|
+
Table(element, context) {
|
|
204
|
+
const rows = [];
|
|
205
|
+
const collect = (node) => {
|
|
206
|
+
for (const child of node.children) {
|
|
207
|
+
if (!isJsx(child)) continue;
|
|
208
|
+
if (child.name === "TableRow") rows.push(child.children.filter(isJsx).map((item) => context.phrasing(lowerChildren(item, context.options))));
|
|
209
|
+
else collect(child);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
collect(element);
|
|
213
|
+
const [head, ...body] = rows;
|
|
214
|
+
if (!head) return [];
|
|
215
|
+
return [{
|
|
216
|
+
type: "table",
|
|
217
|
+
align: head.map(() => null),
|
|
218
|
+
children: [head, ...body].map(row)
|
|
219
|
+
}];
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
builtInLowerings.PropsTable = builtInLowerings.Props;
|
|
223
|
+
function practice(label, element, context) {
|
|
224
|
+
const caption = string(attribute(element, "caption"));
|
|
225
|
+
return [paragraph(strong(text(`${label}:`)), ...caption ? [text(" "), ...context.inline(caption)] : []), ...context.children];
|
|
226
|
+
}
|
|
227
|
+
function absolute(url, options) {
|
|
228
|
+
if (!url.startsWith("/") || url.startsWith("//") || !options.origin) return url;
|
|
229
|
+
return `${options.origin.replace(/\/$/, "")}${url}`;
|
|
230
|
+
}
|
|
231
|
+
/** `/docs/guides` becomes `https://…/docs/guides.md`; anchors and other paths stay. */
|
|
232
|
+
function markdownHref(href, options) {
|
|
233
|
+
const base = options.baseUrl ?? "/docs";
|
|
234
|
+
const [path = "", hash] = href.split("#");
|
|
235
|
+
if (!path.startsWith("/")) return href;
|
|
236
|
+
return absolute(path === base || path.startsWith(`${base}/`) ? `${path.replace(/\/$/, "")}.md` : path, options) + (hash ? `#${hash}` : "");
|
|
237
|
+
}
|
|
238
|
+
const inlineParser = unified().use(remarkParse).use(remarkGfm);
|
|
239
|
+
function parseInline(value) {
|
|
240
|
+
if (!value) return [];
|
|
241
|
+
const first = inlineParser.parse(value).children[0];
|
|
242
|
+
return first?.type === "paragraph" ? first.children : [text(value)];
|
|
243
|
+
}
|
|
244
|
+
const PHRASING = /* @__PURE__ */ new Set([
|
|
245
|
+
"text",
|
|
246
|
+
"inlineCode",
|
|
247
|
+
"strong",
|
|
248
|
+
"emphasis",
|
|
249
|
+
"delete",
|
|
250
|
+
"link",
|
|
251
|
+
"linkReference",
|
|
252
|
+
"image",
|
|
253
|
+
"imageReference",
|
|
254
|
+
"break",
|
|
255
|
+
"html",
|
|
256
|
+
"footnoteReference"
|
|
257
|
+
]);
|
|
258
|
+
const isPhrasing = (node) => PHRASING.has(node.type);
|
|
259
|
+
/**
|
|
260
|
+
* Wraps runs of inline nodes in paragraphs and drops runs that are only whitespace, so the
|
|
261
|
+
* children of a one-line component, like `<Callout>Text **bold**</Callout>`, read as blocks.
|
|
262
|
+
*/
|
|
263
|
+
function toBlocks(nodes) {
|
|
264
|
+
const out = [];
|
|
265
|
+
let run = [];
|
|
266
|
+
const flush = () => {
|
|
267
|
+
if (run.some((node) => node.type !== "text" || node.value.trim())) out.push(paragraph(...run));
|
|
268
|
+
run = [];
|
|
269
|
+
};
|
|
270
|
+
for (const node of nodes) if (isPhrasing(node)) run.push(node);
|
|
271
|
+
else {
|
|
272
|
+
flush();
|
|
273
|
+
out.push(node);
|
|
274
|
+
}
|
|
275
|
+
flush();
|
|
276
|
+
return out;
|
|
277
|
+
}
|
|
278
|
+
function toPhrasing(nodes) {
|
|
279
|
+
const out = [];
|
|
280
|
+
for (const node of nodes) {
|
|
281
|
+
if (isPhrasing(node)) {
|
|
282
|
+
out.push(node);
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if (out.length) out.push(text(" "));
|
|
286
|
+
if (node.type === "paragraph") out.push(...node.children);
|
|
287
|
+
else if (node.type === "code") out.push({
|
|
288
|
+
type: "inlineCode",
|
|
289
|
+
value: node.value
|
|
290
|
+
});
|
|
291
|
+
else if ("children" in node) out.push(...toPhrasing(node.children));
|
|
292
|
+
else if ("value" in node && typeof node.value === "string") out.push(text(node.value));
|
|
293
|
+
}
|
|
294
|
+
return out;
|
|
295
|
+
}
|
|
296
|
+
/** Notation the highlighter reads; agents get the code as it ends up, without it. */
|
|
297
|
+
const NOTATION = /\s*(?:\/\/|#|--|\/\*|\{\/\*|<!--)\s*\[!code\s+(\+\+|--|highlight|hl)\]\s*(?:\*\/\}|\*\/|-->)?\s*$/;
|
|
298
|
+
function cleanCode(node) {
|
|
299
|
+
const lines = node.value.split("\n").flatMap((line) => {
|
|
300
|
+
const match = NOTATION.exec(line);
|
|
301
|
+
if (!match) return [line];
|
|
302
|
+
return match[1] === "--" ? [] : [line.slice(0, match.index)];
|
|
303
|
+
});
|
|
304
|
+
const title = /(?:^|\s)title=(?:"[^"]*"|'[^']*')/.exec(node.meta ?? "")?.[0]?.trim();
|
|
305
|
+
return {
|
|
306
|
+
...node,
|
|
307
|
+
value: lines.join("\n"),
|
|
308
|
+
meta: title ?? null
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function lowerNodes(nodes, options) {
|
|
312
|
+
const lowerings = {
|
|
313
|
+
...builtInLowerings,
|
|
314
|
+
...options.components
|
|
315
|
+
};
|
|
316
|
+
const out = [];
|
|
317
|
+
for (const node of nodes) {
|
|
318
|
+
const type = node.type;
|
|
319
|
+
if (type === "mdxjsEsm" || type === "mdxFlowExpression" || type === "mdxTextExpression") continue;
|
|
320
|
+
if (isJsx(node)) {
|
|
321
|
+
const lowering = node.name ? lowerings[node.name] : void 0;
|
|
322
|
+
const lowered = lowerChildren(node, options);
|
|
323
|
+
const result = lowering?.(node, context(node, lowered, options));
|
|
324
|
+
out.push(...result ?? lowered);
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
if (node.type === "code") {
|
|
328
|
+
out.push(cleanCode(node));
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (node.type === "link") {
|
|
332
|
+
out.push({
|
|
333
|
+
...node,
|
|
334
|
+
url: markdownHref(node.url, options),
|
|
335
|
+
children: lowerNodes(node.children, options)
|
|
336
|
+
});
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (node.type === "image") {
|
|
340
|
+
out.push({
|
|
341
|
+
...node,
|
|
342
|
+
url: absolute(node.url, options)
|
|
343
|
+
});
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
if (node.type === "paragraph") {
|
|
347
|
+
out.push(...toBlocks(lowerNodes(node.children, options)));
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
if ("children" in node) {
|
|
351
|
+
out.push({
|
|
352
|
+
...node,
|
|
353
|
+
children: lowerNodes(node.children, options)
|
|
354
|
+
});
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
out.push(node);
|
|
358
|
+
}
|
|
359
|
+
return out;
|
|
360
|
+
}
|
|
361
|
+
function lowerChildren(element, options) {
|
|
362
|
+
return lowerNodes(element.children, options);
|
|
363
|
+
}
|
|
364
|
+
function context(element, lowered, options) {
|
|
365
|
+
return {
|
|
366
|
+
attr: (name) => attribute(element, name),
|
|
367
|
+
children: toBlocks(lowered),
|
|
368
|
+
inline: parseInline,
|
|
369
|
+
phrasing: toPhrasing,
|
|
370
|
+
href: (href) => markdownHref(href, options),
|
|
371
|
+
options
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
const parser = unified().use(remarkParse).use(remarkMdx).use(remarkGfm);
|
|
375
|
+
const printer = unified().use(remarkStringify, {
|
|
376
|
+
bullet: "-",
|
|
377
|
+
fences: true,
|
|
378
|
+
rule: "-"
|
|
379
|
+
}).use(remarkGfm, { tablePipeAlign: false });
|
|
380
|
+
/**
|
|
381
|
+
* Turns the MDX body of a page into plain Markdown for agents and `.md` exports: components
|
|
382
|
+
* become the Markdown they stand for, imports and expressions go, highlighter notation is
|
|
383
|
+
* stripped from code, and links on the site point at Markdown pages.
|
|
384
|
+
*/
|
|
385
|
+
function mdxToMarkdown(body, { title, description, ...options } = {}) {
|
|
386
|
+
const lowered = {
|
|
387
|
+
type: "root",
|
|
388
|
+
children: lowerNodes(parser.parse(body).children, options)
|
|
389
|
+
};
|
|
390
|
+
const content = String(printer.stringify(lowered)).trim();
|
|
391
|
+
return `${[...[title ? `# ${title}` : "", description ? `> ${description}` : ""].filter(Boolean), content].filter(Boolean).join("\n\n")}\n`;
|
|
392
|
+
}
|
|
393
|
+
export { builtInLowerings, mdxToMarkdown };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { visit } from "unist-util-visit";
|
|
2
|
+
// src/source/prompt.ts
|
|
3
|
+
/**
|
|
4
|
+
* The prompt of an `<AgentPrompt>`: its `prompt` attribute, or else the first fenced code
|
|
5
|
+
* block inside it. A fence keeps the text raw, so `{page}` and `{llms}` stay placeholders
|
|
6
|
+
* instead of turning into MDX expressions.
|
|
7
|
+
*/
|
|
8
|
+
function promptOf(element) {
|
|
9
|
+
const attribute = element.attributes.find((item) => item.type === "mdxJsxAttribute" && item.name === "prompt");
|
|
10
|
+
if (attribute && typeof attribute.value === "string") return { prompt: attribute.value };
|
|
11
|
+
const code = element.children.find((child) => child.type === "code");
|
|
12
|
+
return code ? {
|
|
13
|
+
prompt: code.value,
|
|
14
|
+
code
|
|
15
|
+
} : { prompt: "" };
|
|
16
|
+
}
|
|
17
|
+
/** Moves the fenced prompt of every `<AgentPrompt>` into its `prompt` attribute. */
|
|
18
|
+
function remarkAgentPrompt() {
|
|
19
|
+
return (tree) => {
|
|
20
|
+
visit(tree, "mdxJsxFlowElement", (node) => {
|
|
21
|
+
if (node.name !== "AgentPrompt") return;
|
|
22
|
+
const { prompt, code } = promptOf(node);
|
|
23
|
+
if (!code) return;
|
|
24
|
+
node.children = node.children.filter((child) => child !== code);
|
|
25
|
+
node.attributes.push({
|
|
26
|
+
type: "mdxJsxAttribute",
|
|
27
|
+
name: "prompt",
|
|
28
|
+
value: prompt
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export { promptOf, remarkAgentPrompt };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { join, relative, sep } from "node:path";
|
|
3
|
+
import { ContentError } from "./errors.js";
|
|
4
|
+
import { parseFrontmatter } from "./frontmatter.js";
|
|
5
|
+
// src/source/scan.ts
|
|
6
|
+
const EXTENSIONS = [".mdx", ".md"];
|
|
7
|
+
function readMeta(file, display) {
|
|
8
|
+
let raw;
|
|
9
|
+
try {
|
|
10
|
+
raw = JSON.parse(readFileSync(file, "utf8"));
|
|
11
|
+
} catch (error) {
|
|
12
|
+
throw new ContentError(display, `is not valid JSON. ${error.message}`);
|
|
13
|
+
}
|
|
14
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) throw new ContentError(display, "should be an object.");
|
|
15
|
+
const meta = {};
|
|
16
|
+
for (const [key, value] of Object.entries(raw)) if (key === "title") {
|
|
17
|
+
if (typeof value !== "string") throw new ContentError(display, `"title" should be a string.`);
|
|
18
|
+
meta.title = value;
|
|
19
|
+
} else if (key === "pages") {
|
|
20
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) throw new ContentError(display, `"pages" should be a list of strings.`);
|
|
21
|
+
meta.pages = value;
|
|
22
|
+
} else throw new ContentError(display, `"${key}" is not a meta.json field. Use "title" or "pages".`);
|
|
23
|
+
return meta;
|
|
24
|
+
}
|
|
25
|
+
function toSlugs(path) {
|
|
26
|
+
const parts = path.replace(/\.mdx?$/, "").split("/");
|
|
27
|
+
if (parts.at(-1) === "index") parts.pop();
|
|
28
|
+
return parts;
|
|
29
|
+
}
|
|
30
|
+
function scanContent(root, baseUrl, drafts) {
|
|
31
|
+
const base = baseUrl.replace(/\/$/, "");
|
|
32
|
+
function walk(dir) {
|
|
33
|
+
const path = relative(root, dir).split(sep).join("/");
|
|
34
|
+
const folder = {
|
|
35
|
+
path,
|
|
36
|
+
name: path.split("/").at(-1) ?? "",
|
|
37
|
+
meta: {},
|
|
38
|
+
pages: [],
|
|
39
|
+
folders: []
|
|
40
|
+
};
|
|
41
|
+
for (const entry of readdirSync(dir).toSorted()) {
|
|
42
|
+
if (entry.startsWith(".") || entry.startsWith("_")) continue;
|
|
43
|
+
const absolute = join(dir, entry);
|
|
44
|
+
const file = relative(root, absolute).split(sep).join("/");
|
|
45
|
+
if (statSync(absolute).isDirectory()) folder.folders.push(walk(absolute));
|
|
46
|
+
else if (entry === "meta.json") folder.meta = readMeta(absolute, file);
|
|
47
|
+
else if (EXTENSIONS.some((ext) => entry.endsWith(ext))) {
|
|
48
|
+
const { data, body } = parseFrontmatter(file, readFileSync(absolute, "utf8"));
|
|
49
|
+
if (data.draft && !drafts) continue;
|
|
50
|
+
const slugs = toSlugs(file);
|
|
51
|
+
folder.pages.push({
|
|
52
|
+
path: file,
|
|
53
|
+
slugs,
|
|
54
|
+
url: slugs.length ? `${base}/${slugs.join("/")}` : base || "/",
|
|
55
|
+
data,
|
|
56
|
+
body
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return folder;
|
|
61
|
+
}
|
|
62
|
+
return walk(root);
|
|
63
|
+
}
|
|
64
|
+
export { scanContent };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import GithubSlugger from "github-slugger";
|
|
2
|
+
import { toString } from "hast-util-to-string";
|
|
3
|
+
import { visit } from "unist-util-visit";
|
|
4
|
+
// src/source/toc.ts
|
|
5
|
+
const DEPTHS = {
|
|
6
|
+
h2: 2,
|
|
7
|
+
h3: 3,
|
|
8
|
+
h4: 4
|
|
9
|
+
};
|
|
10
|
+
function rehypeToc(options) {
|
|
11
|
+
return (tree) => {
|
|
12
|
+
const slugger = new GithubSlugger();
|
|
13
|
+
visit(tree, "element", (node) => {
|
|
14
|
+
if (!/^h[1-6]$/.test(node.tagName)) return;
|
|
15
|
+
const title = toString(node).trim();
|
|
16
|
+
const existing = node.properties.id;
|
|
17
|
+
const id = typeof existing === "string" && existing ? existing : slugger.slug(title);
|
|
18
|
+
node.properties.id = id;
|
|
19
|
+
const depth = DEPTHS[node.tagName];
|
|
20
|
+
if (depth && title) options.toc.push({
|
|
21
|
+
id,
|
|
22
|
+
title,
|
|
23
|
+
depth
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export { rehypeToc };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PageStatus } from "./frontmatter.js";
|
|
2
|
+
export type TreePage = {
|
|
3
|
+
type: "page";
|
|
4
|
+
title: string;
|
|
5
|
+
url: string;
|
|
6
|
+
status?: PageStatus;
|
|
7
|
+
};
|
|
8
|
+
export type TreeLink = {
|
|
9
|
+
type: "link";
|
|
10
|
+
title: string;
|
|
11
|
+
href: string;
|
|
12
|
+
status?: PageStatus;
|
|
13
|
+
};
|
|
14
|
+
export type TreeFolder = {
|
|
15
|
+
type: "folder";
|
|
16
|
+
title: string;
|
|
17
|
+
url?: string;
|
|
18
|
+
status?: PageStatus;
|
|
19
|
+
children: TreeNode[];
|
|
20
|
+
};
|
|
21
|
+
export type TreeSection = {
|
|
22
|
+
type: "section";
|
|
23
|
+
title: string;
|
|
24
|
+
};
|
|
25
|
+
export type TreeNode = TreePage | TreeLink | TreeFolder | TreeSection;
|
|
26
|
+
export type Crumb = {
|
|
27
|
+
title: string;
|
|
28
|
+
url?: string;
|
|
29
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ContentError } from "./errors.js";
|
|
2
|
+
// src/source/tree.ts
|
|
3
|
+
function entryName(page) {
|
|
4
|
+
return page.path.split("/").at(-1)?.replace(/\.mdx?$/, "") ?? "";
|
|
5
|
+
}
|
|
6
|
+
function pageNode(page) {
|
|
7
|
+
const title = page.data.navTitle ?? page.data.title;
|
|
8
|
+
const status = page.data.status ? { status: page.data.status } : {};
|
|
9
|
+
return page.data.external ? {
|
|
10
|
+
type: "link",
|
|
11
|
+
title,
|
|
12
|
+
href: page.data.external,
|
|
13
|
+
...status
|
|
14
|
+
} : {
|
|
15
|
+
type: "page",
|
|
16
|
+
title,
|
|
17
|
+
url: page.url,
|
|
18
|
+
...status
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function folderNode(folder) {
|
|
22
|
+
const index = folder.pages.find((page) => entryName(page) === "index");
|
|
23
|
+
return {
|
|
24
|
+
type: "folder",
|
|
25
|
+
title: folder.meta.title ?? index?.data.navTitle ?? index?.data.title ?? folder.name,
|
|
26
|
+
...index && !index.data.external ? { url: index.url } : {},
|
|
27
|
+
...index?.data.status ? { status: index.data.status } : {},
|
|
28
|
+
children: children(folder, Boolean(index))
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function children(folder, skipIndex) {
|
|
32
|
+
const pages = new Map(folder.pages.map((page) => [entryName(page), page]));
|
|
33
|
+
const folders = new Map(folder.folders.map((child) => [child.name, child]));
|
|
34
|
+
const used = /* @__PURE__ */ new Set();
|
|
35
|
+
const nodes = [];
|
|
36
|
+
const metaFile = folder.path ? `${folder.path}/meta.json` : "meta.json";
|
|
37
|
+
const add = (name) => {
|
|
38
|
+
used.add(name);
|
|
39
|
+
const page = pages.get(name);
|
|
40
|
+
if (page) {
|
|
41
|
+
if (!(skipIndex && name === "index") && !page.data.hidden) nodes.push(pageNode(page));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const child = folders.get(name);
|
|
45
|
+
if (child) {
|
|
46
|
+
nodes.push(folderNode(child));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
throw new ContentError(metaFile, `lists "${name}", but there is no ${name}.mdx or ${name}/ next to it.`);
|
|
50
|
+
};
|
|
51
|
+
for (const item of folder.meta.pages ?? []) if (item.startsWith("# ")) nodes.push({
|
|
52
|
+
type: "section",
|
|
53
|
+
title: item.slice(2).trim()
|
|
54
|
+
});
|
|
55
|
+
else add(item);
|
|
56
|
+
const rest = [...pages.keys(), ...folders.keys()].filter((name) => !used.has(name)).toSorted((a, b) => a === "index" ? -1 : b === "index" ? 1 : a.localeCompare(b));
|
|
57
|
+
for (const name of rest) add(name);
|
|
58
|
+
return nodes;
|
|
59
|
+
}
|
|
60
|
+
function buildTree(root) {
|
|
61
|
+
return children(root, false);
|
|
62
|
+
}
|
|
63
|
+
function findTrail(nodes, url) {
|
|
64
|
+
let section = [];
|
|
65
|
+
for (const node of nodes) {
|
|
66
|
+
if (node.type === "section") section = [{ title: node.title }];
|
|
67
|
+
if ((node.type === "page" || node.type === "folder") && node.url === url) return section;
|
|
68
|
+
if (node.type !== "folder") continue;
|
|
69
|
+
const trail = findTrail(node.children, url);
|
|
70
|
+
if (trail) return [
|
|
71
|
+
...section,
|
|
72
|
+
{
|
|
73
|
+
title: node.title,
|
|
74
|
+
...node.url ? { url: node.url } : {}
|
|
75
|
+
},
|
|
76
|
+
...trail
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function flattenTree(nodes) {
|
|
81
|
+
return nodes.flatMap((node) => {
|
|
82
|
+
if (node.type === "page") return [node];
|
|
83
|
+
if (node.type === "folder") return [...node.url ? [{
|
|
84
|
+
type: "page",
|
|
85
|
+
title: node.title,
|
|
86
|
+
url: node.url
|
|
87
|
+
}] : [], ...flattenTree(node.children)];
|
|
88
|
+
return [];
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
export { buildTree, findTrail, flattenTree };
|