blume 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +3349 -7024
- package/dist/cli/index.js.map +39 -69
- package/dist/types/core/config.d.ts +0 -8
- package/dist/types/core/data.d.ts +6 -2
- package/dist/types/core/i18n-ui.d.ts +50 -0
- package/dist/types/core/schema.d.ts +379 -485
- package/dist/types/core/types.d.ts +8 -6
- package/docs/advanced/meta.ts +1 -8
- package/docs/advanced/skills.mdx +28 -0
- package/docs/configuration/ai.mdx +58 -0
- package/docs/configuration/index.mdx +13 -17
- package/docs/configuration/seo.mdx +59 -1
- package/docs/configuration/theming.mdx +15 -18
- package/docs/content/components.mdx +2 -53
- package/docs/content/i18n.mdx +0 -4
- package/docs/content/meta.mdx +3 -17
- package/docs/content/navigation.mdx +41 -4
- package/docs/content/syntax.mdx +1 -1
- package/docs/index.mdx +0 -1
- package/docs/reference/cli.mdx +12 -13
- package/package.json +6 -6
- package/skills/blume/SKILL.md +71 -0
- package/skills/blume-update-docs/SKILL.md +52 -0
- package/skills/blume-update-docs/references/audit-checklist.md +46 -0
- package/src/ai/agent-readability.ts +97 -0
- package/src/ai/ask-context.ts +131 -8
- package/src/ai/ask-data.ts +4 -1
- package/src/astro/generate.ts +19 -12
- package/src/astro/integration.ts +0 -21
- package/src/astro/templates.ts +33 -21
- package/src/cli/commands/build.ts +15 -0
- package/src/cli/commands/dev.ts +31 -20
- package/src/cli/commands/validate.ts +0 -2
- package/src/cli/dev-lock.ts +94 -21
- package/src/cli/index.ts +0 -2
- package/src/components/BlumePage.astro +0 -6
- package/src/components/Icon.astro +1 -12
- package/src/components/content/AccordionItem.astro +3 -6
- package/src/components/content/Badge.astro +1 -3
- package/src/components/content/Callout.astro +3 -9
- package/src/components/content/Card.astro +2 -3
- package/src/components/content/ColorItem.astro +2 -2
- package/src/components/content/Column.astro +1 -1
- package/src/components/content/GithubInfo.astro +11 -10
- package/src/components/content/Prompt.astro +1 -1
- package/src/components/content/Step.astro +3 -4
- package/src/components/content/Tab.astro +2 -3
- package/src/components/content/TypeTable.astro +13 -8
- package/src/components/content/Update.astro +1 -1
- package/src/components/islands/AskAI.astro +66 -2
- package/src/components/islands/ask-ai.tsx +289 -53
- package/src/components/layout/Header.astro +27 -4
- package/src/components/layout/Logo.astro +5 -1
- package/src/components/layout/NavSelector.astro +1 -1
- package/src/components/layout/NavTree.astro +15 -15
- package/src/components/layout/PageActions.astro +73 -30
- package/src/components/layout/PageLayout.astro +42 -0
- package/src/components/layout/ReferenceLayout.astro +1 -0
- package/src/components/layout/RootLayout.astro +79 -4
- package/src/components/layout/Search.astro +5 -5
- package/src/components/layout/nav-utils.ts +9 -4
- package/src/components/openapi/ApiOverview.astro +4 -50
- package/src/components/openapi/ApiTagOperations.astro +42 -0
- package/src/core/builtin-tags.ts +1 -3
- package/src/core/config.ts +5 -28
- package/src/core/data.ts +6 -2
- package/src/core/graph.ts +8 -6
- package/src/core/i18n-ui.ts +5 -0
- package/src/core/links.ts +5 -19
- package/src/core/meta.ts +1 -1
- package/src/core/nav-diagnostics.ts +7 -0
- package/src/core/navigation.ts +38 -17
- package/src/core/project-graph.ts +0 -5
- package/src/core/schema.ts +133 -95
- package/src/core/sources/filesystem.ts +5 -1
- package/src/core/sources/resolve.ts +0 -13
- package/src/core/sources/watch.ts +43 -11
- package/src/core/types.ts +8 -6
- package/src/deploy/robots.ts +37 -4
- package/src/openapi/parse.ts +197 -14
- package/src/openapi/render-mdx.ts +44 -10
- package/src/openapi/scalar.ts +1 -1
- package/src/openapi/source.ts +19 -2
- package/src/search/documents.ts +9 -2
- package/src/theme/entry.ts +45 -17
- package/src/theme/icons.ts +18 -109
- package/src/theme/palette.ts +25 -51
- package/src/theme/twoslash.ts +6 -1
- package/dist/types/core/bridge.d.ts +0 -24
- package/dist/types/core/package-json.d.ts +0 -12
- package/dist/types/migrate/mintlify/assets.d.ts +0 -8
- package/dist/types/migrate/mintlify/config.d.ts +0 -16
- package/dist/types/migrate/mintlify/i18n.d.ts +0 -7
- package/dist/types/migrate/shared.d.ts +0 -153
- package/docs/advanced/bridge.mdx +0 -76
- package/docs/advanced/migrate.mdx +0 -124
- package/src/astro/static-assets.ts +0 -124
- package/src/cli/commands/migrate.ts +0 -39
- package/src/components/content/ApiField.astro +0 -75
- package/src/components/content/ParamField.astro +0 -39
- package/src/components/content/RequestField.astro +0 -23
- package/src/components/content/ResponseField.astro +0 -23
- package/src/components/content/Warning.astro +0 -9
- package/src/core/assets.ts +0 -31
- package/src/core/bridge.ts +0 -102
- package/src/core/sources/mintlify.ts +0 -190
- package/src/migrate/fumadocs/config.ts +0 -155
- package/src/migrate/fumadocs/content.ts +0 -376
- package/src/migrate/fumadocs/frontmatter.ts +0 -18
- package/src/migrate/fumadocs/groups.ts +0 -237
- package/src/migrate/fumadocs/index.ts +0 -355
- package/src/migrate/fumadocs/meta.ts +0 -244
- package/src/migrate/migrate.ts +0 -53
- package/src/migrate/mintlify/assets.ts +0 -46
- package/src/migrate/mintlify/config.ts +0 -954
- package/src/migrate/mintlify/content.ts +0 -120
- package/src/migrate/mintlify/frontmatter.ts +0 -126
- package/src/migrate/mintlify/i18n.ts +0 -51
- package/src/migrate/mintlify/icons.ts +0 -128
- package/src/migrate/mintlify/index.ts +0 -459
- package/src/migrate/mintlify/snippets.ts +0 -315
- package/src/migrate/mintlify/transform.ts +0 -82
- package/src/migrate/nextra/content.ts +0 -46
- package/src/migrate/nextra/frontmatter.ts +0 -40
- package/src/migrate/nextra/index.ts +0 -389
- package/src/migrate/nextra/meta.ts +0 -266
- package/src/migrate/shared.ts +0 -801
- package/src/migrate/starlight/config.ts +0 -455
- package/src/migrate/starlight/content.ts +0 -75
- package/src/migrate/starlight/frontmatter.ts +0 -111
- package/src/migrate/starlight/i18n.ts +0 -54
- package/src/migrate/starlight/index.ts +0 -131
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { readFile as readFileFromDisk } from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
import { dirname, resolve } from "pathe";
|
|
5
|
-
|
|
6
|
-
import matter from "../../core/frontmatter.ts";
|
|
7
|
-
import {
|
|
8
|
-
findOpenTagEnd,
|
|
9
|
-
isInsideRoot,
|
|
10
|
-
renameTag,
|
|
11
|
-
rewriteCallouts,
|
|
12
|
-
stripImports,
|
|
13
|
-
} from "../shared.ts";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Source-to-source rewrites that turn Fumadocs-only MDX into idiomatic Blume
|
|
17
|
-
* markup. Runs once at migration time — no Fumadocs-aware plugins remain in the
|
|
18
|
-
* Blume runtime.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
// Imports
|
|
23
|
-
// ---------------------------------------------------------------------------
|
|
24
|
-
|
|
25
|
-
const FUMADOCS_IMPORT =
|
|
26
|
-
/^import\s+[\s\S]*?\s+from\s+["']fumadocs-(?:ui|core|mdx)(?:\/[^"']*)?["'];?[ \t]*\n?/gmu;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Drop `import … from "fumadocs-ui/…"` (and `-core`/`-mdx`) statements. Blume
|
|
30
|
-
* injects its components globally, so these imports would fail to resolve once
|
|
31
|
-
* the Fumadocs packages are gone.
|
|
32
|
-
*/
|
|
33
|
-
export const stripFumadocsImports = (source: string): string =>
|
|
34
|
-
stripImports(source, FUMADOCS_IMPORT);
|
|
35
|
-
|
|
36
|
-
// ---------------------------------------------------------------------------
|
|
37
|
-
// Callouts
|
|
38
|
-
// ---------------------------------------------------------------------------
|
|
39
|
-
|
|
40
|
-
/** Fumadocs `<Callout type="X">` values mapped to Blume directive names. */
|
|
41
|
-
const CALLOUT_TYPE_DIRECTIVES: Record<string, string> = {
|
|
42
|
-
error: "danger",
|
|
43
|
-
info: "info",
|
|
44
|
-
note: "note",
|
|
45
|
-
success: "success",
|
|
46
|
-
tip: "tip",
|
|
47
|
-
warn: "warning",
|
|
48
|
-
warning: "warning",
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Convert Fumadocs `<Callout type="info|warn|error|…" title="…">` components
|
|
53
|
-
* into Blume `:::` directives. A bare `<Callout>` becomes `:::note`; the `icon`
|
|
54
|
-
* prop is dropped.
|
|
55
|
-
*/
|
|
56
|
-
export const rewriteFumadocsCallouts = (source: string): string =>
|
|
57
|
-
rewriteCallouts(source, {
|
|
58
|
-
defaultDirective: "note",
|
|
59
|
-
tagDirectives: {},
|
|
60
|
-
tags: ["Callout"],
|
|
61
|
-
typeDirectives: CALLOUT_TYPE_DIRECTIVES,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// ---------------------------------------------------------------------------
|
|
65
|
-
// Container component renames
|
|
66
|
-
// ---------------------------------------------------------------------------
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Rename Fumadocs container components to their Blume equivalents. The
|
|
70
|
-
* lookahead in `renameTag` means a longer tag (`Accordions`, `Files`) is never
|
|
71
|
-
* matched by the rule for its shorter prefix (`Accordion`, `File`), so the
|
|
72
|
-
* item-level renames run first and the container renames second:
|
|
73
|
-
*
|
|
74
|
-
* - `<Cards>` -> `<CardGroup>` (items stay `<Card>`).
|
|
75
|
-
* - `<Accordions>`/`<Accordion>` -> `<Accordion>`/`<AccordionItem>`.
|
|
76
|
-
* - `<Files>`/`<Folder>`/`<File>` -> `<FileTree>`/`<TreeFolder>`/`<TreeFile>`.
|
|
77
|
-
*/
|
|
78
|
-
export const rewriteFumadocsContainers = (source: string): string => {
|
|
79
|
-
let out = renameTag(source, "Cards", "CardGroup");
|
|
80
|
-
out = renameTag(out, "Accordion", "AccordionItem");
|
|
81
|
-
out = renameTag(out, "Accordions", "Accordion");
|
|
82
|
-
out = renameTag(out, "File", "TreeFile");
|
|
83
|
-
out = renameTag(out, "Folder", "TreeFolder");
|
|
84
|
-
out = renameTag(out, "Files", "FileTree");
|
|
85
|
-
return out;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// ---------------------------------------------------------------------------
|
|
89
|
-
// Tabs (items + value -> per-Tab title)
|
|
90
|
-
// ---------------------------------------------------------------------------
|
|
91
|
-
|
|
92
|
-
const TABS_TAG = /<Tabs(?=[\s/>])/u;
|
|
93
|
-
const TAB_TAG = /<Tab(?=[\s/>])/u;
|
|
94
|
-
const ITEM_LITERAL = /'(?<s>[^']*)'|"(?<d>[^"]*)"|`(?<t>[^`]*)`/gu;
|
|
95
|
-
|
|
96
|
-
const escapeAttribute = (value: string): string =>
|
|
97
|
-
value.replaceAll('"', """);
|
|
98
|
-
|
|
99
|
-
/** Find the close brace matching the `{` at `open`, or -1 if unterminated. */
|
|
100
|
-
const matchBrace = (source: string, open: number): number => {
|
|
101
|
-
let depth = 0;
|
|
102
|
-
for (let index = open; index < source.length; index += 1) {
|
|
103
|
-
if (source[index] === "{") {
|
|
104
|
-
depth += 1;
|
|
105
|
-
} else if (source[index] === "}") {
|
|
106
|
-
depth -= 1;
|
|
107
|
-
if (depth === 0) {
|
|
108
|
-
return index;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return -1;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
/** Span of an `items={…}` expression within a tag's attributes, or null. */
|
|
116
|
-
const itemsSpan = (attrs: string): { end: number; start: number } | null => {
|
|
117
|
-
const match = /\bitems\s*=\s*/u.exec(attrs);
|
|
118
|
-
if (!match) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
const braceStart = attrs.indexOf("{", match.index + match[0].length);
|
|
122
|
-
if (braceStart === -1) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
const braceEnd = matchBrace(attrs, braceStart);
|
|
126
|
-
return braceEnd === -1 ? null : { end: braceEnd, start: match.index };
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
/** Read the string literals from a Fumadocs `<Tabs items={[…]}>` attribute. */
|
|
130
|
-
const parseItems = (attrs: string): string[] => {
|
|
131
|
-
const span = itemsSpan(attrs);
|
|
132
|
-
if (!span) {
|
|
133
|
-
return [];
|
|
134
|
-
}
|
|
135
|
-
const inner = attrs.slice(span.start, span.end + 1);
|
|
136
|
-
const items: string[] = [];
|
|
137
|
-
for (const match of inner.matchAll(ITEM_LITERAL)) {
|
|
138
|
-
items.push(match.groups?.s ?? match.groups?.d ?? match.groups?.t ?? "");
|
|
139
|
-
}
|
|
140
|
-
return items;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
/** Rebuild a `<Tabs …>` open tag with the `items={…}` attribute removed. */
|
|
144
|
-
const buildTabsOpen = (attrs: string, selfClosing: boolean): string => {
|
|
145
|
-
const span = itemsSpan(attrs);
|
|
146
|
-
const withoutItems = span
|
|
147
|
-
? attrs.slice(0, span.start) + attrs.slice(span.end + 1)
|
|
148
|
-
: attrs;
|
|
149
|
-
const body = withoutItems.replace(/\/\s*$/u, "").trim();
|
|
150
|
-
const space = body ? ` ${body}` : "";
|
|
151
|
-
return selfClosing ? `<Tabs${space} />` : `<Tabs${space}>`;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
/** Give a single `<Tab …>` open tag a `title`, preferring its own `value`. */
|
|
155
|
-
const titleizeTab = (tag: string, fallback: string | undefined): string => {
|
|
156
|
-
if (/\btitle\s*=/u.test(tag)) {
|
|
157
|
-
return tag;
|
|
158
|
-
}
|
|
159
|
-
if (/\bvalue\s*=/u.test(tag)) {
|
|
160
|
-
return tag.replace(/\bvalue(?<eq>\s*=)/u, "title$<eq>");
|
|
161
|
-
}
|
|
162
|
-
if (fallback === undefined) {
|
|
163
|
-
return tag;
|
|
164
|
-
}
|
|
165
|
-
return tag.replace(/^<Tab/u, `<Tab title="${escapeAttribute(fallback)}"`);
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Find the `</name>` that closes the tag opened at `from` (an index just past
|
|
170
|
-
* the open tag's `>`), honoring nesting. Returns its start index, or -1.
|
|
171
|
-
*/
|
|
172
|
-
const findMatchingClose = (
|
|
173
|
-
source: string,
|
|
174
|
-
from: number,
|
|
175
|
-
name: string
|
|
176
|
-
): number => {
|
|
177
|
-
const token = new RegExp(`<${name}(?=[\\s/>])|</${name}>`, "gu");
|
|
178
|
-
token.lastIndex = from;
|
|
179
|
-
let depth = 1;
|
|
180
|
-
for (let match = token.exec(source); match; match = token.exec(source)) {
|
|
181
|
-
if (match[0].startsWith("</")) {
|
|
182
|
-
depth -= 1;
|
|
183
|
-
if (depth === 0) {
|
|
184
|
-
return match.index;
|
|
185
|
-
}
|
|
186
|
-
} else {
|
|
187
|
-
depth += 1;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return -1;
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
/** Title the direct `<Tab>` children of a Tabs block, skipping nested Tabs. */
|
|
194
|
-
const titleizeTabChildren = (inner: string, items: string[]): string => {
|
|
195
|
-
let output = "";
|
|
196
|
-
let cursor = 0;
|
|
197
|
-
let position = 0;
|
|
198
|
-
|
|
199
|
-
while (cursor < inner.length) {
|
|
200
|
-
const rest = inner.slice(cursor);
|
|
201
|
-
const tab = TAB_TAG.exec(rest);
|
|
202
|
-
if (!tab) {
|
|
203
|
-
output += rest;
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
const nested = TABS_TAG.exec(rest);
|
|
207
|
-
if (nested && nested.index < tab.index) {
|
|
208
|
-
const start = cursor + nested.index;
|
|
209
|
-
const openEnd = findOpenTagEnd(inner, start + "<Tabs".length);
|
|
210
|
-
const close =
|
|
211
|
-
openEnd === -1 ? -1 : findMatchingClose(inner, openEnd + 1, "Tabs");
|
|
212
|
-
if (close === -1) {
|
|
213
|
-
output += inner.slice(cursor);
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
const end = close + "</Tabs>".length;
|
|
217
|
-
output += inner.slice(cursor, end);
|
|
218
|
-
cursor = end;
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
const start = cursor + tab.index;
|
|
222
|
-
const openEnd = findOpenTagEnd(inner, start + "<Tab".length);
|
|
223
|
-
if (openEnd === -1) {
|
|
224
|
-
output += inner.slice(cursor, start + 1);
|
|
225
|
-
cursor = start + 1;
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
const tagText = inner.slice(start, openEnd + 1);
|
|
229
|
-
output +=
|
|
230
|
-
inner.slice(cursor, start) + titleizeTab(tagText, items[position]);
|
|
231
|
-
position += 1;
|
|
232
|
-
cursor = openEnd + 1;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return output;
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Reshape Fumadocs tabs to Blume's API. Fumadocs declares tab labels on the
|
|
240
|
-
* parent (`<Tabs items={['npm','pnpm']}>`) and selects with `<Tab value="npm">`;
|
|
241
|
-
* Blume's `<Tab>` carries its own `title`. Each tab is titled from its `value`
|
|
242
|
-
* (or the positional `items` entry) and the `items` prop is stripped. Nested
|
|
243
|
-
* tab groups are handled recursively with their own `items`.
|
|
244
|
-
*/
|
|
245
|
-
export const rewriteFumadocsTabs = (source: string): string => {
|
|
246
|
-
let output = "";
|
|
247
|
-
let cursor = 0;
|
|
248
|
-
|
|
249
|
-
while (cursor < source.length) {
|
|
250
|
-
const match = TABS_TAG.exec(source.slice(cursor));
|
|
251
|
-
if (!match) {
|
|
252
|
-
output += source.slice(cursor);
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
const start = cursor + match.index;
|
|
256
|
-
const openEnd = findOpenTagEnd(source, start + "<Tabs".length);
|
|
257
|
-
if (openEnd === -1) {
|
|
258
|
-
output += source.slice(cursor, start + 1);
|
|
259
|
-
cursor = start + 1;
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
const attrs = source.slice(start + "<Tabs".length, openEnd);
|
|
263
|
-
const selfClosing = attrs.trimEnd().endsWith("/");
|
|
264
|
-
output += source.slice(cursor, start);
|
|
265
|
-
|
|
266
|
-
if (selfClosing) {
|
|
267
|
-
output += buildTabsOpen(attrs, true);
|
|
268
|
-
cursor = openEnd + 1;
|
|
269
|
-
continue;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const close = findMatchingClose(source, openEnd + 1, "Tabs");
|
|
273
|
-
if (close === -1) {
|
|
274
|
-
output += source.slice(start, openEnd + 1);
|
|
275
|
-
cursor = openEnd + 1;
|
|
276
|
-
continue;
|
|
277
|
-
}
|
|
278
|
-
const inner = rewriteFumadocsTabs(source.slice(openEnd + 1, close));
|
|
279
|
-
output += buildTabsOpen(attrs, false);
|
|
280
|
-
output += titleizeTabChildren(inner, parseItems(attrs));
|
|
281
|
-
output += "</Tabs>";
|
|
282
|
-
cursor = close + "</Tabs>".length;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return output;
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
// ---------------------------------------------------------------------------
|
|
289
|
-
// Includes
|
|
290
|
-
// ---------------------------------------------------------------------------
|
|
291
|
-
|
|
292
|
-
const INCLUDE = /<include\b[^>]*>(?<path>[\s\S]*?)<\/include>/gu;
|
|
293
|
-
|
|
294
|
-
interface IncludeOptions {
|
|
295
|
-
filePath: string;
|
|
296
|
-
readFile?: (file: string) => Promise<string>;
|
|
297
|
-
/** Docs root the include must stay within; targets escaping it are skipped. */
|
|
298
|
-
root: string;
|
|
299
|
-
seen?: Set<string>;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Inline Fumadocs `<include>./partial.mdx</include>` references — source-level
|
|
304
|
-
* includes with no Blume runtime equivalent. The referenced file's frontmatter
|
|
305
|
-
* is stripped, nested includes are resolved (with a cycle guard), and the path
|
|
306
|
-
* is resolved relative to the including file. Missing or circular targets are
|
|
307
|
-
* left untouched and reported.
|
|
308
|
-
*/
|
|
309
|
-
export const inlineFumadocsIncludes = async (
|
|
310
|
-
source: string,
|
|
311
|
-
options: IncludeOptions
|
|
312
|
-
): Promise<{ content: string; warnings: string[] }> => {
|
|
313
|
-
const matches = [...source.matchAll(INCLUDE)];
|
|
314
|
-
if (matches.length === 0) {
|
|
315
|
-
return { content: source, warnings: [] };
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
const read = options.readFile ?? ((file) => readFileFromDisk(file, "utf-8"));
|
|
319
|
-
const seen = options.seen ?? new Set<string>();
|
|
320
|
-
const warnings: string[] = [];
|
|
321
|
-
let content = source;
|
|
322
|
-
|
|
323
|
-
for (const match of matches) {
|
|
324
|
-
const rawPath = match.groups?.path?.trim() ?? "";
|
|
325
|
-
if (!rawPath) {
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
const target = resolve(dirname(options.filePath), rawPath);
|
|
329
|
-
if (!isInsideRoot(options.root, target)) {
|
|
330
|
-
warnings.push(
|
|
331
|
-
`<include> target "${rawPath}" is outside the docs tree — left as-is.`
|
|
332
|
-
);
|
|
333
|
-
continue;
|
|
334
|
-
}
|
|
335
|
-
if (seen.has(target)) {
|
|
336
|
-
warnings.push(`Circular <include> "${rawPath}" — left as-is.`);
|
|
337
|
-
continue;
|
|
338
|
-
}
|
|
339
|
-
if (!existsSync(target)) {
|
|
340
|
-
warnings.push(`<include> target "${rawPath}" not found — left as-is.`);
|
|
341
|
-
continue;
|
|
342
|
-
}
|
|
343
|
-
seen.add(target);
|
|
344
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential include reads
|
|
345
|
-
const raw = await read(target);
|
|
346
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential include reads
|
|
347
|
-
const nested = await inlineFumadocsIncludes(matter(raw).content.trim(), {
|
|
348
|
-
...options,
|
|
349
|
-
filePath: target,
|
|
350
|
-
seen,
|
|
351
|
-
});
|
|
352
|
-
seen.delete(target);
|
|
353
|
-
warnings.push(...nested.warnings);
|
|
354
|
-
content = content.replace(match[0], () => nested.content);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
return { content, warnings };
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
// ---------------------------------------------------------------------------
|
|
361
|
-
// Unsupported components
|
|
362
|
-
// ---------------------------------------------------------------------------
|
|
363
|
-
|
|
364
|
-
/** Fumadocs components with no drop-in Blume equivalent — flagged for review. */
|
|
365
|
-
const UNSUPPORTED_COMPONENTS = [
|
|
366
|
-
"Banner",
|
|
367
|
-
"DynamicCodeBlock",
|
|
368
|
-
"ImageZoom",
|
|
369
|
-
"InlineTOC",
|
|
370
|
-
];
|
|
371
|
-
|
|
372
|
-
/** Names of Fumadocs components in `source` that need manual attention. */
|
|
373
|
-
export const unsupportedFumadocsComponents = (source: string): string[] =>
|
|
374
|
-
UNSUPPORTED_COMPONENTS.filter((name) =>
|
|
375
|
-
new RegExp(`<${name}\\b`, "u").test(source)
|
|
376
|
-
);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { stripUnknownPageMeta } from "../shared.ts";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Normalize Fumadocs page frontmatter for Blume. Fumadocs' core fields
|
|
5
|
-
* (`title`, `description`, `icon`) already validate against Blume's page schema
|
|
6
|
-
* and pass through untouched; Fumadocs-only keys with no equivalent — most
|
|
7
|
-
* notably `full` (full-width, no-TOC layout) — are dropped by the strict-schema
|
|
8
|
-
* strip and reported so the author can re-apply them by hand.
|
|
9
|
-
*/
|
|
10
|
-
export const normalizeFumadocsPageMeta = (
|
|
11
|
-
value: unknown
|
|
12
|
-
): { data: Record<string, unknown>; removed: string[] } => {
|
|
13
|
-
const data =
|
|
14
|
-
value && typeof value === "object" && !Array.isArray(value)
|
|
15
|
-
? { ...(value as Record<string, unknown>) }
|
|
16
|
-
: {};
|
|
17
|
-
return stripUnknownPageMeta(data);
|
|
18
|
-
};
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { existsSync, statSync } from "node:fs";
|
|
2
|
-
import { mkdir, rename, writeFile } from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
import { basename, join } from "pathe";
|
|
5
|
-
|
|
6
|
-
import { isInsideRoot } from "../shared.ts";
|
|
7
|
-
import { renderMetaModule } from "./meta.ts";
|
|
8
|
-
import type {
|
|
9
|
-
FumadocsPageItem,
|
|
10
|
-
FumadocsPagesStructure,
|
|
11
|
-
FumadocsSection,
|
|
12
|
-
} from "./meta.ts";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Rebuild Fumadocs `---Section---` separators as Blume group folders.
|
|
16
|
-
*
|
|
17
|
-
* Fumadocs draws a non-collapsible section heading from a `"---Label---"` entry
|
|
18
|
-
* in a folder's `pages` array — exactly what a Blume `(Label)/` group folder
|
|
19
|
-
* renders by default (`display: "flat"`). Blume has no flat-file "separator"
|
|
20
|
-
* primitive, so the only faithful, non-overriding home for a section is a group
|
|
21
|
-
* folder: it is route-transparent (the `(Label)` segment is stripped from URLs,
|
|
22
|
-
* see `core/sources/normalize.ts`) and composes with per-folder `meta.ts`,
|
|
23
|
-
* unlike a global `navigation.sidebar` override (which would disable every other
|
|
24
|
-
* folder's meta site-wide).
|
|
25
|
-
*
|
|
26
|
-
* The reshape runs against the already-migrated `docs/` tree, so each `pages`
|
|
27
|
-
* entry is resolved to a real page file or folder before it is moved. A section
|
|
28
|
-
* that is a single folder is left in place (wrapping it would double the
|
|
29
|
-
* heading); links have no file to move and are dropped with a warning.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
const PAGE_EXTS = [".mdx", ".md"];
|
|
33
|
-
const WORD_SPLIT = /[-_]/u;
|
|
34
|
-
const PATH_SEP = /[/\\]/u;
|
|
35
|
-
|
|
36
|
-
interface ResolvedEntry {
|
|
37
|
-
kind: "file" | "folder";
|
|
38
|
-
path: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const isDirectory = (path: string): boolean => {
|
|
42
|
-
try {
|
|
43
|
-
return statSync(path).isDirectory();
|
|
44
|
-
} catch {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/** Resolve a `pages` name to its on-disk page file or folder under `docsDir`. */
|
|
50
|
-
const resolveEntry = (docsDir: string, name: string): ResolvedEntry | null => {
|
|
51
|
-
// A `pages` entry is author-controlled; reject any that escapes `docsDir`
|
|
52
|
-
// (e.g. `"../../victim"`) so the later `rename` can't move a file out of the
|
|
53
|
-
// docs tree.
|
|
54
|
-
if (!isInsideRoot(docsDir, join(docsDir, name))) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
for (const ext of PAGE_EXTS) {
|
|
58
|
-
const file = join(docsDir, `${name}${ext}`);
|
|
59
|
-
if (existsSync(file)) {
|
|
60
|
-
return { kind: "file", path: file };
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const folder = join(docsDir, name);
|
|
64
|
-
return isDirectory(folder) ? { kind: "folder", path: folder } : null;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const humanize = (name: string): string =>
|
|
68
|
-
name
|
|
69
|
-
.split(WORD_SPLIT)
|
|
70
|
-
.filter(Boolean)
|
|
71
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
72
|
-
.join(" ");
|
|
73
|
-
|
|
74
|
-
const linkWarning = (item: { href: string; text: string }): string =>
|
|
75
|
-
`Dropped sidebar link "${item.text}" (${item.href}) — add it to navbar.links manually.`;
|
|
76
|
-
|
|
77
|
-
const extractWarning = (name: string): string =>
|
|
78
|
-
`Sidebar extract "...${name}" became a normal "${name}" group (its pages are not flattened into the parent).`;
|
|
79
|
-
|
|
80
|
-
export interface GroupReshapeResult {
|
|
81
|
-
/** Ordering keys for the parent folder's `meta.ts` `pages`. */
|
|
82
|
-
order: string[];
|
|
83
|
-
warnings: string[];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** Record an in-place item's ordering key (lead items, or an ungroupable run). */
|
|
87
|
-
const addUngroupedItem = (
|
|
88
|
-
item: FumadocsPageItem,
|
|
89
|
-
order: string[],
|
|
90
|
-
warnings: string[]
|
|
91
|
-
): void => {
|
|
92
|
-
if (item.kind === "link") {
|
|
93
|
-
warnings.push(linkWarning(item));
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (item.kind === "extract") {
|
|
97
|
-
warnings.push(extractWarning(item.name));
|
|
98
|
-
}
|
|
99
|
-
order.push(item.name);
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
/** A section of one folder keeps its place without a wrapping group folder. */
|
|
103
|
-
const reshapeSingleFolderSection = (
|
|
104
|
-
section: FumadocsSection,
|
|
105
|
-
only: FumadocsPageItem & { kind: "extract" | "ref" },
|
|
106
|
-
order: string[],
|
|
107
|
-
warnings: string[]
|
|
108
|
-
): void => {
|
|
109
|
-
order.push(only.name);
|
|
110
|
-
if (humanize(only.name).toLowerCase() !== section.label.toLowerCase()) {
|
|
111
|
-
warnings.push(
|
|
112
|
-
`Section "${section.label}" wraps folder "${only.name}"; set that folder's meta title to "${section.label}" to make the heading match.`
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
if (only.kind === "extract") {
|
|
116
|
-
warnings.push(extractWarning(only.name));
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
/** Move one section item into the group folder; return its ordering key. */
|
|
121
|
-
const moveItemIntoGroup = async (
|
|
122
|
-
item: FumadocsPageItem,
|
|
123
|
-
docsDir: string,
|
|
124
|
-
groupDir: string,
|
|
125
|
-
label: string,
|
|
126
|
-
warnings: string[]
|
|
127
|
-
): Promise<string | null> => {
|
|
128
|
-
if (item.kind === "link") {
|
|
129
|
-
warnings.push(linkWarning(item));
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
const resolved = resolveEntry(docsDir, item.name);
|
|
133
|
-
if (!resolved) {
|
|
134
|
-
warnings.push(
|
|
135
|
-
`Sidebar entry "${item.name}" in section "${label}" matched no page or folder; skipped.`
|
|
136
|
-
);
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
const dest = join(groupDir, basename(resolved.path));
|
|
140
|
-
if (existsSync(dest)) {
|
|
141
|
-
warnings.push(
|
|
142
|
-
`Skipped moving "${item.name}" into section "${label}" (target already exists).`
|
|
143
|
-
);
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
await mkdir(groupDir, { recursive: true });
|
|
147
|
-
await rename(resolved.path, dest);
|
|
148
|
-
if (item.kind === "extract") {
|
|
149
|
-
warnings.push(extractWarning(item.name));
|
|
150
|
-
}
|
|
151
|
-
return item.name;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const reshapeSection = async (
|
|
155
|
-
section: FumadocsSection,
|
|
156
|
-
docsDir: string,
|
|
157
|
-
order: string[],
|
|
158
|
-
warnings: string[]
|
|
159
|
-
): Promise<void> => {
|
|
160
|
-
const movable = section.items.filter((item) => item.kind !== "link");
|
|
161
|
-
|
|
162
|
-
// A lone folder already renders as its own group; wrapping it in a `(Label)/`
|
|
163
|
-
// folder would stack two headings, so leave it in place.
|
|
164
|
-
if (movable.length === 1) {
|
|
165
|
-
const [only] = movable as [FumadocsPageItem & { kind: "extract" | "ref" }];
|
|
166
|
-
if (resolveEntry(docsDir, only.name)?.kind === "folder") {
|
|
167
|
-
reshapeSingleFolderSection(section, only, order, warnings);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (PATH_SEP.test(section.label)) {
|
|
173
|
-
warnings.push(
|
|
174
|
-
`Section "${section.label}" has a slash in its name and can't become a group folder; its pages stay ungrouped.`
|
|
175
|
-
);
|
|
176
|
-
for (const item of section.items) {
|
|
177
|
-
addUngroupedItem(item, order, warnings);
|
|
178
|
-
}
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const groupDir = join(docsDir, `(${section.label})`);
|
|
183
|
-
const sectionKeys: string[] = [];
|
|
184
|
-
for (const item of section.items) {
|
|
185
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential moves into one group
|
|
186
|
-
const key = await moveItemIntoGroup(
|
|
187
|
-
item,
|
|
188
|
-
docsDir,
|
|
189
|
-
groupDir,
|
|
190
|
-
section.label,
|
|
191
|
-
warnings
|
|
192
|
-
);
|
|
193
|
-
if (key) {
|
|
194
|
-
sectionKeys.push(key);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Nothing movable (e.g. a link-only section) — drop the empty heading.
|
|
199
|
-
if (sectionKeys.length === 0) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// The group folder's key in the nav is its label, so order it by label.
|
|
204
|
-
order.push(section.label);
|
|
205
|
-
// Preserve the authored order of the section's pages.
|
|
206
|
-
if (sectionKeys.length > 1) {
|
|
207
|
-
await writeFile(
|
|
208
|
-
join(groupDir, "meta.ts"),
|
|
209
|
-
renderMetaModule({ pages: sectionKeys }),
|
|
210
|
-
"utf-8"
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Reshape a parsed `pages` structure into group folders under `docsDir`,
|
|
217
|
-
* returning the parent folder's `meta.ts` page ordering and any warnings. Items
|
|
218
|
-
* are moved within the already-migrated `docs/` tree, so this must run after the
|
|
219
|
-
* pages have been moved out of `content/docs`.
|
|
220
|
-
*/
|
|
221
|
-
export const reshapeFumadocsGroups = async (
|
|
222
|
-
structure: FumadocsPagesStructure,
|
|
223
|
-
docsDir: string
|
|
224
|
-
): Promise<GroupReshapeResult> => {
|
|
225
|
-
const order: string[] = [];
|
|
226
|
-
const warnings: string[] = [];
|
|
227
|
-
|
|
228
|
-
for (const item of structure.lead) {
|
|
229
|
-
addUngroupedItem(item, order, warnings);
|
|
230
|
-
}
|
|
231
|
-
for (const section of structure.sections) {
|
|
232
|
-
// oxlint-disable-next-line no-await-in-loop -- sections share `docsDir` state
|
|
233
|
-
await reshapeSection(section, docsDir, order, warnings);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return { order, warnings };
|
|
237
|
-
};
|