blume 0.5.2 → 0.5.4
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 +2235 -5942
- package/dist/cli/index.js.map +36 -65
- package/dist/types/core/config.d.ts +0 -8
- package/dist/types/core/data.d.ts +2 -2
- package/dist/types/core/schema.d.ts +58 -453
- package/dist/types/core/types.d.ts +1 -7
- package/docs/advanced/meta.ts +1 -8
- package/docs/advanced/skills.mdx +28 -0
- package/docs/configuration/ai.mdx +3 -1
- package/docs/configuration/index.mdx +13 -17
- package/docs/configuration/theming.mdx +3 -11
- package/docs/content/components.mdx +2 -53
- package/docs/content/i18n.mdx +1 -5
- package/docs/content/sources.mdx +1 -1
- package/docs/content/syntax.mdx +1 -1
- package/docs/index.mdx +0 -1
- package/docs/reference/cli.mdx +12 -13
- package/package.json +4 -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/mcp/discovery.ts +3 -1
- package/src/ai/mcp/server.ts +3 -1
- package/src/astro/component-slots.ts +10 -2
- package/src/astro/generate.ts +15 -12
- package/src/astro/integration.ts +0 -21
- package/src/astro/templates.ts +62 -37
- package/src/cli/coalesce.ts +43 -0
- package/src/cli/commands/dev.ts +30 -22
- package/src/cli/commands/validate.ts +0 -2
- package/src/cli/dev-lock.ts +4 -2
- 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 +8 -5
- package/src/components/content/Column.astro +1 -1
- package/src/components/content/Prompt.astro +8 -4
- package/src/components/content/Step.astro +3 -4
- package/src/components/content/Tab.astro +2 -3
- package/src/components/content/Tabs.astro +13 -2
- package/src/components/content/TypeTable.astro +5 -5
- package/src/components/content/Update.astro +1 -1
- package/src/components/content/mermaid-element.ts +20 -2
- package/src/components/islands/ask-ai.tsx +4 -8
- package/src/components/islands/base-path.ts +30 -0
- package/src/components/islands/hooks.ts +12 -8
- package/src/components/layout/Header.astro +26 -3
- package/src/components/layout/Logo.astro +5 -1
- package/src/components/layout/NavSelector.astro +1 -1
- package/src/components/layout/NavTree.astro +14 -14
- package/src/components/layout/PageActions.astro +17 -11
- package/src/components/layout/PageLayout.astro +42 -0
- package/src/components/layout/ReferenceLayout.astro +1 -0
- package/src/components/layout/RootLayout.astro +31 -2
- package/src/components/layout/Search.astro +9 -6
- package/src/components/layout/nav-utils.ts +9 -4
- package/src/components/layout/search/types.ts +16 -5
- package/src/components/openapi/ApiOverview.astro +4 -50
- package/src/components/openapi/ApiTagOperations.astro +42 -0
- package/src/components/openapi/ParametersTable.astro +1 -1
- package/src/components/openapi/SchemaProperty.astro +1 -1
- package/src/components/openapi/SchemaTable.astro +3 -3
- package/src/components/openapi/helpers.ts +17 -8
- package/src/components/openapi/snippets.ts +17 -4
- package/src/core/builtin-tags.ts +1 -3
- package/src/core/config.ts +19 -33
- package/src/core/data.ts +2 -2
- package/src/core/graph.ts +7 -5
- package/src/core/links.ts +5 -19
- package/src/core/meta.ts +1 -1
- package/src/core/navigation.ts +5 -6
- package/src/core/project-graph.ts +0 -5
- package/src/core/schema.ts +13 -90
- package/src/core/sources/filesystem.ts +19 -1
- package/src/core/sources/mdx-remote.ts +20 -4
- package/src/core/sources/normalize.ts +28 -6
- package/src/core/sources/resolve.ts +0 -13
- package/src/core/sources/watch.ts +45 -0
- package/src/core/types.ts +1 -8
- package/src/markdown/code-title.ts +6 -3
- package/src/markdown/package-install.ts +3 -1
- package/src/og/card.ts +16 -4
- package/src/openapi/parse.ts +197 -14
- package/src/openapi/render-mdx.ts +54 -11
- package/src/openapi/source.ts +19 -2
- package/src/search/sync/orama-cloud.ts +2 -0
- package/src/search/sync/typesense.ts +4 -0
- package/src/theme/entry.ts +45 -17
- package/src/theme/icons.ts +22 -104
- package/src/theme/palette.ts +35 -47
- package/src/theme/twoslash.ts +6 -1
- package/dist/types/core/bridge.d.ts +0 -24
- 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/docs/advanced/bridge.mdx +0 -76
- package/docs/advanced/migrate.mdx +0 -123
- package/src/astro/static-assets.ts +0 -117
- 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 -204
- package/src/migrate/fumadocs/config.ts +0 -155
- package/src/migrate/fumadocs/content.ts +0 -378
- package/src/migrate/fumadocs/frontmatter.ts +0 -18
- package/src/migrate/fumadocs/groups.ts +0 -237
- package/src/migrate/fumadocs/index.ts +0 -340
- 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 -958
- 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 -372
- package/src/migrate/mintlify/snippets.ts +0 -306
- 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 -374
- package/src/migrate/nextra/meta.ts +0 -266
- package/src/migrate/shared.ts +0 -728
- package/src/migrate/starlight/config.ts +0 -455
- package/src/migrate/starlight/content.ts +0 -78
- 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,155 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
import { basename, dirname, join } from "pathe";
|
|
5
|
-
|
|
6
|
-
import type { BlumeConfig } from "../../core/schema.ts";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Build a `BlumeConfig` for a Fumadocs project. Fumadocs is code-first — its
|
|
10
|
-
* navigation comes from the folder tree plus `meta.json` files, not a JSON
|
|
11
|
-
* config — so there is little to translate. We take the title from
|
|
12
|
-
* `package.json` and scrape the `loader({ baseUrl })` route prefix from the
|
|
13
|
-
* source loader so migrated routes keep serving under `/<baseUrl>`. The source
|
|
14
|
-
* files are TypeScript, so we read by pattern rather than executing them.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/** Loader files that may hold `loader({ baseUrl: "/docs" })`. */
|
|
18
|
-
const SOURCE_FILES = [
|
|
19
|
-
"lib/source.ts",
|
|
20
|
-
"app/source.ts",
|
|
21
|
-
"src/lib/source.ts",
|
|
22
|
-
"src/app/source.ts",
|
|
23
|
-
"source.ts",
|
|
24
|
-
];
|
|
25
|
-
|
|
26
|
-
const BASE_URL = /baseUrl\s*:\s*['"`](?<base>[^'"`]+)['"`]/u;
|
|
27
|
-
|
|
28
|
-
/** Title-case a package name (drop any scope) into a readable doc title. */
|
|
29
|
-
const prettifyTitle = (name: string): string => {
|
|
30
|
-
const base = name.includes("/")
|
|
31
|
-
? name.slice(name.lastIndexOf("/") + 1)
|
|
32
|
-
: name;
|
|
33
|
-
const words = base.split(/[-_\s]+/u).filter(Boolean);
|
|
34
|
-
if (words.length === 0) {
|
|
35
|
-
return "Documentation";
|
|
36
|
-
}
|
|
37
|
-
return words
|
|
38
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
39
|
-
.join(" ");
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Generic monorepo app-shell package names. When the migrated project is named
|
|
44
|
-
* one of these, its name makes a poor doc title ("Web"), so we fall back to the
|
|
45
|
-
* repo name — but only in a monorepo, where a better name is actually available.
|
|
46
|
-
*/
|
|
47
|
-
const GENERIC_NAMES = new Set([
|
|
48
|
-
"api",
|
|
49
|
-
"app",
|
|
50
|
-
"client",
|
|
51
|
-
"frontend",
|
|
52
|
-
"server",
|
|
53
|
-
"site",
|
|
54
|
-
"web",
|
|
55
|
-
"www",
|
|
56
|
-
]);
|
|
57
|
-
|
|
58
|
-
/** The nearest ancestor that is a git repository root, or null. */
|
|
59
|
-
const gitRepoRoot = (start: string): string | null => {
|
|
60
|
-
let dir = start;
|
|
61
|
-
for (;;) {
|
|
62
|
-
if (existsSync(join(dir, ".git"))) {
|
|
63
|
-
return dir;
|
|
64
|
-
}
|
|
65
|
-
const parent = dirname(dir);
|
|
66
|
-
if (parent === dir) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
dir = parent;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
/** The unscoped package name (`@acme/web` -> `web`). */
|
|
74
|
-
const bareName = (name: string): string =>
|
|
75
|
-
name.includes("/") ? name.slice(name.lastIndexOf("/") + 1) : name;
|
|
76
|
-
|
|
77
|
-
const readTitle = async (root: string): Promise<string> => {
|
|
78
|
-
const packageJson = join(root, "package.json");
|
|
79
|
-
if (!existsSync(packageJson)) {
|
|
80
|
-
return "Documentation";
|
|
81
|
-
}
|
|
82
|
-
try {
|
|
83
|
-
const parsed = JSON.parse(await readFile(packageJson, "utf-8")) as {
|
|
84
|
-
name?: unknown;
|
|
85
|
-
};
|
|
86
|
-
const { name } = parsed;
|
|
87
|
-
if (typeof name !== "string" || !name.trim()) {
|
|
88
|
-
return "Documentation";
|
|
89
|
-
}
|
|
90
|
-
// A generic name (`apps/web` -> "Web") is a weak title. In a monorepo the
|
|
91
|
-
// repo's own directory name is usually better, so prefer it when this isn't
|
|
92
|
-
// already the repo root.
|
|
93
|
-
if (GENERIC_NAMES.has(bareName(name).toLowerCase())) {
|
|
94
|
-
const repoRoot = gitRepoRoot(root);
|
|
95
|
-
if (repoRoot && repoRoot !== root) {
|
|
96
|
-
const repoTitle = prettifyTitle(basename(repoRoot));
|
|
97
|
-
if (repoTitle !== "Documentation") {
|
|
98
|
-
return repoTitle;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return prettifyTitle(name);
|
|
103
|
-
} catch {
|
|
104
|
-
return "Documentation";
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const scrapeBaseUrl = async (root: string): Promise<string | null> => {
|
|
109
|
-
for (const candidate of SOURCE_FILES) {
|
|
110
|
-
const file = join(root, candidate);
|
|
111
|
-
if (!existsSync(file)) {
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential probing of candidates
|
|
115
|
-
const base = BASE_URL.exec(await readFile(file, "utf-8"))?.groups?.base;
|
|
116
|
-
if (base) {
|
|
117
|
-
return base;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return null;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
export interface FumadocsConfigResult {
|
|
124
|
-
config: BlumeConfig;
|
|
125
|
-
warnings: string[];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** Resolve the Blume config and route prefix for a Fumadocs project. */
|
|
129
|
-
export const loadFumadocsConfig = async (
|
|
130
|
-
root: string
|
|
131
|
-
): Promise<FumadocsConfigResult> => {
|
|
132
|
-
const title = await readTitle(root);
|
|
133
|
-
const baseUrl = await scrapeBaseUrl(root);
|
|
134
|
-
// Default to the conventional Fumadocs `/docs` base when none is declared.
|
|
135
|
-
const prefix = (baseUrl ?? "docs").replaceAll(/^\/+|\/+$/gu, "");
|
|
136
|
-
const warnings: string[] = [];
|
|
137
|
-
|
|
138
|
-
if (prefix) {
|
|
139
|
-
warnings.push(
|
|
140
|
-
`Docs are served under /${prefix} (set content.sources prefix); change it to "" to serve from the site root.`
|
|
141
|
-
);
|
|
142
|
-
return {
|
|
143
|
-
config: {
|
|
144
|
-
content: {
|
|
145
|
-
sources: [{ prefix, root: "docs", type: "filesystem" }],
|
|
146
|
-
},
|
|
147
|
-
title,
|
|
148
|
-
},
|
|
149
|
-
warnings,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
warnings.push("Docs are served from the site root.");
|
|
154
|
-
return { config: { title }, warnings };
|
|
155
|
-
};
|
|
@@ -1,378 +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
|
-
} from "../shared.ts";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Source-to-source rewrites that turn Fumadocs-only MDX into idiomatic Blume
|
|
16
|
-
* markup. Runs once at migration time — no Fumadocs-aware plugins remain in the
|
|
17
|
-
* Blume runtime.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
// ---------------------------------------------------------------------------
|
|
21
|
-
// Imports
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
|
|
24
|
-
const FUMADOCS_IMPORT =
|
|
25
|
-
/^import\s+[\s\S]*?\s+from\s+["']fumadocs-(?:ui|core|mdx)(?:\/[^"']*)?["'];?[ \t]*\n?/gmu;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Drop `import … from "fumadocs-ui/…"` (and `-core`/`-mdx`) statements. Blume
|
|
29
|
-
* injects its components globally, so these imports would fail to resolve once
|
|
30
|
-
* the Fumadocs packages are gone.
|
|
31
|
-
*/
|
|
32
|
-
export const stripFumadocsImports = (source: string): string => {
|
|
33
|
-
const stripped = source.replace(FUMADOCS_IMPORT, "");
|
|
34
|
-
// Collapse the blank gap a removed import block leaves behind.
|
|
35
|
-
return stripped === source ? source : stripped.replaceAll(/\n{3,}/gu, "\n\n");
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// ---------------------------------------------------------------------------
|
|
39
|
-
// Callouts
|
|
40
|
-
// ---------------------------------------------------------------------------
|
|
41
|
-
|
|
42
|
-
/** Fumadocs `<Callout type="X">` values mapped to Blume directive names. */
|
|
43
|
-
const CALLOUT_TYPE_DIRECTIVES: Record<string, string> = {
|
|
44
|
-
error: "danger",
|
|
45
|
-
info: "info",
|
|
46
|
-
note: "note",
|
|
47
|
-
success: "success",
|
|
48
|
-
tip: "tip",
|
|
49
|
-
warn: "warning",
|
|
50
|
-
warning: "warning",
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Convert Fumadocs `<Callout type="info|warn|error|…" title="…">` components
|
|
55
|
-
* into Blume `:::` directives. A bare `<Callout>` becomes `:::note`; the `icon`
|
|
56
|
-
* prop is dropped.
|
|
57
|
-
*/
|
|
58
|
-
export const rewriteFumadocsCallouts = (source: string): string =>
|
|
59
|
-
rewriteCallouts(source, {
|
|
60
|
-
defaultDirective: "note",
|
|
61
|
-
tagDirectives: {},
|
|
62
|
-
tags: ["Callout"],
|
|
63
|
-
typeDirectives: CALLOUT_TYPE_DIRECTIVES,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// ---------------------------------------------------------------------------
|
|
67
|
-
// Container component renames
|
|
68
|
-
// ---------------------------------------------------------------------------
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Rename Fumadocs container components to their Blume equivalents. The
|
|
72
|
-
* lookahead in `renameTag` means a longer tag (`Accordions`, `Files`) is never
|
|
73
|
-
* matched by the rule for its shorter prefix (`Accordion`, `File`), so the
|
|
74
|
-
* item-level renames run first and the container renames second:
|
|
75
|
-
*
|
|
76
|
-
* - `<Cards>` -> `<CardGroup>` (items stay `<Card>`).
|
|
77
|
-
* - `<Accordions>`/`<Accordion>` -> `<Accordion>`/`<AccordionItem>`.
|
|
78
|
-
* - `<Files>`/`<Folder>`/`<File>` -> `<FileTree>`/`<TreeFolder>`/`<TreeFile>`.
|
|
79
|
-
*/
|
|
80
|
-
export const rewriteFumadocsContainers = (source: string): string => {
|
|
81
|
-
let out = renameTag(source, "Cards", "CardGroup");
|
|
82
|
-
out = renameTag(out, "Accordion", "AccordionItem");
|
|
83
|
-
out = renameTag(out, "Accordions", "Accordion");
|
|
84
|
-
out = renameTag(out, "File", "TreeFile");
|
|
85
|
-
out = renameTag(out, "Folder", "TreeFolder");
|
|
86
|
-
out = renameTag(out, "Files", "FileTree");
|
|
87
|
-
return out;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// ---------------------------------------------------------------------------
|
|
91
|
-
// Tabs (items + value -> per-Tab title)
|
|
92
|
-
// ---------------------------------------------------------------------------
|
|
93
|
-
|
|
94
|
-
const TABS_TAG = /<Tabs(?=[\s/>])/u;
|
|
95
|
-
const TAB_TAG = /<Tab(?=[\s/>])/u;
|
|
96
|
-
const ITEM_LITERAL = /'(?<s>[^']*)'|"(?<d>[^"]*)"|`(?<t>[^`]*)`/gu;
|
|
97
|
-
|
|
98
|
-
const escapeAttribute = (value: string): string =>
|
|
99
|
-
value.replaceAll('"', """);
|
|
100
|
-
|
|
101
|
-
/** Find the close brace matching the `{` at `open`, or -1 if unterminated. */
|
|
102
|
-
const matchBrace = (source: string, open: number): number => {
|
|
103
|
-
let depth = 0;
|
|
104
|
-
for (let index = open; index < source.length; index += 1) {
|
|
105
|
-
if (source[index] === "{") {
|
|
106
|
-
depth += 1;
|
|
107
|
-
} else if (source[index] === "}") {
|
|
108
|
-
depth -= 1;
|
|
109
|
-
if (depth === 0) {
|
|
110
|
-
return index;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return -1;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/** Span of an `items={…}` expression within a tag's attributes, or null. */
|
|
118
|
-
const itemsSpan = (attrs: string): { end: number; start: number } | null => {
|
|
119
|
-
const match = /\bitems\s*=\s*/u.exec(attrs);
|
|
120
|
-
if (!match) {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
const braceStart = attrs.indexOf("{", match.index + match[0].length);
|
|
124
|
-
if (braceStart === -1) {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
const braceEnd = matchBrace(attrs, braceStart);
|
|
128
|
-
return braceEnd === -1 ? null : { end: braceEnd, start: match.index };
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
/** Read the string literals from a Fumadocs `<Tabs items={[…]}>` attribute. */
|
|
132
|
-
const parseItems = (attrs: string): string[] => {
|
|
133
|
-
const span = itemsSpan(attrs);
|
|
134
|
-
if (!span) {
|
|
135
|
-
return [];
|
|
136
|
-
}
|
|
137
|
-
const inner = attrs.slice(span.start, span.end + 1);
|
|
138
|
-
const items: string[] = [];
|
|
139
|
-
for (const match of inner.matchAll(ITEM_LITERAL)) {
|
|
140
|
-
items.push(match.groups?.s ?? match.groups?.d ?? match.groups?.t ?? "");
|
|
141
|
-
}
|
|
142
|
-
return items;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
/** Rebuild a `<Tabs …>` open tag with the `items={…}` attribute removed. */
|
|
146
|
-
const buildTabsOpen = (attrs: string, selfClosing: boolean): string => {
|
|
147
|
-
const span = itemsSpan(attrs);
|
|
148
|
-
const withoutItems = span
|
|
149
|
-
? attrs.slice(0, span.start) + attrs.slice(span.end + 1)
|
|
150
|
-
: attrs;
|
|
151
|
-
const body = withoutItems.replace(/\/\s*$/u, "").trim();
|
|
152
|
-
const space = body ? ` ${body}` : "";
|
|
153
|
-
return selfClosing ? `<Tabs${space} />` : `<Tabs${space}>`;
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
/** Give a single `<Tab …>` open tag a `title`, preferring its own `value`. */
|
|
157
|
-
const titleizeTab = (tag: string, fallback: string | undefined): string => {
|
|
158
|
-
if (/\btitle\s*=/u.test(tag)) {
|
|
159
|
-
return tag;
|
|
160
|
-
}
|
|
161
|
-
if (/\bvalue\s*=/u.test(tag)) {
|
|
162
|
-
return tag.replace(/\bvalue(?<eq>\s*=)/u, "title$<eq>");
|
|
163
|
-
}
|
|
164
|
-
if (fallback === undefined) {
|
|
165
|
-
return tag;
|
|
166
|
-
}
|
|
167
|
-
return tag.replace(/^<Tab/u, `<Tab title="${escapeAttribute(fallback)}"`);
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Find the `</name>` that closes the tag opened at `from` (an index just past
|
|
172
|
-
* the open tag's `>`), honoring nesting. Returns its start index, or -1.
|
|
173
|
-
*/
|
|
174
|
-
const findMatchingClose = (
|
|
175
|
-
source: string,
|
|
176
|
-
from: number,
|
|
177
|
-
name: string
|
|
178
|
-
): number => {
|
|
179
|
-
const token = new RegExp(`<${name}(?=[\\s/>])|</${name}>`, "gu");
|
|
180
|
-
token.lastIndex = from;
|
|
181
|
-
let depth = 1;
|
|
182
|
-
for (let match = token.exec(source); match; match = token.exec(source)) {
|
|
183
|
-
if (match[0].startsWith("</")) {
|
|
184
|
-
depth -= 1;
|
|
185
|
-
if (depth === 0) {
|
|
186
|
-
return match.index;
|
|
187
|
-
}
|
|
188
|
-
} else {
|
|
189
|
-
depth += 1;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return -1;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
/** Title the direct `<Tab>` children of a Tabs block, skipping nested Tabs. */
|
|
196
|
-
const titleizeTabChildren = (inner: string, items: string[]): string => {
|
|
197
|
-
let output = "";
|
|
198
|
-
let cursor = 0;
|
|
199
|
-
let position = 0;
|
|
200
|
-
|
|
201
|
-
while (cursor < inner.length) {
|
|
202
|
-
const rest = inner.slice(cursor);
|
|
203
|
-
const tab = TAB_TAG.exec(rest);
|
|
204
|
-
if (!tab) {
|
|
205
|
-
output += rest;
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
const nested = TABS_TAG.exec(rest);
|
|
209
|
-
if (nested && nested.index < tab.index) {
|
|
210
|
-
const start = cursor + nested.index;
|
|
211
|
-
const openEnd = findOpenTagEnd(inner, start + "<Tabs".length);
|
|
212
|
-
const close =
|
|
213
|
-
openEnd === -1 ? -1 : findMatchingClose(inner, openEnd + 1, "Tabs");
|
|
214
|
-
if (close === -1) {
|
|
215
|
-
output += inner.slice(cursor);
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
const end = close + "</Tabs>".length;
|
|
219
|
-
output += inner.slice(cursor, end);
|
|
220
|
-
cursor = end;
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
const start = cursor + tab.index;
|
|
224
|
-
const openEnd = findOpenTagEnd(inner, start + "<Tab".length);
|
|
225
|
-
if (openEnd === -1) {
|
|
226
|
-
output += inner.slice(cursor, start + 1);
|
|
227
|
-
cursor = start + 1;
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
const tagText = inner.slice(start, openEnd + 1);
|
|
231
|
-
output +=
|
|
232
|
-
inner.slice(cursor, start) + titleizeTab(tagText, items[position]);
|
|
233
|
-
position += 1;
|
|
234
|
-
cursor = openEnd + 1;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return output;
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Reshape Fumadocs tabs to Blume's API. Fumadocs declares tab labels on the
|
|
242
|
-
* parent (`<Tabs items={['npm','pnpm']}>`) and selects with `<Tab value="npm">`;
|
|
243
|
-
* Blume's `<Tab>` carries its own `title`. Each tab is titled from its `value`
|
|
244
|
-
* (or the positional `items` entry) and the `items` prop is stripped. Nested
|
|
245
|
-
* tab groups are handled recursively with their own `items`.
|
|
246
|
-
*/
|
|
247
|
-
export const rewriteFumadocsTabs = (source: string): string => {
|
|
248
|
-
let output = "";
|
|
249
|
-
let cursor = 0;
|
|
250
|
-
|
|
251
|
-
while (cursor < source.length) {
|
|
252
|
-
const match = TABS_TAG.exec(source.slice(cursor));
|
|
253
|
-
if (!match) {
|
|
254
|
-
output += source.slice(cursor);
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
const start = cursor + match.index;
|
|
258
|
-
const openEnd = findOpenTagEnd(source, start + "<Tabs".length);
|
|
259
|
-
if (openEnd === -1) {
|
|
260
|
-
output += source.slice(cursor, start + 1);
|
|
261
|
-
cursor = start + 1;
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
const attrs = source.slice(start + "<Tabs".length, openEnd);
|
|
265
|
-
const selfClosing = attrs.trimEnd().endsWith("/");
|
|
266
|
-
output += source.slice(cursor, start);
|
|
267
|
-
|
|
268
|
-
if (selfClosing) {
|
|
269
|
-
output += buildTabsOpen(attrs, true);
|
|
270
|
-
cursor = openEnd + 1;
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const close = findMatchingClose(source, openEnd + 1, "Tabs");
|
|
275
|
-
if (close === -1) {
|
|
276
|
-
output += source.slice(start, openEnd + 1);
|
|
277
|
-
cursor = openEnd + 1;
|
|
278
|
-
continue;
|
|
279
|
-
}
|
|
280
|
-
const inner = rewriteFumadocsTabs(source.slice(openEnd + 1, close));
|
|
281
|
-
output += buildTabsOpen(attrs, false);
|
|
282
|
-
output += titleizeTabChildren(inner, parseItems(attrs));
|
|
283
|
-
output += "</Tabs>";
|
|
284
|
-
cursor = close + "</Tabs>".length;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return output;
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
// ---------------------------------------------------------------------------
|
|
291
|
-
// Includes
|
|
292
|
-
// ---------------------------------------------------------------------------
|
|
293
|
-
|
|
294
|
-
const INCLUDE = /<include\b[^>]*>(?<path>[\s\S]*?)<\/include>/gu;
|
|
295
|
-
|
|
296
|
-
interface IncludeOptions {
|
|
297
|
-
filePath: string;
|
|
298
|
-
readFile?: (file: string) => Promise<string>;
|
|
299
|
-
/** Docs root the include must stay within; targets escaping it are skipped. */
|
|
300
|
-
root: string;
|
|
301
|
-
seen?: Set<string>;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Inline Fumadocs `<include>./partial.mdx</include>` references — source-level
|
|
306
|
-
* includes with no Blume runtime equivalent. The referenced file's frontmatter
|
|
307
|
-
* is stripped, nested includes are resolved (with a cycle guard), and the path
|
|
308
|
-
* is resolved relative to the including file. Missing or circular targets are
|
|
309
|
-
* left untouched and reported.
|
|
310
|
-
*/
|
|
311
|
-
export const inlineFumadocsIncludes = async (
|
|
312
|
-
source: string,
|
|
313
|
-
options: IncludeOptions
|
|
314
|
-
): Promise<{ content: string; warnings: string[] }> => {
|
|
315
|
-
const matches = [...source.matchAll(INCLUDE)];
|
|
316
|
-
if (matches.length === 0) {
|
|
317
|
-
return { content: source, warnings: [] };
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
const read = options.readFile ?? ((file) => readFileFromDisk(file, "utf-8"));
|
|
321
|
-
const seen = options.seen ?? new Set<string>();
|
|
322
|
-
const warnings: string[] = [];
|
|
323
|
-
let content = source;
|
|
324
|
-
|
|
325
|
-
for (const match of matches) {
|
|
326
|
-
const rawPath = match.groups?.path?.trim() ?? "";
|
|
327
|
-
if (!rawPath) {
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
const target = resolve(dirname(options.filePath), rawPath);
|
|
331
|
-
if (!isInsideRoot(options.root, target)) {
|
|
332
|
-
warnings.push(
|
|
333
|
-
`<include> target "${rawPath}" is outside the docs tree — left as-is.`
|
|
334
|
-
);
|
|
335
|
-
continue;
|
|
336
|
-
}
|
|
337
|
-
if (seen.has(target)) {
|
|
338
|
-
warnings.push(`Circular <include> "${rawPath}" — left as-is.`);
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
if (!existsSync(target)) {
|
|
342
|
-
warnings.push(`<include> target "${rawPath}" not found — left as-is.`);
|
|
343
|
-
continue;
|
|
344
|
-
}
|
|
345
|
-
seen.add(target);
|
|
346
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential include reads
|
|
347
|
-
const raw = await read(target);
|
|
348
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential include reads
|
|
349
|
-
const nested = await inlineFumadocsIncludes(matter(raw).content.trim(), {
|
|
350
|
-
...options,
|
|
351
|
-
filePath: target,
|
|
352
|
-
seen,
|
|
353
|
-
});
|
|
354
|
-
seen.delete(target);
|
|
355
|
-
warnings.push(...nested.warnings);
|
|
356
|
-
content = content.replace(match[0], () => nested.content);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
return { content, warnings };
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
// ---------------------------------------------------------------------------
|
|
363
|
-
// Unsupported components
|
|
364
|
-
// ---------------------------------------------------------------------------
|
|
365
|
-
|
|
366
|
-
/** Fumadocs components with no drop-in Blume equivalent — flagged for review. */
|
|
367
|
-
const UNSUPPORTED_COMPONENTS = [
|
|
368
|
-
"Banner",
|
|
369
|
-
"DynamicCodeBlock",
|
|
370
|
-
"ImageZoom",
|
|
371
|
-
"InlineTOC",
|
|
372
|
-
];
|
|
373
|
-
|
|
374
|
-
/** Names of Fumadocs components in `source` that need manual attention. */
|
|
375
|
-
export const unsupportedFumadocsComponents = (source: string): string[] =>
|
|
376
|
-
UNSUPPORTED_COMPONENTS.filter((name) =>
|
|
377
|
-
new RegExp(`<${name}\\b`, "u").test(source)
|
|
378
|
-
);
|
|
@@ -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
|
-
};
|