fumadocs-mdx 14.0.1 → 14.0.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-6UAK5FF5.js → build-mdx-W3233QBZ.js} +1 -1
- package/dist/bun/index.d.ts +1 -1
- package/dist/bun/index.js +5 -5
- package/dist/{chunk-ZY6UZ7NH.js → chunk-6RPNS75C.js} +1 -1
- package/dist/{chunk-7UKSZSPY.js → chunk-ED3ON275.js} +3 -4
- package/dist/{chunk-BEBCWQC7.js → chunk-GB4W3YCZ.js} +1 -1
- package/dist/{chunk-SLY7WXTX.js → chunk-KOPLIEVQ.js} +5 -6
- package/dist/{chunk-MTTISKQJ.js → chunk-LPX7ZO66.js} +1 -1
- package/dist/{chunk-K6HCOGOX.js → chunk-OLL7FM7W.js} +2 -2
- package/dist/{chunk-IQGEFL2B.js → chunk-Q5OSGLJL.js} +1 -1
- package/dist/{chunk-E5DJTSIM.js → chunk-S7KOJHHO.js} +4 -1
- package/dist/{chunk-6NISOLQ6.js → chunk-USWQVJWR.js} +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +1 -1
- package/dist/{core-B9ZoS6sA.d.ts → core-C3QZSdEx.d.ts} +1 -1
- package/dist/{index-CNOvhtOn.d.ts → index-RVIZxMZG.d.ts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/load-from-file-OZ5N7DXU.js +8 -0
- package/dist/next/index.cjs +8 -6
- package/dist/next/index.d.ts +1 -1
- package/dist/next/index.js +5 -5
- package/dist/node/loader.js +3 -3
- package/dist/plugins/index-file.d.ts +1 -1
- package/dist/plugins/index-file.js +1 -1
- package/dist/plugins/json-schema.d.ts +1 -1
- package/dist/plugins/last-modified.d.ts +5 -2
- package/dist/plugins/last-modified.js +10 -3
- package/dist/runtime/browser.d.ts +1 -1
- package/dist/runtime/dynamic.d.ts +1 -1
- package/dist/runtime/dynamic.js +4 -4
- package/dist/runtime/server.d.ts +1 -1
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +7 -7
- package/dist/webpack/mdx.d.ts +2 -2
- package/dist/webpack/mdx.js +4 -4
- package/dist/webpack/meta.d.ts +2 -2
- package/dist/webpack/meta.js +3 -3
- package/package.json +4 -6
- package/dist/bin.cjs +0 -1958
- package/dist/bin.d.cts +0 -1
- package/dist/bun/index.cjs +0 -1147
- package/dist/bun/index.d.cts +0 -25
- package/dist/config/index.cjs +0 -400
- package/dist/config/index.d.cts +0 -18
- package/dist/core-DTuP23zu.d.cts +0 -341
- package/dist/index-BD8Woo4m.d.cts +0 -8
- package/dist/index.cjs +0 -18
- package/dist/index.d.cts +0 -61
- package/dist/load-from-file-5HUQN36V.js +0 -8
- package/dist/next/index.d.cts +0 -33
- package/dist/node/loader.cjs +0 -1200
- package/dist/node/loader.d.cts +0 -5
- package/dist/plugins/index-file.cjs +0 -495
- package/dist/plugins/index-file.d.cts +0 -14
- package/dist/plugins/json-schema.cjs +0 -114
- package/dist/plugins/json-schema.d.cts +0 -31
- package/dist/plugins/last-modified.cjs +0 -110
- package/dist/plugins/last-modified.d.cts +0 -37
- package/dist/runtime/browser.cjs +0 -93
- package/dist/runtime/browser.d.cts +0 -53
- package/dist/runtime/dynamic.cjs +0 -1023
- package/dist/runtime/dynamic.d.cts +0 -27
- package/dist/runtime/server.cjs +0 -176
- package/dist/runtime/server.d.cts +0 -14
- package/dist/runtime/types.cjs +0 -18
- package/dist/runtime/types.d.cts +0 -61
- package/dist/vite/index.cjs +0 -1687
- package/dist/vite/index.d.cts +0 -44
- package/dist/webpack/mdx.cjs +0 -1124
- package/dist/webpack/mdx.d.cts +0 -20
- package/dist/webpack/meta.cjs +0 -684
- package/dist/webpack/meta.d.cts +0 -20
package/dist/runtime/dynamic.cjs
DELETED
|
@@ -1,1023 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/runtime/dynamic.ts
|
|
31
|
-
var dynamic_exports = {};
|
|
32
|
-
__export(dynamic_exports, {
|
|
33
|
-
dynamic: () => dynamic
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(dynamic_exports);
|
|
36
|
-
|
|
37
|
-
// src/config/build.ts
|
|
38
|
-
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
39
|
-
|
|
40
|
-
// src/config/preset.ts
|
|
41
|
-
function pluginOption(def, options = []) {
|
|
42
|
-
const list = def(Array.isArray(options) ? options : []).filter(
|
|
43
|
-
Boolean
|
|
44
|
-
);
|
|
45
|
-
if (typeof options === "function") {
|
|
46
|
-
return options(list);
|
|
47
|
-
}
|
|
48
|
-
return list;
|
|
49
|
-
}
|
|
50
|
-
function applyMdxPreset(options = {}) {
|
|
51
|
-
return async (environment = "bundler") => {
|
|
52
|
-
if (options.preset === "minimal") return options;
|
|
53
|
-
const plugins = await import("fumadocs-core/mdx-plugins");
|
|
54
|
-
const {
|
|
55
|
-
valueToExport = [],
|
|
56
|
-
rehypeCodeOptions,
|
|
57
|
-
remarkImageOptions,
|
|
58
|
-
remarkHeadingOptions,
|
|
59
|
-
remarkStructureOptions,
|
|
60
|
-
remarkCodeTabOptions,
|
|
61
|
-
remarkNpmOptions,
|
|
62
|
-
...mdxOptions
|
|
63
|
-
} = options;
|
|
64
|
-
const remarkPlugins = pluginOption(
|
|
65
|
-
(v) => [
|
|
66
|
-
plugins.remarkGfm,
|
|
67
|
-
[
|
|
68
|
-
plugins.remarkHeading,
|
|
69
|
-
{
|
|
70
|
-
generateToc: false,
|
|
71
|
-
...remarkHeadingOptions
|
|
72
|
-
}
|
|
73
|
-
],
|
|
74
|
-
remarkImageOptions !== false && [
|
|
75
|
-
plugins.remarkImage,
|
|
76
|
-
{
|
|
77
|
-
...remarkImageOptions,
|
|
78
|
-
useImport: remarkImageOptions?.useImport ?? environment === "bundler"
|
|
79
|
-
}
|
|
80
|
-
],
|
|
81
|
-
"remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
|
|
82
|
-
plugins.remarkCodeTab,
|
|
83
|
-
remarkCodeTabOptions
|
|
84
|
-
],
|
|
85
|
-
"remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
|
|
86
|
-
...v,
|
|
87
|
-
remarkStructureOptions !== false && [
|
|
88
|
-
plugins.remarkStructure,
|
|
89
|
-
remarkStructureOptions
|
|
90
|
-
],
|
|
91
|
-
valueToExport.length > 0 && (() => {
|
|
92
|
-
return (_, file) => {
|
|
93
|
-
file.data["mdx-export"] ??= [];
|
|
94
|
-
for (const name of valueToExport) {
|
|
95
|
-
if (!(name in file.data)) continue;
|
|
96
|
-
file.data["mdx-export"].push({
|
|
97
|
-
name,
|
|
98
|
-
value: file.data[name]
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
})
|
|
103
|
-
],
|
|
104
|
-
mdxOptions.remarkPlugins
|
|
105
|
-
);
|
|
106
|
-
const rehypePlugins = pluginOption(
|
|
107
|
-
(v) => [
|
|
108
|
-
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
|
109
|
-
...v,
|
|
110
|
-
plugins.rehypeToc
|
|
111
|
-
],
|
|
112
|
-
mdxOptions.rehypePlugins
|
|
113
|
-
);
|
|
114
|
-
return {
|
|
115
|
-
...mdxOptions,
|
|
116
|
-
outputFormat: environment === "runtime" ? "function-body" : mdxOptions.outputFormat,
|
|
117
|
-
remarkPlugins,
|
|
118
|
-
rehypePlugins
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// src/config/build.ts
|
|
124
|
-
var SupportedFormats = {
|
|
125
|
-
doc: ["mdx", "md"],
|
|
126
|
-
meta: ["json", "yaml"]
|
|
127
|
-
};
|
|
128
|
-
function buildCollection(name, config) {
|
|
129
|
-
if (config.type === "docs") {
|
|
130
|
-
return {
|
|
131
|
-
...config,
|
|
132
|
-
name,
|
|
133
|
-
meta: buildPrimitiveCollection(name, config.meta),
|
|
134
|
-
docs: buildPrimitiveCollection(name, config.docs),
|
|
135
|
-
hasFile(filePath) {
|
|
136
|
-
return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
return buildPrimitiveCollection(name, config);
|
|
141
|
-
}
|
|
142
|
-
function buildPrimitiveCollection(name, { files, ...config }) {
|
|
143
|
-
const supportedFormats = SupportedFormats[config.type];
|
|
144
|
-
const patterns = files ?? [`**/*.{${supportedFormats.join(",")}}`];
|
|
145
|
-
let matchers;
|
|
146
|
-
return {
|
|
147
|
-
...config,
|
|
148
|
-
name,
|
|
149
|
-
patterns,
|
|
150
|
-
isFileSupported(filePath) {
|
|
151
|
-
return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
|
|
152
|
-
},
|
|
153
|
-
hasFile(filePath) {
|
|
154
|
-
matchers ??= (Array.isArray(config.dir) ? config.dir : [config.dir]).map(
|
|
155
|
-
(dir) => (0, import_picomatch.default)(patterns, {
|
|
156
|
-
cwd: dir
|
|
157
|
-
})
|
|
158
|
-
);
|
|
159
|
-
return this.isFileSupported(filePath) && matchers.some((matcher) => matcher(filePath));
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
function buildConfig(config) {
|
|
164
|
-
const collections = /* @__PURE__ */ new Map();
|
|
165
|
-
const loaded = {};
|
|
166
|
-
for (const [k, v] of Object.entries(config)) {
|
|
167
|
-
if (!v) {
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
if (typeof v === "object" && "type" in v) {
|
|
171
|
-
if (v.type === "docs") {
|
|
172
|
-
collections.set(k, buildCollection(k, v));
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
if (v.type === "doc" || v.type === "meta") {
|
|
176
|
-
collections.set(
|
|
177
|
-
k,
|
|
178
|
-
buildCollection(k, v)
|
|
179
|
-
);
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
if (k === "default" && v) {
|
|
184
|
-
Object.assign(loaded, v);
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
throw new Error(
|
|
188
|
-
`Unknown export "${k}", you can only export collections from source configuration file.`
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
const mdxOptionsCache = /* @__PURE__ */ new Map();
|
|
192
|
-
return {
|
|
193
|
-
global: loaded,
|
|
194
|
-
collectionList: Array.from(collections.values()),
|
|
195
|
-
getCollection(name) {
|
|
196
|
-
return collections.get(name);
|
|
197
|
-
},
|
|
198
|
-
getMDXOptions(collection, environment = "bundler") {
|
|
199
|
-
const key = collection ? `${environment}:${collection.name}` : environment;
|
|
200
|
-
const cached = mdxOptionsCache.get(key);
|
|
201
|
-
if (cached) return cached;
|
|
202
|
-
let result;
|
|
203
|
-
if (collection?.mdxOptions) {
|
|
204
|
-
const optionsFn = collection.mdxOptions;
|
|
205
|
-
result = typeof optionsFn === "function" ? optionsFn(environment) : optionsFn;
|
|
206
|
-
} else {
|
|
207
|
-
result = (async () => {
|
|
208
|
-
const optionsFn = this.global.mdxOptions;
|
|
209
|
-
const options = typeof optionsFn === "function" ? await optionsFn() : optionsFn;
|
|
210
|
-
return applyMdxPreset(options)(environment);
|
|
211
|
-
})();
|
|
212
|
-
}
|
|
213
|
-
mdxOptionsCache.set(key, result);
|
|
214
|
-
return result;
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// src/loaders/mdx/build-mdx.ts
|
|
220
|
-
var import_mdx = require("@mdx-js/mdx");
|
|
221
|
-
var import_vfile = require("vfile");
|
|
222
|
-
|
|
223
|
-
// src/loaders/mdx/remark-include.ts
|
|
224
|
-
var import_unified = require("unified");
|
|
225
|
-
var import_unist_util_visit2 = require("unist-util-visit");
|
|
226
|
-
var path = __toESM(require("path"), 1);
|
|
227
|
-
var fs = __toESM(require("fs/promises"), 1);
|
|
228
|
-
|
|
229
|
-
// src/utils/fuma-matter.ts
|
|
230
|
-
var import_js_yaml = require("js-yaml");
|
|
231
|
-
var regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
|
|
232
|
-
function fumaMatter(input) {
|
|
233
|
-
const output = { matter: "", data: {}, content: input };
|
|
234
|
-
const match = regex.exec(input);
|
|
235
|
-
if (!match) {
|
|
236
|
-
return output;
|
|
237
|
-
}
|
|
238
|
-
output.matter = match[0];
|
|
239
|
-
output.content = input.slice(match[0].length);
|
|
240
|
-
const loaded = (0, import_js_yaml.load)(match[1]);
|
|
241
|
-
output.data = loaded ?? {};
|
|
242
|
-
return output;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// src/loaders/mdx/remark-include.ts
|
|
246
|
-
var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
247
|
-
|
|
248
|
-
// src/loaders/mdx/remark-unravel.ts
|
|
249
|
-
var import_unist_util_visit = require("unist-util-visit");
|
|
250
|
-
function remarkMarkAndUnravel() {
|
|
251
|
-
return (tree) => {
|
|
252
|
-
(0, import_unist_util_visit.visit)(tree, function(node, index, parent) {
|
|
253
|
-
let offset = -1;
|
|
254
|
-
let all = true;
|
|
255
|
-
let oneOrMore = false;
|
|
256
|
-
if (parent && typeof index === "number" && node.type === "paragraph") {
|
|
257
|
-
const children = node.children;
|
|
258
|
-
while (++offset < children.length) {
|
|
259
|
-
const child = children[offset];
|
|
260
|
-
if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
|
|
261
|
-
oneOrMore = true;
|
|
262
|
-
} else if (child.type === "text" && child.value.trim().length === 0) {
|
|
263
|
-
} else {
|
|
264
|
-
all = false;
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
if (all && oneOrMore) {
|
|
269
|
-
offset = -1;
|
|
270
|
-
const newChildren = [];
|
|
271
|
-
while (++offset < children.length) {
|
|
272
|
-
const child = children[offset];
|
|
273
|
-
if (child.type === "mdxJsxTextElement") {
|
|
274
|
-
child.type = "mdxJsxFlowElement";
|
|
275
|
-
}
|
|
276
|
-
if (child.type === "mdxTextExpression") {
|
|
277
|
-
child.type = "mdxFlowExpression";
|
|
278
|
-
}
|
|
279
|
-
if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
|
|
280
|
-
} else {
|
|
281
|
-
newChildren.push(child);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
parent.children.splice(index, 1, ...newChildren);
|
|
285
|
-
return index;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// src/loaders/mdx/mdast-utils.ts
|
|
293
|
-
function flattenNode(node) {
|
|
294
|
-
if ("children" in node)
|
|
295
|
-
return node.children.map((child) => flattenNode(child)).join("");
|
|
296
|
-
if ("value" in node) return node.value;
|
|
297
|
-
return "";
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// src/loaders/mdx/remark-include.ts
|
|
301
|
-
var ElementLikeTypes = [
|
|
302
|
-
"mdxJsxFlowElement",
|
|
303
|
-
"mdxJsxTextElement",
|
|
304
|
-
"containerDirective",
|
|
305
|
-
"textDirective",
|
|
306
|
-
"leafDirective"
|
|
307
|
-
];
|
|
308
|
-
function isElementLike(node) {
|
|
309
|
-
return ElementLikeTypes.includes(node.type);
|
|
310
|
-
}
|
|
311
|
-
function parseElementAttributes(element) {
|
|
312
|
-
if (Array.isArray(element.attributes)) {
|
|
313
|
-
const attributes = {};
|
|
314
|
-
for (const attr of element.attributes) {
|
|
315
|
-
if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
|
|
316
|
-
attributes[attr.name] = attr.value;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return attributes;
|
|
320
|
-
}
|
|
321
|
-
return element.attributes ?? {};
|
|
322
|
-
}
|
|
323
|
-
function parseSpecifier(specifier) {
|
|
324
|
-
const idx = specifier.lastIndexOf("#");
|
|
325
|
-
if (idx === -1) return { file: specifier };
|
|
326
|
-
return {
|
|
327
|
-
file: specifier.slice(0, idx),
|
|
328
|
-
section: specifier.slice(idx + 1)
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
function extractSection(root, section) {
|
|
332
|
-
let nodes;
|
|
333
|
-
let capturingHeadingContent = false;
|
|
334
|
-
(0, import_unist_util_visit2.visit)(root, (node) => {
|
|
335
|
-
if (node.type === "heading") {
|
|
336
|
-
if (capturingHeadingContent) {
|
|
337
|
-
return false;
|
|
338
|
-
}
|
|
339
|
-
if (node.data?.hProperties?.id === section) {
|
|
340
|
-
capturingHeadingContent = true;
|
|
341
|
-
nodes = [node];
|
|
342
|
-
return "skip";
|
|
343
|
-
}
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
if (capturingHeadingContent) {
|
|
347
|
-
nodes?.push(node);
|
|
348
|
-
return "skip";
|
|
349
|
-
}
|
|
350
|
-
if (isElementLike(node) && node.name === "section") {
|
|
351
|
-
const attributes = parseElementAttributes(node);
|
|
352
|
-
if (attributes.id === section) {
|
|
353
|
-
nodes = node.children;
|
|
354
|
-
return false;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
if (nodes)
|
|
359
|
-
return {
|
|
360
|
-
type: "root",
|
|
361
|
-
children: nodes
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
function remarkInclude() {
|
|
365
|
-
const TagName = "include";
|
|
366
|
-
const embedContent = async (file, heading, params, data) => {
|
|
367
|
-
let content;
|
|
368
|
-
try {
|
|
369
|
-
content = (await fs.readFile(file)).toString();
|
|
370
|
-
} catch (e) {
|
|
371
|
-
throw new Error(
|
|
372
|
-
`failed to read file ${file}
|
|
373
|
-
${e instanceof Error ? e.message : String(e)}`,
|
|
374
|
-
{ cause: e }
|
|
375
|
-
);
|
|
376
|
-
}
|
|
377
|
-
const ext = path.extname(file);
|
|
378
|
-
data._compiler?.addDependency(file);
|
|
379
|
-
if (params.lang || ext !== ".md" && ext !== ".mdx") {
|
|
380
|
-
const lang = params.lang ?? ext.slice(1);
|
|
381
|
-
return {
|
|
382
|
-
type: "code",
|
|
383
|
-
lang,
|
|
384
|
-
meta: params.meta,
|
|
385
|
-
value: content,
|
|
386
|
-
data: {}
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
const parser = data._getProcessor ? data._getProcessor(ext === ".mdx" ? "mdx" : "md") : this;
|
|
390
|
-
const parsed = fumaMatter(content);
|
|
391
|
-
let mdast = parser.parse({
|
|
392
|
-
path: file,
|
|
393
|
-
value: parsed.content,
|
|
394
|
-
data: { frontmatter: parsed.data }
|
|
395
|
-
});
|
|
396
|
-
const baseProcessor = (0, import_unified.unified)().use(remarkMarkAndUnravel);
|
|
397
|
-
if (heading) {
|
|
398
|
-
const extracted = extractSection(
|
|
399
|
-
await baseProcessor.use(import_mdx_plugins.remarkHeading).run(mdast),
|
|
400
|
-
heading
|
|
401
|
-
);
|
|
402
|
-
if (!extracted)
|
|
403
|
-
throw new Error(
|
|
404
|
-
`Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag, or a :::section directive with remark-directive configured.`
|
|
405
|
-
);
|
|
406
|
-
mdast = extracted;
|
|
407
|
-
} else {
|
|
408
|
-
mdast = await baseProcessor.run(mdast);
|
|
409
|
-
}
|
|
410
|
-
await update(mdast, path.dirname(file), data);
|
|
411
|
-
return mdast;
|
|
412
|
-
};
|
|
413
|
-
async function update(tree, directory, data) {
|
|
414
|
-
const queue = [];
|
|
415
|
-
(0, import_unist_util_visit2.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
|
|
416
|
-
const node = _node;
|
|
417
|
-
if (node.name !== TagName) return;
|
|
418
|
-
const specifier = flattenNode(node);
|
|
419
|
-
if (specifier.length === 0) return "skip";
|
|
420
|
-
const attributes = parseElementAttributes(node);
|
|
421
|
-
const { file: relativePath, section } = parseSpecifier(specifier);
|
|
422
|
-
const file = path.resolve(
|
|
423
|
-
"cwd" in attributes ? process.cwd() : directory,
|
|
424
|
-
relativePath
|
|
425
|
-
);
|
|
426
|
-
queue.push(
|
|
427
|
-
embedContent(file, section, attributes, data).then((replace) => {
|
|
428
|
-
Object.assign(
|
|
429
|
-
parent && parent.type === "paragraph" ? parent : node,
|
|
430
|
-
replace
|
|
431
|
-
);
|
|
432
|
-
})
|
|
433
|
-
);
|
|
434
|
-
return "skip";
|
|
435
|
-
});
|
|
436
|
-
await Promise.all(queue);
|
|
437
|
-
}
|
|
438
|
-
return async (tree, file) => {
|
|
439
|
-
await update(tree, path.dirname(file.path), file.data);
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
// src/loaders/mdx/remark-postprocess.ts
|
|
444
|
-
var import_unist_util_visit3 = require("unist-util-visit");
|
|
445
|
-
var import_mdast_util_to_markdown = require("mdast-util-to-markdown");
|
|
446
|
-
var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
447
|
-
var import_unist_util_remove_position = require("unist-util-remove-position");
|
|
448
|
-
var import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
449
|
-
function remarkPostprocess({
|
|
450
|
-
_format,
|
|
451
|
-
includeProcessedMarkdown = false,
|
|
452
|
-
includeMDAST = false,
|
|
453
|
-
extractLinkReferences = false,
|
|
454
|
-
valueToExport = []
|
|
455
|
-
}) {
|
|
456
|
-
let _stringifyProcessor;
|
|
457
|
-
const getStringifyProcessor = () => {
|
|
458
|
-
return _stringifyProcessor ??= _format === "mdx" ? this : (
|
|
459
|
-
// force Markdown processor to stringify MDX nodes
|
|
460
|
-
this().use(import_remark_mdx.default).freeze()
|
|
461
|
-
);
|
|
462
|
-
};
|
|
463
|
-
return (tree, file) => {
|
|
464
|
-
const frontmatter = file.data.frontmatter ??= {};
|
|
465
|
-
if (!frontmatter.title) {
|
|
466
|
-
(0, import_unist_util_visit3.visit)(tree, "heading", (node) => {
|
|
467
|
-
if (node.depth === 1) {
|
|
468
|
-
frontmatter.title = flattenNode(node);
|
|
469
|
-
return false;
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
file.data["mdx-export"] ??= [];
|
|
474
|
-
if (extractLinkReferences) {
|
|
475
|
-
const urls = [];
|
|
476
|
-
(0, import_unist_util_visit3.visit)(tree, "link", (node) => {
|
|
477
|
-
urls.push({
|
|
478
|
-
href: node.url
|
|
479
|
-
});
|
|
480
|
-
return "skip";
|
|
481
|
-
});
|
|
482
|
-
file.data["mdx-export"].push({
|
|
483
|
-
name: "extractedReferences",
|
|
484
|
-
value: urls
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
if (includeProcessedMarkdown) {
|
|
488
|
-
const processor = getStringifyProcessor();
|
|
489
|
-
const markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
|
|
490
|
-
...processor.data("settings"),
|
|
491
|
-
// from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
|
|
492
|
-
extensions: processor.data("toMarkdownExtensions") || []
|
|
493
|
-
});
|
|
494
|
-
file.data["mdx-export"].push({
|
|
495
|
-
name: "_markdown",
|
|
496
|
-
value: markdown
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
if (includeMDAST) {
|
|
500
|
-
const options = includeMDAST === true ? {} : includeMDAST;
|
|
501
|
-
const mdast = JSON.stringify(
|
|
502
|
-
options.removePosition ? (0, import_unist_util_remove_position.removePosition)(structuredClone(tree)) : tree
|
|
503
|
-
);
|
|
504
|
-
file.data["mdx-export"].push({
|
|
505
|
-
name: "_mdast",
|
|
506
|
-
value: mdast
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
for (const { name, value } of file.data["mdx-export"]) {
|
|
510
|
-
tree.children.unshift(getMdastExport(name, value));
|
|
511
|
-
}
|
|
512
|
-
file.data["mdx-export"] = [];
|
|
513
|
-
for (const name of valueToExport) {
|
|
514
|
-
if (!(name in file.data)) continue;
|
|
515
|
-
tree.children.unshift(getMdastExport(name, file.data[name]));
|
|
516
|
-
}
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
function getMdastExport(name, value) {
|
|
520
|
-
return {
|
|
521
|
-
type: "mdxjsEsm",
|
|
522
|
-
value: "",
|
|
523
|
-
data: {
|
|
524
|
-
estree: {
|
|
525
|
-
type: "Program",
|
|
526
|
-
sourceType: "module",
|
|
527
|
-
body: [
|
|
528
|
-
{
|
|
529
|
-
type: "ExportNamedDeclaration",
|
|
530
|
-
attributes: [],
|
|
531
|
-
specifiers: [],
|
|
532
|
-
source: null,
|
|
533
|
-
declaration: {
|
|
534
|
-
type: "VariableDeclaration",
|
|
535
|
-
kind: "let",
|
|
536
|
-
declarations: [
|
|
537
|
-
{
|
|
538
|
-
type: "VariableDeclarator",
|
|
539
|
-
id: {
|
|
540
|
-
type: "Identifier",
|
|
541
|
-
name
|
|
542
|
-
},
|
|
543
|
-
init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
|
|
544
|
-
}
|
|
545
|
-
]
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
]
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
// src/loaders/mdx/build-mdx.ts
|
|
555
|
-
async function buildMDX(core, collection, {
|
|
556
|
-
filePath,
|
|
557
|
-
frontmatter,
|
|
558
|
-
source,
|
|
559
|
-
_compiler,
|
|
560
|
-
environment,
|
|
561
|
-
isDevelopment
|
|
562
|
-
}) {
|
|
563
|
-
const mdxOptions = await core.getConfig().getMDXOptions(collection, environment);
|
|
564
|
-
function getProcessor(format) {
|
|
565
|
-
const cache = core.cache;
|
|
566
|
-
const key = `build-mdx:${collection?.name ?? "global"}:${format}`;
|
|
567
|
-
let processor = cache.get(key);
|
|
568
|
-
if (!processor) {
|
|
569
|
-
const postprocessOptions = {
|
|
570
|
-
_format: format,
|
|
571
|
-
...collection?.postprocess,
|
|
572
|
-
valueToExport: [
|
|
573
|
-
...collection?.postprocess?.valueToExport ?? [],
|
|
574
|
-
"structuredData",
|
|
575
|
-
"frontmatter"
|
|
576
|
-
]
|
|
577
|
-
};
|
|
578
|
-
processor = (0, import_mdx.createProcessor)({
|
|
579
|
-
outputFormat: "program",
|
|
580
|
-
development: isDevelopment,
|
|
581
|
-
...mdxOptions,
|
|
582
|
-
remarkPlugins: [
|
|
583
|
-
remarkInclude,
|
|
584
|
-
...mdxOptions.remarkPlugins ?? [],
|
|
585
|
-
[remarkPostprocess, postprocessOptions]
|
|
586
|
-
],
|
|
587
|
-
format
|
|
588
|
-
});
|
|
589
|
-
cache.set(key, processor);
|
|
590
|
-
}
|
|
591
|
-
return processor;
|
|
592
|
-
}
|
|
593
|
-
let vfile = new import_vfile.VFile({
|
|
594
|
-
value: source,
|
|
595
|
-
path: filePath,
|
|
596
|
-
data: { frontmatter, _compiler, _getProcessor: getProcessor }
|
|
597
|
-
});
|
|
598
|
-
if (collection) {
|
|
599
|
-
vfile = await core.transformVFile({ collection, filePath, source }, vfile);
|
|
600
|
-
}
|
|
601
|
-
return getProcessor(filePath.endsWith(".mdx") ? "mdx" : "md").process(vfile);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
// src/runtime/dynamic.ts
|
|
605
|
-
var import_client = require("@fumadocs/mdx-remote/client");
|
|
606
|
-
var import_node_url = require("url");
|
|
607
|
-
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
608
|
-
|
|
609
|
-
// src/runtime/server.ts
|
|
610
|
-
var path2 = __toESM(require("path"), 1);
|
|
611
|
-
function server(options = {}) {
|
|
612
|
-
const { doc: { passthroughs: docPassthroughs = [] } = {} } = options;
|
|
613
|
-
function fileInfo(file, base) {
|
|
614
|
-
if (file.startsWith("./")) {
|
|
615
|
-
file = file.slice(2);
|
|
616
|
-
}
|
|
617
|
-
return {
|
|
618
|
-
path: file,
|
|
619
|
-
fullPath: path2.join(base, file)
|
|
620
|
-
};
|
|
621
|
-
}
|
|
622
|
-
function mapDocData(entry) {
|
|
623
|
-
const data = {
|
|
624
|
-
body: entry.default,
|
|
625
|
-
toc: entry.toc,
|
|
626
|
-
structuredData: entry.structuredData,
|
|
627
|
-
_exports: entry
|
|
628
|
-
};
|
|
629
|
-
for (const key of docPassthroughs) {
|
|
630
|
-
data[key] = entry[key];
|
|
631
|
-
}
|
|
632
|
-
return data;
|
|
633
|
-
}
|
|
634
|
-
return {
|
|
635
|
-
async doc(_name, base, glob2) {
|
|
636
|
-
const out = await Promise.all(
|
|
637
|
-
Object.entries(glob2).map(async ([k, v]) => {
|
|
638
|
-
const data = typeof v === "function" ? await v() : v;
|
|
639
|
-
return {
|
|
640
|
-
...mapDocData(data),
|
|
641
|
-
...data.frontmatter,
|
|
642
|
-
...createDocMethods(fileInfo(k, base), () => data)
|
|
643
|
-
};
|
|
644
|
-
})
|
|
645
|
-
);
|
|
646
|
-
return out;
|
|
647
|
-
},
|
|
648
|
-
async docLazy(_name, base, head, body) {
|
|
649
|
-
const out = await Promise.all(
|
|
650
|
-
Object.entries(head).map(async ([k, v]) => {
|
|
651
|
-
const data = typeof v === "function" ? await v() : v;
|
|
652
|
-
const content = body[k];
|
|
653
|
-
return {
|
|
654
|
-
...data,
|
|
655
|
-
...createDocMethods(fileInfo(k, base), content),
|
|
656
|
-
async load() {
|
|
657
|
-
return mapDocData(await content());
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
})
|
|
661
|
-
);
|
|
662
|
-
return out;
|
|
663
|
-
},
|
|
664
|
-
async meta(_name, base, glob2) {
|
|
665
|
-
const out = await Promise.all(
|
|
666
|
-
Object.entries(glob2).map(async ([k, v]) => {
|
|
667
|
-
const data = typeof v === "function" ? await v() : v;
|
|
668
|
-
return {
|
|
669
|
-
info: fileInfo(k, base),
|
|
670
|
-
...data
|
|
671
|
-
};
|
|
672
|
-
})
|
|
673
|
-
);
|
|
674
|
-
return out;
|
|
675
|
-
},
|
|
676
|
-
async docs(name, base, metaGlob, docGlob) {
|
|
677
|
-
const entry = {
|
|
678
|
-
docs: await this.doc(name, base, docGlob),
|
|
679
|
-
meta: await this.meta(name, base, metaGlob),
|
|
680
|
-
toFumadocsSource() {
|
|
681
|
-
return toFumadocsSource(this.docs, this.meta);
|
|
682
|
-
}
|
|
683
|
-
};
|
|
684
|
-
return entry;
|
|
685
|
-
},
|
|
686
|
-
async docsLazy(name, base, metaGlob, docHeadGlob, docBodyGlob) {
|
|
687
|
-
const entry = {
|
|
688
|
-
docs: await this.docLazy(name, base, docHeadGlob, docBodyGlob),
|
|
689
|
-
meta: await this.meta(name, base, metaGlob),
|
|
690
|
-
toFumadocsSource() {
|
|
691
|
-
return toFumadocsSource(this.docs, this.meta);
|
|
692
|
-
}
|
|
693
|
-
};
|
|
694
|
-
return entry;
|
|
695
|
-
}
|
|
696
|
-
};
|
|
697
|
-
}
|
|
698
|
-
function toFumadocsSource(pages, metas) {
|
|
699
|
-
const files = [];
|
|
700
|
-
for (const entry of pages) {
|
|
701
|
-
files.push({
|
|
702
|
-
type: "page",
|
|
703
|
-
path: entry.info.path,
|
|
704
|
-
absolutePath: entry.info.fullPath,
|
|
705
|
-
data: entry
|
|
706
|
-
});
|
|
707
|
-
}
|
|
708
|
-
for (const entry of metas) {
|
|
709
|
-
files.push({
|
|
710
|
-
type: "meta",
|
|
711
|
-
path: entry.info.path,
|
|
712
|
-
absolutePath: entry.info.fullPath,
|
|
713
|
-
data: entry
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
return {
|
|
717
|
-
files
|
|
718
|
-
};
|
|
719
|
-
}
|
|
720
|
-
function createDocMethods(info, load2) {
|
|
721
|
-
return {
|
|
722
|
-
info,
|
|
723
|
-
async getText(type) {
|
|
724
|
-
if (type === "raw") {
|
|
725
|
-
const fs4 = await import("fs/promises");
|
|
726
|
-
return (await fs4.readFile(info.fullPath)).toString();
|
|
727
|
-
}
|
|
728
|
-
const data = await load2();
|
|
729
|
-
if (typeof data._markdown !== "string")
|
|
730
|
-
throw new Error(
|
|
731
|
-
"getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
|
|
732
|
-
);
|
|
733
|
-
return data._markdown;
|
|
734
|
-
},
|
|
735
|
-
async getMDAST() {
|
|
736
|
-
const data = await load2();
|
|
737
|
-
if (!data._mdast)
|
|
738
|
-
throw new Error(
|
|
739
|
-
"getMDAST() requires `includeMDAST` to be enabled in your collection config."
|
|
740
|
-
);
|
|
741
|
-
return JSON.parse(data._mdast);
|
|
742
|
-
}
|
|
743
|
-
};
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
// src/core.ts
|
|
747
|
-
var import_node_path2 = __toESM(require("path"), 1);
|
|
748
|
-
var import_promises = __toESM(require("fs/promises"), 1);
|
|
749
|
-
|
|
750
|
-
// src/utils/validation.ts
|
|
751
|
-
var ValidationError = class extends Error {
|
|
752
|
-
constructor(message, issues) {
|
|
753
|
-
super(
|
|
754
|
-
`${message}:
|
|
755
|
-
${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
|
|
756
|
-
);
|
|
757
|
-
this.title = message;
|
|
758
|
-
this.issues = issues;
|
|
759
|
-
}
|
|
760
|
-
async toStringFormatted() {
|
|
761
|
-
const picocolors = await import("picocolors");
|
|
762
|
-
return [
|
|
763
|
-
picocolors.bold(`[MDX] ${this.title}:`),
|
|
764
|
-
...this.issues.map(
|
|
765
|
-
(issue) => picocolors.redBright(
|
|
766
|
-
`- ${picocolors.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
|
|
767
|
-
)
|
|
768
|
-
)
|
|
769
|
-
].join("\n");
|
|
770
|
-
}
|
|
771
|
-
};
|
|
772
|
-
async function validate(schema, data, context, errorMessage) {
|
|
773
|
-
if (typeof schema === "function" && !("~standard" in schema)) {
|
|
774
|
-
schema = schema(context);
|
|
775
|
-
}
|
|
776
|
-
if ("~standard" in schema) {
|
|
777
|
-
const result = await schema["~standard"].validate(
|
|
778
|
-
data
|
|
779
|
-
);
|
|
780
|
-
if (result.issues) {
|
|
781
|
-
throw new ValidationError(errorMessage, result.issues);
|
|
782
|
-
}
|
|
783
|
-
return result.value;
|
|
784
|
-
}
|
|
785
|
-
return data;
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
// src/utils/codegen.ts
|
|
789
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
790
|
-
var import_tinyglobby = require("tinyglobby");
|
|
791
|
-
function ident(code, tab = 1) {
|
|
792
|
-
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
// src/core.ts
|
|
796
|
-
async function getPlugins(pluginOptions) {
|
|
797
|
-
const plugins = [];
|
|
798
|
-
for await (const option of pluginOptions) {
|
|
799
|
-
if (!option) continue;
|
|
800
|
-
if (Array.isArray(option)) plugins.push(...await getPlugins(option));
|
|
801
|
-
else plugins.push(option);
|
|
802
|
-
}
|
|
803
|
-
return plugins;
|
|
804
|
-
}
|
|
805
|
-
function createCore(options, defaultPlugins = []) {
|
|
806
|
-
let config;
|
|
807
|
-
let plugins;
|
|
808
|
-
async function transformMetadata({
|
|
809
|
-
collection,
|
|
810
|
-
filePath,
|
|
811
|
-
source
|
|
812
|
-
}, data) {
|
|
813
|
-
if (collection.schema) {
|
|
814
|
-
data = await validate(
|
|
815
|
-
collection.schema,
|
|
816
|
-
data,
|
|
817
|
-
{ path: filePath, source },
|
|
818
|
-
collection.type === "doc" ? `invalid frontmatter in ${filePath}` : `invalid data in ${filePath}`
|
|
819
|
-
);
|
|
820
|
-
}
|
|
821
|
-
return data;
|
|
822
|
-
}
|
|
823
|
-
const core = {
|
|
824
|
-
/**
|
|
825
|
-
* Convenient cache store, reset when config changes
|
|
826
|
-
*/
|
|
827
|
-
cache: /* @__PURE__ */ new Map(),
|
|
828
|
-
async init({ config: newConfig }) {
|
|
829
|
-
config = await newConfig;
|
|
830
|
-
this.cache.clear();
|
|
831
|
-
plugins = await getPlugins([
|
|
832
|
-
postprocessPlugin(),
|
|
833
|
-
...defaultPlugins,
|
|
834
|
-
...config.global.plugins ?? []
|
|
835
|
-
]);
|
|
836
|
-
for (const plugin of plugins) {
|
|
837
|
-
const out = await plugin.config?.call(pluginContext, config);
|
|
838
|
-
if (out) config = out;
|
|
839
|
-
}
|
|
840
|
-
},
|
|
841
|
-
getOptions() {
|
|
842
|
-
return options;
|
|
843
|
-
},
|
|
844
|
-
getConfig() {
|
|
845
|
-
return config;
|
|
846
|
-
},
|
|
847
|
-
/**
|
|
848
|
-
* The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
|
|
849
|
-
*/
|
|
850
|
-
getCompiledConfigPath() {
|
|
851
|
-
return import_node_path2.default.join(options.outDir, "source.config.mjs");
|
|
852
|
-
},
|
|
853
|
-
getPlugins() {
|
|
854
|
-
return plugins;
|
|
855
|
-
},
|
|
856
|
-
getPluginContext() {
|
|
857
|
-
return pluginContext;
|
|
858
|
-
},
|
|
859
|
-
async initServer(server2) {
|
|
860
|
-
for (const plugin of plugins) {
|
|
861
|
-
await plugin.configureServer?.call(pluginContext, server2);
|
|
862
|
-
}
|
|
863
|
-
},
|
|
864
|
-
async emit({ filterPlugin = () => true } = {}) {
|
|
865
|
-
return (await Promise.all(
|
|
866
|
-
plugins.map((plugin) => {
|
|
867
|
-
if (!filterPlugin(plugin) || !plugin.emit) return [];
|
|
868
|
-
return plugin.emit.call(pluginContext);
|
|
869
|
-
})
|
|
870
|
-
)).flat();
|
|
871
|
-
},
|
|
872
|
-
async emitAndWrite(emitOptions) {
|
|
873
|
-
const start = performance.now();
|
|
874
|
-
const out = await this.emit(emitOptions);
|
|
875
|
-
await Promise.all(
|
|
876
|
-
out.map(async (entry) => {
|
|
877
|
-
const file = import_node_path2.default.join(options.outDir, entry.path);
|
|
878
|
-
await import_promises.default.mkdir(import_node_path2.default.dirname(file), { recursive: true });
|
|
879
|
-
await import_promises.default.writeFile(file, entry.content);
|
|
880
|
-
})
|
|
881
|
-
);
|
|
882
|
-
console.log(`[MDX] generated files in ${performance.now() - start}ms`);
|
|
883
|
-
},
|
|
884
|
-
async transformMeta(options2, data) {
|
|
885
|
-
const ctx = {
|
|
886
|
-
...pluginContext,
|
|
887
|
-
...options2
|
|
888
|
-
};
|
|
889
|
-
data = await transformMetadata(options2, data);
|
|
890
|
-
for (const plugin of plugins) {
|
|
891
|
-
if (plugin.meta?.transform)
|
|
892
|
-
data = await plugin.meta.transform.call(ctx, data) ?? data;
|
|
893
|
-
}
|
|
894
|
-
return data;
|
|
895
|
-
},
|
|
896
|
-
async transformFrontmatter(options2, data) {
|
|
897
|
-
const ctx = {
|
|
898
|
-
...pluginContext,
|
|
899
|
-
...options2
|
|
900
|
-
};
|
|
901
|
-
data = await transformMetadata(options2, data);
|
|
902
|
-
for (const plugin of plugins) {
|
|
903
|
-
if (plugin.doc?.frontmatter)
|
|
904
|
-
data = await plugin.doc.frontmatter.call(ctx, data) ?? data;
|
|
905
|
-
}
|
|
906
|
-
return data;
|
|
907
|
-
},
|
|
908
|
-
async transformVFile(options2, file) {
|
|
909
|
-
const ctx = {
|
|
910
|
-
...pluginContext,
|
|
911
|
-
...options2
|
|
912
|
-
};
|
|
913
|
-
for (const plugin of plugins) {
|
|
914
|
-
if (plugin.doc?.vfile)
|
|
915
|
-
file = await plugin.doc.vfile.call(ctx, file) ?? file;
|
|
916
|
-
}
|
|
917
|
-
return file;
|
|
918
|
-
}
|
|
919
|
-
};
|
|
920
|
-
const pluginContext = {
|
|
921
|
-
core,
|
|
922
|
-
...options
|
|
923
|
-
};
|
|
924
|
-
return core;
|
|
925
|
-
}
|
|
926
|
-
function postprocessPlugin() {
|
|
927
|
-
const LinkReferenceTypes = `{
|
|
928
|
-
/**
|
|
929
|
-
* extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
|
|
930
|
-
*/
|
|
931
|
-
extractedReferences?: import('fumadocs-mdx').ExtractedReference[];
|
|
932
|
-
}`;
|
|
933
|
-
return {
|
|
934
|
-
"index-file": {
|
|
935
|
-
generateTypeConfig() {
|
|
936
|
-
const lines = [];
|
|
937
|
-
lines.push("{");
|
|
938
|
-
lines.push(" DocData: {");
|
|
939
|
-
for (const collection of this.core.getConfig().collectionList) {
|
|
940
|
-
let postprocessOptions;
|
|
941
|
-
switch (collection.type) {
|
|
942
|
-
case "doc":
|
|
943
|
-
postprocessOptions = collection.postprocess;
|
|
944
|
-
break;
|
|
945
|
-
case "docs":
|
|
946
|
-
postprocessOptions = collection.docs.postprocess;
|
|
947
|
-
break;
|
|
948
|
-
}
|
|
949
|
-
if (postprocessOptions?.extractLinkReferences) {
|
|
950
|
-
lines.push(ident(`${collection.name}: ${LinkReferenceTypes},`, 2));
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
lines.push(" }");
|
|
954
|
-
lines.push("}");
|
|
955
|
-
return lines.join("\n");
|
|
956
|
-
},
|
|
957
|
-
serverOptions(options) {
|
|
958
|
-
options.doc ??= {};
|
|
959
|
-
options.doc.passthroughs ??= [];
|
|
960
|
-
options.doc.passthroughs.push("extractedReferences");
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
};
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
// src/runtime/dynamic.ts
|
|
967
|
-
async function dynamic(configExports, coreOptions, serverOptions) {
|
|
968
|
-
const core = createCore(coreOptions);
|
|
969
|
-
await core.init({
|
|
970
|
-
config: buildConfig(configExports)
|
|
971
|
-
});
|
|
972
|
-
const create = server(serverOptions);
|
|
973
|
-
function getDocCollection(name) {
|
|
974
|
-
const collection = core.getConfig().getCollection(name);
|
|
975
|
-
if (!collection) return;
|
|
976
|
-
if (collection.type === "docs") return collection.docs;
|
|
977
|
-
else if (collection.type === "doc") return collection;
|
|
978
|
-
}
|
|
979
|
-
function convertLazyEntries(collection, entries) {
|
|
980
|
-
const head = {};
|
|
981
|
-
const body = {};
|
|
982
|
-
async function compile({ info, data }) {
|
|
983
|
-
let content = (await import_promises2.default.readFile(info.fullPath)).toString();
|
|
984
|
-
content = fumaMatter(content).content;
|
|
985
|
-
const compiled = await buildMDX(core, collection, {
|
|
986
|
-
filePath: info.fullPath,
|
|
987
|
-
source: content,
|
|
988
|
-
frontmatter: data,
|
|
989
|
-
isDevelopment: false,
|
|
990
|
-
environment: "runtime"
|
|
991
|
-
});
|
|
992
|
-
return await (0, import_client.executeMdx)(String(compiled.value), {
|
|
993
|
-
baseUrl: (0, import_node_url.pathToFileURL)(info.fullPath)
|
|
994
|
-
});
|
|
995
|
-
}
|
|
996
|
-
for (const entry of entries) {
|
|
997
|
-
head[entry.info.path] = () => entry.data;
|
|
998
|
-
let cachedResult;
|
|
999
|
-
body[entry.info.path] = () => cachedResult ??= compile(entry);
|
|
1000
|
-
}
|
|
1001
|
-
return { head, body };
|
|
1002
|
-
}
|
|
1003
|
-
return {
|
|
1004
|
-
async doc(name, base, entries) {
|
|
1005
|
-
const collection = getDocCollection(name);
|
|
1006
|
-
if (!collection)
|
|
1007
|
-
throw new Error(`the doc collection ${name} doesn't exist.`);
|
|
1008
|
-
const { head, body } = convertLazyEntries(collection, entries);
|
|
1009
|
-
return create.docLazy(name, base, head, body);
|
|
1010
|
-
},
|
|
1011
|
-
async docs(name, base, meta, entries) {
|
|
1012
|
-
const collection = getDocCollection(name);
|
|
1013
|
-
if (!collection)
|
|
1014
|
-
throw new Error(`the doc collection ${name} doesn't exist.`);
|
|
1015
|
-
const docs = convertLazyEntries(collection, entries);
|
|
1016
|
-
return create.docsLazy(name, base, meta, docs.head, docs.body);
|
|
1017
|
-
}
|
|
1018
|
-
};
|
|
1019
|
-
}
|
|
1020
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1021
|
-
0 && (module.exports = {
|
|
1022
|
-
dynamic
|
|
1023
|
-
});
|