fumadocs-mdx 11.8.0 → 11.8.2
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/build-mdx-DnC1jKvn.d.cts +46 -0
- package/dist/build-mdx-DnC1jKvn.d.ts +46 -0
- package/dist/{chunk-XZR5QXVY.js → chunk-BWRDVK5L.js} +1 -1
- package/dist/{chunk-7JFPDRW7.js → chunk-QQWCBFFE.js} +2 -4
- package/dist/{chunk-XVL4ZQFK.js → chunk-QVZ7JH4H.js} +1 -1
- package/dist/{chunk-GYWPPGFD.js → chunk-SMSNZ6N5.js} +38 -7
- package/dist/chunk-SVTXMVLQ.js +139 -0
- package/dist/config/index.cjs +121 -70
- package/dist/config/index.d.cts +5 -1
- package/dist/config/index.d.ts +5 -1
- package/dist/config/index.js +2 -2
- package/dist/config/zod-3.cjs +121 -70
- package/dist/config/zod-3.d.cts +1 -1
- package/dist/config/zod-3.d.ts +1 -1
- package/dist/config/zod-3.js +2 -2
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/loader-mdx.cjs +130 -81
- package/dist/loader-mdx.js +8 -8
- package/dist/{mdx-options-3NB74EMB.js → mdx-options-T73E4LQB.js} +1 -1
- package/dist/next/index.cjs +42 -11
- package/dist/next/index.js +2 -2
- package/dist/runtime/async.cjs +122 -73
- package/dist/runtime/async.d.cts +3 -2
- package/dist/runtime/async.d.ts +3 -2
- package/dist/runtime/async.js +3 -3
- package/dist/runtime/vite.d.cts +3 -12
- package/dist/runtime/vite.d.ts +3 -12
- package/dist/{types-BukvTPdG.d.cts → types-BmVgoqsr.d.cts} +3 -12
- package/dist/{types-B2ozVm_9.d.ts → types-WSHJKA8L.d.ts} +3 -12
- package/dist/vite/index.cjs +126 -77
- package/dist/vite/index.js +3 -3
- package/package.json +9 -7
- package/dist/chunk-IGXZS2W6.js +0 -119
package/dist/config/zod-3.cjs
CHANGED
|
@@ -94,16 +94,42 @@ function defineConfig(config = {}) {
|
|
|
94
94
|
// src/utils/mdx-options.ts
|
|
95
95
|
var plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
|
|
96
96
|
|
|
97
|
-
// src/mdx-plugins/remark-
|
|
97
|
+
// src/mdx-plugins/remark-postprocess.ts
|
|
98
|
+
var import_unist_util_visit = require("unist-util-visit");
|
|
98
99
|
var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
function remarkPostprocess({
|
|
101
|
+
injectExports
|
|
102
|
+
}) {
|
|
103
|
+
return (tree, file) => {
|
|
104
|
+
let title;
|
|
105
|
+
const urls = [];
|
|
106
|
+
(0, import_unist_util_visit.visit)(tree, ["heading", "link"], (node) => {
|
|
107
|
+
if (node.type === "heading" && node.depth === 1) {
|
|
108
|
+
title = flattenNode(node);
|
|
109
|
+
}
|
|
110
|
+
if (node.type !== "link") return;
|
|
111
|
+
urls.push({
|
|
112
|
+
href: node.url
|
|
113
|
+
});
|
|
114
|
+
return "skip";
|
|
115
|
+
});
|
|
116
|
+
if (title) {
|
|
117
|
+
file.data.frontmatter ??= {};
|
|
118
|
+
if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
|
|
119
|
+
}
|
|
120
|
+
file.data.extractedReferences = urls;
|
|
121
|
+
for (const name of injectExports) {
|
|
122
|
+
if (!(name in file.data)) continue;
|
|
123
|
+
tree.children.unshift(getMdastExport(name, file.data[name]));
|
|
104
124
|
}
|
|
105
125
|
};
|
|
106
126
|
}
|
|
127
|
+
function flattenNode(node) {
|
|
128
|
+
if ("children" in node)
|
|
129
|
+
return node.children.map((child) => flattenNode(child)).join("");
|
|
130
|
+
if ("value" in node) return node.value;
|
|
131
|
+
return "";
|
|
132
|
+
}
|
|
107
133
|
function getMdastExport(name, value) {
|
|
108
134
|
return {
|
|
109
135
|
type: "mdxjsEsm",
|
|
@@ -115,6 +141,7 @@ function getMdastExport(name, value) {
|
|
|
115
141
|
body: [
|
|
116
142
|
{
|
|
117
143
|
type: "ExportNamedDeclaration",
|
|
144
|
+
attributes: [],
|
|
118
145
|
specifiers: [],
|
|
119
146
|
source: null,
|
|
120
147
|
declaration: {
|
|
@@ -161,6 +188,7 @@ function getDefaultMDXOptions({
|
|
|
161
188
|
}) {
|
|
162
189
|
const mdxExports = [
|
|
163
190
|
"structuredData",
|
|
191
|
+
"extractedReferences",
|
|
164
192
|
"frontmatter",
|
|
165
193
|
"lastModified",
|
|
166
194
|
...valueToExport
|
|
@@ -192,7 +220,10 @@ function getDefaultMDXOptions({
|
|
|
192
220
|
plugins.remarkStructure,
|
|
193
221
|
remarkStructureOptions
|
|
194
222
|
],
|
|
195
|
-
[
|
|
223
|
+
[
|
|
224
|
+
remarkPostprocess,
|
|
225
|
+
{ injectExports: mdxExports }
|
|
226
|
+
]
|
|
196
227
|
],
|
|
197
228
|
mdxOptions.remarkPlugins
|
|
198
229
|
);
|
|
@@ -213,7 +244,8 @@ function getDefaultMDXOptions({
|
|
|
213
244
|
}
|
|
214
245
|
|
|
215
246
|
// src/mdx-plugins/remark-include.ts
|
|
216
|
-
var
|
|
247
|
+
var import_unified = require("unified");
|
|
248
|
+
var import_unist_util_visit2 = require("unist-util-visit");
|
|
217
249
|
var path = __toESM(require("path"), 1);
|
|
218
250
|
var fs = __toESM(require("fs/promises"), 1);
|
|
219
251
|
|
|
@@ -234,9 +266,13 @@ function fumaMatter(input) {
|
|
|
234
266
|
}
|
|
235
267
|
|
|
236
268
|
// src/mdx-plugins/remark-include.ts
|
|
237
|
-
|
|
269
|
+
var import_remark_parse = __toESM(require("remark-parse"), 1);
|
|
270
|
+
var import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
271
|
+
var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
272
|
+
var baseProcessor = (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading);
|
|
273
|
+
function flattenNode2(node) {
|
|
238
274
|
if ("children" in node)
|
|
239
|
-
return node.children.map((child) =>
|
|
275
|
+
return node.children.map((child) => flattenNode2(child)).join("");
|
|
240
276
|
if ("value" in node) return node.value;
|
|
241
277
|
return "";
|
|
242
278
|
}
|
|
@@ -249,86 +285,96 @@ function parseSpecifier(specifier) {
|
|
|
249
285
|
};
|
|
250
286
|
}
|
|
251
287
|
function extractSection(root, section) {
|
|
288
|
+
let nodes;
|
|
252
289
|
for (const node of root.children) {
|
|
253
290
|
if (node.type === "mdxJsxFlowElement" && node.name === "section" && node.attributes.some(
|
|
254
291
|
(attr) => attr.type === "mdxJsxAttribute" && attr.name === "id" && attr.value === section
|
|
255
292
|
)) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
293
|
+
nodes = node.children;
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
if (node.type === "heading" && node.data?.hProperties?.id === section) {
|
|
297
|
+
nodes = [node];
|
|
298
|
+
continue;
|
|
260
299
|
}
|
|
300
|
+
if (!nodes) continue;
|
|
301
|
+
if (node.type === "heading") break;
|
|
302
|
+
nodes.push(node);
|
|
261
303
|
}
|
|
304
|
+
if (nodes)
|
|
305
|
+
return {
|
|
306
|
+
type: "root",
|
|
307
|
+
children: nodes
|
|
308
|
+
};
|
|
262
309
|
}
|
|
263
310
|
function remarkInclude() {
|
|
264
311
|
const TagName = "include";
|
|
312
|
+
async function embedContent(file, heading, params, data) {
|
|
313
|
+
let content;
|
|
314
|
+
try {
|
|
315
|
+
content = (await fs.readFile(file)).toString();
|
|
316
|
+
} catch (e) {
|
|
317
|
+
throw new Error(
|
|
318
|
+
`failed to read file ${file}
|
|
319
|
+
${e instanceof Error ? e.message : String(e)}`,
|
|
320
|
+
{ cause: e }
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
const ext = path.extname(file);
|
|
324
|
+
data._compiler?.addDependency(file);
|
|
325
|
+
if (params.lang || ext !== ".md" && ext !== ".mdx") {
|
|
326
|
+
const lang = params.lang ?? ext.slice(1);
|
|
327
|
+
return {
|
|
328
|
+
type: "code",
|
|
329
|
+
lang,
|
|
330
|
+
meta: params.meta,
|
|
331
|
+
value: content,
|
|
332
|
+
data: {}
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
const processor = (data._getProcessor ?? getDefaultProcessor)(
|
|
336
|
+
ext === ".mdx" ? "mdx" : "md"
|
|
337
|
+
);
|
|
338
|
+
let parsed = await baseProcessor.run(
|
|
339
|
+
processor.parse(fumaMatter(content).content)
|
|
340
|
+
);
|
|
341
|
+
if (heading) {
|
|
342
|
+
const extracted = extractSection(parsed, heading);
|
|
343
|
+
if (!extracted)
|
|
344
|
+
throw new Error(
|
|
345
|
+
`Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag.`
|
|
346
|
+
);
|
|
347
|
+
parsed = extracted;
|
|
348
|
+
}
|
|
349
|
+
await update(parsed, path.dirname(file), data);
|
|
350
|
+
return parsed;
|
|
351
|
+
}
|
|
265
352
|
async function update(tree, directory, data) {
|
|
266
353
|
const queue = [];
|
|
267
|
-
(0,
|
|
354
|
+
(0, import_unist_util_visit2.visit)(
|
|
268
355
|
tree,
|
|
269
356
|
["mdxJsxFlowElement", "mdxJsxTextElement"],
|
|
270
|
-
(
|
|
271
|
-
|
|
357
|
+
(_node, _, parent) => {
|
|
358
|
+
const node = _node;
|
|
359
|
+
if (node.name !== TagName) return;
|
|
272
360
|
const params = {};
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
params[attr.name] = attr.value;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
specifier = value;
|
|
361
|
+
const specifier = flattenNode2(node);
|
|
362
|
+
if (specifier.length === 0) return "skip";
|
|
363
|
+
for (const attr of node.attributes) {
|
|
364
|
+
if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
|
|
365
|
+
params[attr.name] = attr.value;
|
|
282
366
|
}
|
|
283
367
|
}
|
|
284
|
-
|
|
285
|
-
const
|
|
286
|
-
const targetPath = path.resolve(
|
|
368
|
+
const { file: relativePath, section } = parseSpecifier(specifier);
|
|
369
|
+
const file = path.resolve(
|
|
287
370
|
"cwd" in params ? process.cwd() : directory,
|
|
288
|
-
|
|
371
|
+
relativePath
|
|
289
372
|
);
|
|
290
|
-
const asCode = params.lang || !file.endsWith(".md") && !file.endsWith(".mdx");
|
|
291
373
|
queue.push(
|
|
292
|
-
|
|
293
|
-
data._compiler?.addDependency(targetPath);
|
|
294
|
-
if (asCode) {
|
|
295
|
-
const lang = params.lang ?? path.extname(file).slice(1);
|
|
296
|
-
Object.assign(node, {
|
|
297
|
-
type: "code",
|
|
298
|
-
lang,
|
|
299
|
-
meta: params.meta,
|
|
300
|
-
value: content,
|
|
301
|
-
data: {}
|
|
302
|
-
});
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
const processor = data._processor ? data._processor.getProcessor(
|
|
306
|
-
targetPath.endsWith(".md") ? "md" : "mdx"
|
|
307
|
-
) : this;
|
|
308
|
-
let parsed = processor.parse(fumaMatter(content).content);
|
|
309
|
-
if (section) {
|
|
310
|
-
const extracted = extractSection(parsed, section);
|
|
311
|
-
if (!extracted)
|
|
312
|
-
throw new Error(
|
|
313
|
-
`Cannot find section ${section} in ${file}, make sure you have encapsulated the section in a <section id="${section}"> tag`
|
|
314
|
-
);
|
|
315
|
-
parsed = extracted;
|
|
316
|
-
}
|
|
317
|
-
await update.call(
|
|
318
|
-
processor,
|
|
319
|
-
parsed,
|
|
320
|
-
path.dirname(targetPath),
|
|
321
|
-
data
|
|
322
|
-
);
|
|
374
|
+
embedContent(file, section, params, data).then((replace) => {
|
|
323
375
|
Object.assign(
|
|
324
376
|
parent && parent.type === "paragraph" ? parent : node,
|
|
325
|
-
|
|
326
|
-
);
|
|
327
|
-
}).catch((e) => {
|
|
328
|
-
throw new Error(
|
|
329
|
-
`failed to read file ${targetPath}
|
|
330
|
-
${e instanceof Error ? e.message : String(e)}`,
|
|
331
|
-
{ cause: e }
|
|
377
|
+
replace
|
|
332
378
|
);
|
|
333
379
|
})
|
|
334
380
|
);
|
|
@@ -338,9 +384,14 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
338
384
|
await Promise.all(queue);
|
|
339
385
|
}
|
|
340
386
|
return async (tree, file) => {
|
|
341
|
-
await update
|
|
387
|
+
await update(tree, path.dirname(file.path), file.data);
|
|
342
388
|
};
|
|
343
389
|
}
|
|
390
|
+
function getDefaultProcessor(format) {
|
|
391
|
+
const mdProcessor = (0, import_unified.unified)().use(import_remark_parse.default);
|
|
392
|
+
if (format === "md") return mdProcessor;
|
|
393
|
+
return mdProcessor.use(import_remark_mdx.default);
|
|
394
|
+
}
|
|
344
395
|
|
|
345
396
|
// src/config/zod-3.ts
|
|
346
397
|
var metaSchema2 = import_v3.z.object({
|
package/dist/config/zod-3.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod/v3';
|
|
2
2
|
export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, g as getDefaultMDXOptions } from '../define-DnJzAZrj.cjs';
|
|
3
|
-
export { remarkInclude } from './index.cjs';
|
|
3
|
+
export { Params, remarkInclude } from './index.cjs';
|
|
4
4
|
import '@standard-schema/spec';
|
|
5
5
|
import 'fumadocs-core/mdx-plugins';
|
|
6
6
|
import '@mdx-js/mdx';
|
package/dist/config/zod-3.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod/v3';
|
|
2
2
|
export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, g as getDefaultMDXOptions } from '../define-DnJzAZrj.js';
|
|
3
|
-
export { remarkInclude } from './index.js';
|
|
3
|
+
export { Params, remarkInclude } from './index.js';
|
|
4
4
|
import '@standard-schema/spec';
|
|
5
5
|
import 'fumadocs-core/mdx-plugins';
|
|
6
6
|
import '@mdx-js/mdx';
|
package/dist/config/zod-3.js
CHANGED
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
} from "../chunk-GBMFGEC7.js";
|
|
6
6
|
import {
|
|
7
7
|
getDefaultMDXOptions
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-SMSNZ6N5.js";
|
|
9
9
|
import {
|
|
10
10
|
remarkInclude
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-SVTXMVLQ.js";
|
|
12
12
|
import "../chunk-VWJKRQZR.js";
|
|
13
13
|
|
|
14
14
|
// src/config/zod-3.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
|
|
2
|
-
import { R as Runtime, B as BaseCollectionEntry } from './types-
|
|
2
|
+
import { R as Runtime, B as BaseCollectionEntry } from './types-BmVgoqsr.cjs';
|
|
3
3
|
import '@standard-schema/spec';
|
|
4
4
|
import './define-DnJzAZrj.cjs';
|
|
5
5
|
import 'fumadocs-core/mdx-plugins';
|
|
6
6
|
import '@mdx-js/mdx';
|
|
7
7
|
import 'unified';
|
|
8
8
|
import 'zod';
|
|
9
|
+
import './build-mdx-DnC1jKvn.cjs';
|
|
10
|
+
import 'fumadocs-core/server';
|
|
9
11
|
import 'react';
|
|
10
12
|
import 'mdx/types';
|
|
11
|
-
import 'fumadocs-core/server';
|
|
12
13
|
|
|
13
14
|
declare const _runtime: Runtime;
|
|
14
15
|
declare function createMDXSource<Doc extends PageData & BaseCollectionEntry, Meta extends MetaData & BaseCollectionEntry>(docs: Doc[], meta?: Meta[]): Source<{
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
|
|
2
|
-
import { R as Runtime, B as BaseCollectionEntry } from './types-
|
|
2
|
+
import { R as Runtime, B as BaseCollectionEntry } from './types-WSHJKA8L.js';
|
|
3
3
|
import '@standard-schema/spec';
|
|
4
4
|
import './define-DnJzAZrj.js';
|
|
5
5
|
import 'fumadocs-core/mdx-plugins';
|
|
6
6
|
import '@mdx-js/mdx';
|
|
7
7
|
import 'unified';
|
|
8
8
|
import 'zod';
|
|
9
|
+
import './build-mdx-DnC1jKvn.js';
|
|
10
|
+
import 'fumadocs-core/server';
|
|
9
11
|
import 'react';
|
|
10
12
|
import 'mdx/types';
|
|
11
|
-
import 'fumadocs-core/server';
|
|
12
13
|
|
|
13
14
|
declare const _runtime: Runtime;
|
|
14
15
|
declare function createMDXSource<Doc extends PageData & BaseCollectionEntry, Meta extends MetaData & BaseCollectionEntry>(docs: Doc[], meta?: Meta[]): Source<{
|
package/dist/loader-mdx.cjs
CHANGED
|
@@ -30,15 +30,40 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
-
// src/mdx-plugins/remark-
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
// src/mdx-plugins/remark-postprocess.ts
|
|
34
|
+
function remarkPostprocess({
|
|
35
|
+
injectExports
|
|
36
|
+
}) {
|
|
37
|
+
return (tree, file) => {
|
|
38
|
+
let title;
|
|
39
|
+
const urls = [];
|
|
40
|
+
(0, import_unist_util_visit.visit)(tree, ["heading", "link"], (node) => {
|
|
41
|
+
if (node.type === "heading" && node.depth === 1) {
|
|
42
|
+
title = flattenNode(node);
|
|
43
|
+
}
|
|
44
|
+
if (node.type !== "link") return;
|
|
45
|
+
urls.push({
|
|
46
|
+
href: node.url
|
|
47
|
+
});
|
|
48
|
+
return "skip";
|
|
49
|
+
});
|
|
50
|
+
if (title) {
|
|
51
|
+
file.data.frontmatter ??= {};
|
|
52
|
+
if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
|
|
53
|
+
}
|
|
54
|
+
file.data.extractedReferences = urls;
|
|
55
|
+
for (const name of injectExports) {
|
|
56
|
+
if (!(name in file.data)) continue;
|
|
57
|
+
tree.children.unshift(getMdastExport(name, file.data[name]));
|
|
39
58
|
}
|
|
40
59
|
};
|
|
41
60
|
}
|
|
61
|
+
function flattenNode(node) {
|
|
62
|
+
if ("children" in node)
|
|
63
|
+
return node.children.map((child) => flattenNode(child)).join("");
|
|
64
|
+
if ("value" in node) return node.value;
|
|
65
|
+
return "";
|
|
66
|
+
}
|
|
42
67
|
function getMdastExport(name, value) {
|
|
43
68
|
return {
|
|
44
69
|
type: "mdxjsEsm",
|
|
@@ -50,6 +75,7 @@ function getMdastExport(name, value) {
|
|
|
50
75
|
body: [
|
|
51
76
|
{
|
|
52
77
|
type: "ExportNamedDeclaration",
|
|
78
|
+
attributes: [],
|
|
53
79
|
specifiers: [],
|
|
54
80
|
source: null,
|
|
55
81
|
declaration: {
|
|
@@ -72,10 +98,11 @@ function getMdastExport(name, value) {
|
|
|
72
98
|
}
|
|
73
99
|
};
|
|
74
100
|
}
|
|
75
|
-
var import_estree_util_value_to_estree;
|
|
76
|
-
var
|
|
77
|
-
"src/mdx-plugins/remark-
|
|
101
|
+
var import_unist_util_visit, import_estree_util_value_to_estree;
|
|
102
|
+
var init_remark_postprocess = __esm({
|
|
103
|
+
"src/mdx-plugins/remark-postprocess.ts"() {
|
|
78
104
|
"use strict";
|
|
105
|
+
import_unist_util_visit = require("unist-util-visit");
|
|
79
106
|
import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
80
107
|
}
|
|
81
108
|
});
|
|
@@ -107,6 +134,7 @@ function getDefaultMDXOptions({
|
|
|
107
134
|
}) {
|
|
108
135
|
const mdxExports = [
|
|
109
136
|
"structuredData",
|
|
137
|
+
"extractedReferences",
|
|
110
138
|
"frontmatter",
|
|
111
139
|
"lastModified",
|
|
112
140
|
...valueToExport
|
|
@@ -138,7 +166,10 @@ function getDefaultMDXOptions({
|
|
|
138
166
|
plugins.remarkStructure,
|
|
139
167
|
remarkStructureOptions
|
|
140
168
|
],
|
|
141
|
-
[
|
|
169
|
+
[
|
|
170
|
+
remarkPostprocess,
|
|
171
|
+
{ injectExports: mdxExports }
|
|
172
|
+
]
|
|
142
173
|
],
|
|
143
174
|
mdxOptions.remarkPlugins
|
|
144
175
|
);
|
|
@@ -162,7 +193,7 @@ var init_mdx_options = __esm({
|
|
|
162
193
|
"src/utils/mdx-options.ts"() {
|
|
163
194
|
"use strict";
|
|
164
195
|
plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
|
|
165
|
-
|
|
196
|
+
init_remark_postprocess();
|
|
166
197
|
}
|
|
167
198
|
});
|
|
168
199
|
|
|
@@ -309,7 +340,8 @@ async function getConfigHash(configPath) {
|
|
|
309
340
|
var import_mdx = require("@mdx-js/mdx");
|
|
310
341
|
|
|
311
342
|
// src/mdx-plugins/remark-include.ts
|
|
312
|
-
var
|
|
343
|
+
var import_unified = require("unified");
|
|
344
|
+
var import_unist_util_visit2 = require("unist-util-visit");
|
|
313
345
|
var path2 = __toESM(require("path"), 1);
|
|
314
346
|
var fs2 = __toESM(require("fs/promises"), 1);
|
|
315
347
|
|
|
@@ -330,9 +362,13 @@ function fumaMatter(input) {
|
|
|
330
362
|
}
|
|
331
363
|
|
|
332
364
|
// src/mdx-plugins/remark-include.ts
|
|
333
|
-
|
|
365
|
+
var import_remark_parse = __toESM(require("remark-parse"), 1);
|
|
366
|
+
var import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
367
|
+
var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
368
|
+
var baseProcessor = (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading);
|
|
369
|
+
function flattenNode2(node) {
|
|
334
370
|
if ("children" in node)
|
|
335
|
-
return node.children.map((child) =>
|
|
371
|
+
return node.children.map((child) => flattenNode2(child)).join("");
|
|
336
372
|
if ("value" in node) return node.value;
|
|
337
373
|
return "";
|
|
338
374
|
}
|
|
@@ -345,86 +381,96 @@ function parseSpecifier(specifier) {
|
|
|
345
381
|
};
|
|
346
382
|
}
|
|
347
383
|
function extractSection(root, section) {
|
|
384
|
+
let nodes;
|
|
348
385
|
for (const node of root.children) {
|
|
349
386
|
if (node.type === "mdxJsxFlowElement" && node.name === "section" && node.attributes.some(
|
|
350
387
|
(attr) => attr.type === "mdxJsxAttribute" && attr.name === "id" && attr.value === section
|
|
351
388
|
)) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
children: node.children
|
|
355
|
-
};
|
|
389
|
+
nodes = node.children;
|
|
390
|
+
break;
|
|
356
391
|
}
|
|
392
|
+
if (node.type === "heading" && node.data?.hProperties?.id === section) {
|
|
393
|
+
nodes = [node];
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (!nodes) continue;
|
|
397
|
+
if (node.type === "heading") break;
|
|
398
|
+
nodes.push(node);
|
|
357
399
|
}
|
|
400
|
+
if (nodes)
|
|
401
|
+
return {
|
|
402
|
+
type: "root",
|
|
403
|
+
children: nodes
|
|
404
|
+
};
|
|
358
405
|
}
|
|
359
406
|
function remarkInclude() {
|
|
360
407
|
const TagName = "include";
|
|
408
|
+
async function embedContent(file, heading, params, data) {
|
|
409
|
+
let content;
|
|
410
|
+
try {
|
|
411
|
+
content = (await fs2.readFile(file)).toString();
|
|
412
|
+
} catch (e) {
|
|
413
|
+
throw new Error(
|
|
414
|
+
`failed to read file ${file}
|
|
415
|
+
${e instanceof Error ? e.message : String(e)}`,
|
|
416
|
+
{ cause: e }
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
const ext = path2.extname(file);
|
|
420
|
+
data._compiler?.addDependency(file);
|
|
421
|
+
if (params.lang || ext !== ".md" && ext !== ".mdx") {
|
|
422
|
+
const lang = params.lang ?? ext.slice(1);
|
|
423
|
+
return {
|
|
424
|
+
type: "code",
|
|
425
|
+
lang,
|
|
426
|
+
meta: params.meta,
|
|
427
|
+
value: content,
|
|
428
|
+
data: {}
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
const processor = (data._getProcessor ?? getDefaultProcessor)(
|
|
432
|
+
ext === ".mdx" ? "mdx" : "md"
|
|
433
|
+
);
|
|
434
|
+
let parsed = await baseProcessor.run(
|
|
435
|
+
processor.parse(fumaMatter(content).content)
|
|
436
|
+
);
|
|
437
|
+
if (heading) {
|
|
438
|
+
const extracted = extractSection(parsed, heading);
|
|
439
|
+
if (!extracted)
|
|
440
|
+
throw new Error(
|
|
441
|
+
`Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag.`
|
|
442
|
+
);
|
|
443
|
+
parsed = extracted;
|
|
444
|
+
}
|
|
445
|
+
await update(parsed, path2.dirname(file), data);
|
|
446
|
+
return parsed;
|
|
447
|
+
}
|
|
361
448
|
async function update(tree, directory, data) {
|
|
362
449
|
const queue = [];
|
|
363
|
-
(0,
|
|
450
|
+
(0, import_unist_util_visit2.visit)(
|
|
364
451
|
tree,
|
|
365
452
|
["mdxJsxFlowElement", "mdxJsxTextElement"],
|
|
366
|
-
(
|
|
367
|
-
|
|
453
|
+
(_node, _, parent) => {
|
|
454
|
+
const node = _node;
|
|
455
|
+
if (node.name !== TagName) return;
|
|
368
456
|
const params = {};
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
params[attr.name] = attr.value;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
specifier = value;
|
|
457
|
+
const specifier = flattenNode2(node);
|
|
458
|
+
if (specifier.length === 0) return "skip";
|
|
459
|
+
for (const attr of node.attributes) {
|
|
460
|
+
if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
|
|
461
|
+
params[attr.name] = attr.value;
|
|
378
462
|
}
|
|
379
463
|
}
|
|
380
|
-
|
|
381
|
-
const
|
|
382
|
-
const targetPath = path2.resolve(
|
|
464
|
+
const { file: relativePath, section } = parseSpecifier(specifier);
|
|
465
|
+
const file = path2.resolve(
|
|
383
466
|
"cwd" in params ? process.cwd() : directory,
|
|
384
|
-
|
|
467
|
+
relativePath
|
|
385
468
|
);
|
|
386
|
-
const asCode = params.lang || !file.endsWith(".md") && !file.endsWith(".mdx");
|
|
387
469
|
queue.push(
|
|
388
|
-
|
|
389
|
-
data._compiler?.addDependency(targetPath);
|
|
390
|
-
if (asCode) {
|
|
391
|
-
const lang = params.lang ?? path2.extname(file).slice(1);
|
|
392
|
-
Object.assign(node, {
|
|
393
|
-
type: "code",
|
|
394
|
-
lang,
|
|
395
|
-
meta: params.meta,
|
|
396
|
-
value: content,
|
|
397
|
-
data: {}
|
|
398
|
-
});
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
const processor = data._processor ? data._processor.getProcessor(
|
|
402
|
-
targetPath.endsWith(".md") ? "md" : "mdx"
|
|
403
|
-
) : this;
|
|
404
|
-
let parsed = processor.parse(fumaMatter(content).content);
|
|
405
|
-
if (section) {
|
|
406
|
-
const extracted = extractSection(parsed, section);
|
|
407
|
-
if (!extracted)
|
|
408
|
-
throw new Error(
|
|
409
|
-
`Cannot find section ${section} in ${file}, make sure you have encapsulated the section in a <section id="${section}"> tag`
|
|
410
|
-
);
|
|
411
|
-
parsed = extracted;
|
|
412
|
-
}
|
|
413
|
-
await update.call(
|
|
414
|
-
processor,
|
|
415
|
-
parsed,
|
|
416
|
-
path2.dirname(targetPath),
|
|
417
|
-
data
|
|
418
|
-
);
|
|
470
|
+
embedContent(file, section, params, data).then((replace) => {
|
|
419
471
|
Object.assign(
|
|
420
472
|
parent && parent.type === "paragraph" ? parent : node,
|
|
421
|
-
|
|
422
|
-
);
|
|
423
|
-
}).catch((e) => {
|
|
424
|
-
throw new Error(
|
|
425
|
-
`failed to read file ${targetPath}
|
|
426
|
-
${e instanceof Error ? e.message : String(e)}`,
|
|
427
|
-
{ cause: e }
|
|
473
|
+
replace
|
|
428
474
|
);
|
|
429
475
|
})
|
|
430
476
|
);
|
|
@@ -434,9 +480,14 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
434
480
|
await Promise.all(queue);
|
|
435
481
|
}
|
|
436
482
|
return async (tree, file) => {
|
|
437
|
-
await update
|
|
483
|
+
await update(tree, path2.dirname(file.path), file.data);
|
|
438
484
|
};
|
|
439
485
|
}
|
|
486
|
+
function getDefaultProcessor(format) {
|
|
487
|
+
const mdProcessor = (0, import_unified.unified)().use(import_remark_parse.default);
|
|
488
|
+
if (format === "md") return mdProcessor;
|
|
489
|
+
return mdProcessor.use(import_remark_mdx.default);
|
|
490
|
+
}
|
|
440
491
|
|
|
441
492
|
// src/utils/build-mdx.ts
|
|
442
493
|
var cache2 = /* @__PURE__ */ new Map();
|
|
@@ -465,9 +516,7 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
465
516
|
...data,
|
|
466
517
|
frontmatter,
|
|
467
518
|
_compiler,
|
|
468
|
-
|
|
469
|
-
getProcessor
|
|
470
|
-
}
|
|
519
|
+
_getProcessor: getProcessor
|
|
471
520
|
}
|
|
472
521
|
});
|
|
473
522
|
}
|
|
@@ -559,13 +608,13 @@ async function loader(source, callback) {
|
|
|
559
608
|
if (collection && collection.type !== "doc") {
|
|
560
609
|
collection = void 0;
|
|
561
610
|
}
|
|
562
|
-
let
|
|
611
|
+
let frontmatter = matter.data;
|
|
563
612
|
const mdxOptions = collection?.mdxOptions ?? await config.getDefaultMDXOptions();
|
|
564
613
|
if (collection?.schema) {
|
|
565
614
|
try {
|
|
566
|
-
|
|
615
|
+
frontmatter = await validate(
|
|
567
616
|
collection.schema,
|
|
568
|
-
|
|
617
|
+
frontmatter,
|
|
569
618
|
{
|
|
570
619
|
source,
|
|
571
620
|
path: filePath
|
|
@@ -594,7 +643,7 @@ async function loader(source, callback) {
|
|
|
594
643
|
development: this.mode === "development",
|
|
595
644
|
...mdxOptions,
|
|
596
645
|
filePath,
|
|
597
|
-
frontmatter
|
|
646
|
+
frontmatter,
|
|
598
647
|
data: {
|
|
599
648
|
lastModified: timestamp
|
|
600
649
|
},
|