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/node/loader.cjs
DELETED
|
@@ -1,1200 +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 __esm = (fn, res) => function __init() {
|
|
9
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
-
};
|
|
11
|
-
var __export = (target, all) => {
|
|
12
|
-
for (var name in all)
|
|
13
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
-
};
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from))
|
|
18
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
-
mod
|
|
30
|
-
));
|
|
31
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
-
|
|
33
|
-
// src/utils/fuma-matter.ts
|
|
34
|
-
function fumaMatter(input) {
|
|
35
|
-
const output = { matter: "", data: {}, content: input };
|
|
36
|
-
const match = regex.exec(input);
|
|
37
|
-
if (!match) {
|
|
38
|
-
return output;
|
|
39
|
-
}
|
|
40
|
-
output.matter = match[0];
|
|
41
|
-
output.content = input.slice(match[0].length);
|
|
42
|
-
const loaded = (0, import_js_yaml.load)(match[1]);
|
|
43
|
-
output.data = loaded ?? {};
|
|
44
|
-
return output;
|
|
45
|
-
}
|
|
46
|
-
var import_js_yaml, regex;
|
|
47
|
-
var init_fuma_matter = __esm({
|
|
48
|
-
"src/utils/fuma-matter.ts"() {
|
|
49
|
-
"use strict";
|
|
50
|
-
import_js_yaml = require("js-yaml");
|
|
51
|
-
regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// src/loaders/mdx/remark-unravel.ts
|
|
56
|
-
function remarkMarkAndUnravel() {
|
|
57
|
-
return (tree) => {
|
|
58
|
-
(0, import_unist_util_visit.visit)(tree, function(node, index, parent) {
|
|
59
|
-
let offset = -1;
|
|
60
|
-
let all = true;
|
|
61
|
-
let oneOrMore = false;
|
|
62
|
-
if (parent && typeof index === "number" && node.type === "paragraph") {
|
|
63
|
-
const children = node.children;
|
|
64
|
-
while (++offset < children.length) {
|
|
65
|
-
const child = children[offset];
|
|
66
|
-
if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
|
|
67
|
-
oneOrMore = true;
|
|
68
|
-
} else if (child.type === "text" && child.value.trim().length === 0) {
|
|
69
|
-
} else {
|
|
70
|
-
all = false;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (all && oneOrMore) {
|
|
75
|
-
offset = -1;
|
|
76
|
-
const newChildren = [];
|
|
77
|
-
while (++offset < children.length) {
|
|
78
|
-
const child = children[offset];
|
|
79
|
-
if (child.type === "mdxJsxTextElement") {
|
|
80
|
-
child.type = "mdxJsxFlowElement";
|
|
81
|
-
}
|
|
82
|
-
if (child.type === "mdxTextExpression") {
|
|
83
|
-
child.type = "mdxFlowExpression";
|
|
84
|
-
}
|
|
85
|
-
if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
|
|
86
|
-
} else {
|
|
87
|
-
newChildren.push(child);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
parent.children.splice(index, 1, ...newChildren);
|
|
91
|
-
return index;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
var import_unist_util_visit;
|
|
98
|
-
var init_remark_unravel = __esm({
|
|
99
|
-
"src/loaders/mdx/remark-unravel.ts"() {
|
|
100
|
-
"use strict";
|
|
101
|
-
import_unist_util_visit = require("unist-util-visit");
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// src/loaders/mdx/mdast-utils.ts
|
|
106
|
-
function flattenNode(node) {
|
|
107
|
-
if ("children" in node)
|
|
108
|
-
return node.children.map((child) => flattenNode(child)).join("");
|
|
109
|
-
if ("value" in node) return node.value;
|
|
110
|
-
return "";
|
|
111
|
-
}
|
|
112
|
-
var init_mdast_utils = __esm({
|
|
113
|
-
"src/loaders/mdx/mdast-utils.ts"() {
|
|
114
|
-
"use strict";
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
// src/loaders/mdx/remark-include.ts
|
|
119
|
-
function isElementLike(node) {
|
|
120
|
-
return ElementLikeTypes.includes(node.type);
|
|
121
|
-
}
|
|
122
|
-
function parseElementAttributes(element) {
|
|
123
|
-
if (Array.isArray(element.attributes)) {
|
|
124
|
-
const attributes = {};
|
|
125
|
-
for (const attr of element.attributes) {
|
|
126
|
-
if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
|
|
127
|
-
attributes[attr.name] = attr.value;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return attributes;
|
|
131
|
-
}
|
|
132
|
-
return element.attributes ?? {};
|
|
133
|
-
}
|
|
134
|
-
function parseSpecifier(specifier) {
|
|
135
|
-
const idx = specifier.lastIndexOf("#");
|
|
136
|
-
if (idx === -1) return { file: specifier };
|
|
137
|
-
return {
|
|
138
|
-
file: specifier.slice(0, idx),
|
|
139
|
-
section: specifier.slice(idx + 1)
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
function extractSection(root, section) {
|
|
143
|
-
let nodes;
|
|
144
|
-
let capturingHeadingContent = false;
|
|
145
|
-
(0, import_unist_util_visit2.visit)(root, (node) => {
|
|
146
|
-
if (node.type === "heading") {
|
|
147
|
-
if (capturingHeadingContent) {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
if (node.data?.hProperties?.id === section) {
|
|
151
|
-
capturingHeadingContent = true;
|
|
152
|
-
nodes = [node];
|
|
153
|
-
return "skip";
|
|
154
|
-
}
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
if (capturingHeadingContent) {
|
|
158
|
-
nodes?.push(node);
|
|
159
|
-
return "skip";
|
|
160
|
-
}
|
|
161
|
-
if (isElementLike(node) && node.name === "section") {
|
|
162
|
-
const attributes = parseElementAttributes(node);
|
|
163
|
-
if (attributes.id === section) {
|
|
164
|
-
nodes = node.children;
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
if (nodes)
|
|
170
|
-
return {
|
|
171
|
-
type: "root",
|
|
172
|
-
children: nodes
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function remarkInclude() {
|
|
176
|
-
const TagName = "include";
|
|
177
|
-
const embedContent = async (file, heading, params, data) => {
|
|
178
|
-
let content;
|
|
179
|
-
try {
|
|
180
|
-
content = (await fs2.readFile(file)).toString();
|
|
181
|
-
} catch (e) {
|
|
182
|
-
throw new Error(
|
|
183
|
-
`failed to read file ${file}
|
|
184
|
-
${e instanceof Error ? e.message : String(e)}`,
|
|
185
|
-
{ cause: e }
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
const ext = path3.extname(file);
|
|
189
|
-
data._compiler?.addDependency(file);
|
|
190
|
-
if (params.lang || ext !== ".md" && ext !== ".mdx") {
|
|
191
|
-
const lang = params.lang ?? ext.slice(1);
|
|
192
|
-
return {
|
|
193
|
-
type: "code",
|
|
194
|
-
lang,
|
|
195
|
-
meta: params.meta,
|
|
196
|
-
value: content,
|
|
197
|
-
data: {}
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
const parser = data._getProcessor ? data._getProcessor(ext === ".mdx" ? "mdx" : "md") : this;
|
|
201
|
-
const parsed = fumaMatter(content);
|
|
202
|
-
let mdast = parser.parse({
|
|
203
|
-
path: file,
|
|
204
|
-
value: parsed.content,
|
|
205
|
-
data: { frontmatter: parsed.data }
|
|
206
|
-
});
|
|
207
|
-
const baseProcessor = (0, import_unified.unified)().use(remarkMarkAndUnravel);
|
|
208
|
-
if (heading) {
|
|
209
|
-
const extracted = extractSection(
|
|
210
|
-
await baseProcessor.use(import_mdx_plugins.remarkHeading).run(mdast),
|
|
211
|
-
heading
|
|
212
|
-
);
|
|
213
|
-
if (!extracted)
|
|
214
|
-
throw new Error(
|
|
215
|
-
`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.`
|
|
216
|
-
);
|
|
217
|
-
mdast = extracted;
|
|
218
|
-
} else {
|
|
219
|
-
mdast = await baseProcessor.run(mdast);
|
|
220
|
-
}
|
|
221
|
-
await update(mdast, path3.dirname(file), data);
|
|
222
|
-
return mdast;
|
|
223
|
-
};
|
|
224
|
-
async function update(tree, directory, data) {
|
|
225
|
-
const queue = [];
|
|
226
|
-
(0, import_unist_util_visit2.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
|
|
227
|
-
const node = _node;
|
|
228
|
-
if (node.name !== TagName) return;
|
|
229
|
-
const specifier = flattenNode(node);
|
|
230
|
-
if (specifier.length === 0) return "skip";
|
|
231
|
-
const attributes = parseElementAttributes(node);
|
|
232
|
-
const { file: relativePath, section } = parseSpecifier(specifier);
|
|
233
|
-
const file = path3.resolve(
|
|
234
|
-
"cwd" in attributes ? process.cwd() : directory,
|
|
235
|
-
relativePath
|
|
236
|
-
);
|
|
237
|
-
queue.push(
|
|
238
|
-
embedContent(file, section, attributes, data).then((replace) => {
|
|
239
|
-
Object.assign(
|
|
240
|
-
parent && parent.type === "paragraph" ? parent : node,
|
|
241
|
-
replace
|
|
242
|
-
);
|
|
243
|
-
})
|
|
244
|
-
);
|
|
245
|
-
return "skip";
|
|
246
|
-
});
|
|
247
|
-
await Promise.all(queue);
|
|
248
|
-
}
|
|
249
|
-
return async (tree, file) => {
|
|
250
|
-
await update(tree, path3.dirname(file.path), file.data);
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
var import_unified, import_unist_util_visit2, path3, fs2, import_mdx_plugins, ElementLikeTypes;
|
|
254
|
-
var init_remark_include = __esm({
|
|
255
|
-
"src/loaders/mdx/remark-include.ts"() {
|
|
256
|
-
"use strict";
|
|
257
|
-
import_unified = require("unified");
|
|
258
|
-
import_unist_util_visit2 = require("unist-util-visit");
|
|
259
|
-
path3 = __toESM(require("path"), 1);
|
|
260
|
-
fs2 = __toESM(require("fs/promises"), 1);
|
|
261
|
-
init_fuma_matter();
|
|
262
|
-
import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
263
|
-
init_remark_unravel();
|
|
264
|
-
init_mdast_utils();
|
|
265
|
-
ElementLikeTypes = [
|
|
266
|
-
"mdxJsxFlowElement",
|
|
267
|
-
"mdxJsxTextElement",
|
|
268
|
-
"containerDirective",
|
|
269
|
-
"textDirective",
|
|
270
|
-
"leafDirective"
|
|
271
|
-
];
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
// src/loaders/mdx/remark-postprocess.ts
|
|
276
|
-
function remarkPostprocess({
|
|
277
|
-
_format,
|
|
278
|
-
includeProcessedMarkdown = false,
|
|
279
|
-
includeMDAST = false,
|
|
280
|
-
extractLinkReferences = false,
|
|
281
|
-
valueToExport = []
|
|
282
|
-
}) {
|
|
283
|
-
let _stringifyProcessor;
|
|
284
|
-
const getStringifyProcessor = () => {
|
|
285
|
-
return _stringifyProcessor ??= _format === "mdx" ? this : (
|
|
286
|
-
// force Markdown processor to stringify MDX nodes
|
|
287
|
-
this().use(import_remark_mdx.default).freeze()
|
|
288
|
-
);
|
|
289
|
-
};
|
|
290
|
-
return (tree, file) => {
|
|
291
|
-
const frontmatter = file.data.frontmatter ??= {};
|
|
292
|
-
if (!frontmatter.title) {
|
|
293
|
-
(0, import_unist_util_visit3.visit)(tree, "heading", (node) => {
|
|
294
|
-
if (node.depth === 1) {
|
|
295
|
-
frontmatter.title = flattenNode(node);
|
|
296
|
-
return false;
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
file.data["mdx-export"] ??= [];
|
|
301
|
-
if (extractLinkReferences) {
|
|
302
|
-
const urls = [];
|
|
303
|
-
(0, import_unist_util_visit3.visit)(tree, "link", (node) => {
|
|
304
|
-
urls.push({
|
|
305
|
-
href: node.url
|
|
306
|
-
});
|
|
307
|
-
return "skip";
|
|
308
|
-
});
|
|
309
|
-
file.data["mdx-export"].push({
|
|
310
|
-
name: "extractedReferences",
|
|
311
|
-
value: urls
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
if (includeProcessedMarkdown) {
|
|
315
|
-
const processor = getStringifyProcessor();
|
|
316
|
-
const markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
|
|
317
|
-
...processor.data("settings"),
|
|
318
|
-
// from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
|
|
319
|
-
extensions: processor.data("toMarkdownExtensions") || []
|
|
320
|
-
});
|
|
321
|
-
file.data["mdx-export"].push({
|
|
322
|
-
name: "_markdown",
|
|
323
|
-
value: markdown
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
if (includeMDAST) {
|
|
327
|
-
const options = includeMDAST === true ? {} : includeMDAST;
|
|
328
|
-
const mdast = JSON.stringify(
|
|
329
|
-
options.removePosition ? (0, import_unist_util_remove_position.removePosition)(structuredClone(tree)) : tree
|
|
330
|
-
);
|
|
331
|
-
file.data["mdx-export"].push({
|
|
332
|
-
name: "_mdast",
|
|
333
|
-
value: mdast
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
for (const { name, value } of file.data["mdx-export"]) {
|
|
337
|
-
tree.children.unshift(getMdastExport(name, value));
|
|
338
|
-
}
|
|
339
|
-
file.data["mdx-export"] = [];
|
|
340
|
-
for (const name of valueToExport) {
|
|
341
|
-
if (!(name in file.data)) continue;
|
|
342
|
-
tree.children.unshift(getMdastExport(name, file.data[name]));
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
function getMdastExport(name, value) {
|
|
347
|
-
return {
|
|
348
|
-
type: "mdxjsEsm",
|
|
349
|
-
value: "",
|
|
350
|
-
data: {
|
|
351
|
-
estree: {
|
|
352
|
-
type: "Program",
|
|
353
|
-
sourceType: "module",
|
|
354
|
-
body: [
|
|
355
|
-
{
|
|
356
|
-
type: "ExportNamedDeclaration",
|
|
357
|
-
attributes: [],
|
|
358
|
-
specifiers: [],
|
|
359
|
-
source: null,
|
|
360
|
-
declaration: {
|
|
361
|
-
type: "VariableDeclaration",
|
|
362
|
-
kind: "let",
|
|
363
|
-
declarations: [
|
|
364
|
-
{
|
|
365
|
-
type: "VariableDeclarator",
|
|
366
|
-
id: {
|
|
367
|
-
type: "Identifier",
|
|
368
|
-
name
|
|
369
|
-
},
|
|
370
|
-
init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
|
|
371
|
-
}
|
|
372
|
-
]
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
]
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
var import_unist_util_visit3, import_mdast_util_to_markdown, import_estree_util_value_to_estree, import_unist_util_remove_position, import_remark_mdx;
|
|
381
|
-
var init_remark_postprocess = __esm({
|
|
382
|
-
"src/loaders/mdx/remark-postprocess.ts"() {
|
|
383
|
-
"use strict";
|
|
384
|
-
import_unist_util_visit3 = require("unist-util-visit");
|
|
385
|
-
import_mdast_util_to_markdown = require("mdast-util-to-markdown");
|
|
386
|
-
import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
387
|
-
import_unist_util_remove_position = require("unist-util-remove-position");
|
|
388
|
-
import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
389
|
-
init_mdast_utils();
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
// src/loaders/mdx/build-mdx.ts
|
|
394
|
-
var build_mdx_exports = {};
|
|
395
|
-
__export(build_mdx_exports, {
|
|
396
|
-
buildMDX: () => buildMDX
|
|
397
|
-
});
|
|
398
|
-
async function buildMDX(core2, collection, {
|
|
399
|
-
filePath,
|
|
400
|
-
frontmatter,
|
|
401
|
-
source,
|
|
402
|
-
_compiler,
|
|
403
|
-
environment,
|
|
404
|
-
isDevelopment
|
|
405
|
-
}) {
|
|
406
|
-
const mdxOptions = await core2.getConfig().getMDXOptions(collection, environment);
|
|
407
|
-
function getProcessor(format) {
|
|
408
|
-
const cache = core2.cache;
|
|
409
|
-
const key = `build-mdx:${collection?.name ?? "global"}:${format}`;
|
|
410
|
-
let processor = cache.get(key);
|
|
411
|
-
if (!processor) {
|
|
412
|
-
const postprocessOptions = {
|
|
413
|
-
_format: format,
|
|
414
|
-
...collection?.postprocess,
|
|
415
|
-
valueToExport: [
|
|
416
|
-
...collection?.postprocess?.valueToExport ?? [],
|
|
417
|
-
"structuredData",
|
|
418
|
-
"frontmatter"
|
|
419
|
-
]
|
|
420
|
-
};
|
|
421
|
-
processor = (0, import_mdx.createProcessor)({
|
|
422
|
-
outputFormat: "program",
|
|
423
|
-
development: isDevelopment,
|
|
424
|
-
...mdxOptions,
|
|
425
|
-
remarkPlugins: [
|
|
426
|
-
remarkInclude,
|
|
427
|
-
...mdxOptions.remarkPlugins ?? [],
|
|
428
|
-
[remarkPostprocess, postprocessOptions]
|
|
429
|
-
],
|
|
430
|
-
format
|
|
431
|
-
});
|
|
432
|
-
cache.set(key, processor);
|
|
433
|
-
}
|
|
434
|
-
return processor;
|
|
435
|
-
}
|
|
436
|
-
let vfile = new import_vfile.VFile({
|
|
437
|
-
value: source,
|
|
438
|
-
path: filePath,
|
|
439
|
-
data: { frontmatter, _compiler, _getProcessor: getProcessor }
|
|
440
|
-
});
|
|
441
|
-
if (collection) {
|
|
442
|
-
vfile = await core2.transformVFile({ collection, filePath, source }, vfile);
|
|
443
|
-
}
|
|
444
|
-
return getProcessor(filePath.endsWith(".mdx") ? "mdx" : "md").process(vfile);
|
|
445
|
-
}
|
|
446
|
-
var import_mdx, import_vfile;
|
|
447
|
-
var init_build_mdx = __esm({
|
|
448
|
-
"src/loaders/mdx/build-mdx.ts"() {
|
|
449
|
-
"use strict";
|
|
450
|
-
import_mdx = require("@mdx-js/mdx");
|
|
451
|
-
import_vfile = require("vfile");
|
|
452
|
-
init_remark_include();
|
|
453
|
-
init_remark_postprocess();
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
// src/config/preset.ts
|
|
458
|
-
function pluginOption(def, options = []) {
|
|
459
|
-
const list = def(Array.isArray(options) ? options : []).filter(
|
|
460
|
-
Boolean
|
|
461
|
-
);
|
|
462
|
-
if (typeof options === "function") {
|
|
463
|
-
return options(list);
|
|
464
|
-
}
|
|
465
|
-
return list;
|
|
466
|
-
}
|
|
467
|
-
function applyMdxPreset(options = {}) {
|
|
468
|
-
return async (environment = "bundler") => {
|
|
469
|
-
if (options.preset === "minimal") return options;
|
|
470
|
-
const plugins = await import("fumadocs-core/mdx-plugins");
|
|
471
|
-
const {
|
|
472
|
-
valueToExport = [],
|
|
473
|
-
rehypeCodeOptions,
|
|
474
|
-
remarkImageOptions,
|
|
475
|
-
remarkHeadingOptions,
|
|
476
|
-
remarkStructureOptions,
|
|
477
|
-
remarkCodeTabOptions,
|
|
478
|
-
remarkNpmOptions,
|
|
479
|
-
...mdxOptions
|
|
480
|
-
} = options;
|
|
481
|
-
const remarkPlugins = pluginOption(
|
|
482
|
-
(v) => [
|
|
483
|
-
plugins.remarkGfm,
|
|
484
|
-
[
|
|
485
|
-
plugins.remarkHeading,
|
|
486
|
-
{
|
|
487
|
-
generateToc: false,
|
|
488
|
-
...remarkHeadingOptions
|
|
489
|
-
}
|
|
490
|
-
],
|
|
491
|
-
remarkImageOptions !== false && [
|
|
492
|
-
plugins.remarkImage,
|
|
493
|
-
{
|
|
494
|
-
...remarkImageOptions,
|
|
495
|
-
useImport: remarkImageOptions?.useImport ?? environment === "bundler"
|
|
496
|
-
}
|
|
497
|
-
],
|
|
498
|
-
"remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
|
|
499
|
-
plugins.remarkCodeTab,
|
|
500
|
-
remarkCodeTabOptions
|
|
501
|
-
],
|
|
502
|
-
"remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
|
|
503
|
-
...v,
|
|
504
|
-
remarkStructureOptions !== false && [
|
|
505
|
-
plugins.remarkStructure,
|
|
506
|
-
remarkStructureOptions
|
|
507
|
-
],
|
|
508
|
-
valueToExport.length > 0 && (() => {
|
|
509
|
-
return (_, file) => {
|
|
510
|
-
file.data["mdx-export"] ??= [];
|
|
511
|
-
for (const name of valueToExport) {
|
|
512
|
-
if (!(name in file.data)) continue;
|
|
513
|
-
file.data["mdx-export"].push({
|
|
514
|
-
name,
|
|
515
|
-
value: file.data[name]
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
})
|
|
520
|
-
],
|
|
521
|
-
mdxOptions.remarkPlugins
|
|
522
|
-
);
|
|
523
|
-
const rehypePlugins = pluginOption(
|
|
524
|
-
(v) => [
|
|
525
|
-
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
|
526
|
-
...v,
|
|
527
|
-
plugins.rehypeToc
|
|
528
|
-
],
|
|
529
|
-
mdxOptions.rehypePlugins
|
|
530
|
-
);
|
|
531
|
-
return {
|
|
532
|
-
...mdxOptions,
|
|
533
|
-
outputFormat: environment === "runtime" ? "function-body" : mdxOptions.outputFormat,
|
|
534
|
-
remarkPlugins,
|
|
535
|
-
rehypePlugins
|
|
536
|
-
};
|
|
537
|
-
};
|
|
538
|
-
}
|
|
539
|
-
var init_preset = __esm({
|
|
540
|
-
"src/config/preset.ts"() {
|
|
541
|
-
"use strict";
|
|
542
|
-
}
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
// src/config/build.ts
|
|
546
|
-
function buildCollection(name, config) {
|
|
547
|
-
if (config.type === "docs") {
|
|
548
|
-
return {
|
|
549
|
-
...config,
|
|
550
|
-
name,
|
|
551
|
-
meta: buildPrimitiveCollection(name, config.meta),
|
|
552
|
-
docs: buildPrimitiveCollection(name, config.docs),
|
|
553
|
-
hasFile(filePath) {
|
|
554
|
-
return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);
|
|
555
|
-
}
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
return buildPrimitiveCollection(name, config);
|
|
559
|
-
}
|
|
560
|
-
function buildPrimitiveCollection(name, { files, ...config }) {
|
|
561
|
-
const supportedFormats = SupportedFormats[config.type];
|
|
562
|
-
const patterns = files ?? [`**/*.{${supportedFormats.join(",")}}`];
|
|
563
|
-
let matchers;
|
|
564
|
-
return {
|
|
565
|
-
...config,
|
|
566
|
-
name,
|
|
567
|
-
patterns,
|
|
568
|
-
isFileSupported(filePath) {
|
|
569
|
-
return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
|
|
570
|
-
},
|
|
571
|
-
hasFile(filePath) {
|
|
572
|
-
matchers ??= (Array.isArray(config.dir) ? config.dir : [config.dir]).map(
|
|
573
|
-
(dir) => (0, import_picomatch.default)(patterns, {
|
|
574
|
-
cwd: dir
|
|
575
|
-
})
|
|
576
|
-
);
|
|
577
|
-
return this.isFileSupported(filePath) && matchers.some((matcher) => matcher(filePath));
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
|
-
function buildConfig(config) {
|
|
582
|
-
const collections = /* @__PURE__ */ new Map();
|
|
583
|
-
const loaded = {};
|
|
584
|
-
for (const [k, v] of Object.entries(config)) {
|
|
585
|
-
if (!v) {
|
|
586
|
-
continue;
|
|
587
|
-
}
|
|
588
|
-
if (typeof v === "object" && "type" in v) {
|
|
589
|
-
if (v.type === "docs") {
|
|
590
|
-
collections.set(k, buildCollection(k, v));
|
|
591
|
-
continue;
|
|
592
|
-
}
|
|
593
|
-
if (v.type === "doc" || v.type === "meta") {
|
|
594
|
-
collections.set(
|
|
595
|
-
k,
|
|
596
|
-
buildCollection(k, v)
|
|
597
|
-
);
|
|
598
|
-
continue;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
if (k === "default" && v) {
|
|
602
|
-
Object.assign(loaded, v);
|
|
603
|
-
continue;
|
|
604
|
-
}
|
|
605
|
-
throw new Error(
|
|
606
|
-
`Unknown export "${k}", you can only export collections from source configuration file.`
|
|
607
|
-
);
|
|
608
|
-
}
|
|
609
|
-
const mdxOptionsCache = /* @__PURE__ */ new Map();
|
|
610
|
-
return {
|
|
611
|
-
global: loaded,
|
|
612
|
-
collectionList: Array.from(collections.values()),
|
|
613
|
-
getCollection(name) {
|
|
614
|
-
return collections.get(name);
|
|
615
|
-
},
|
|
616
|
-
getMDXOptions(collection, environment = "bundler") {
|
|
617
|
-
const key = collection ? `${environment}:${collection.name}` : environment;
|
|
618
|
-
const cached = mdxOptionsCache.get(key);
|
|
619
|
-
if (cached) return cached;
|
|
620
|
-
let result;
|
|
621
|
-
if (collection?.mdxOptions) {
|
|
622
|
-
const optionsFn = collection.mdxOptions;
|
|
623
|
-
result = typeof optionsFn === "function" ? optionsFn(environment) : optionsFn;
|
|
624
|
-
} else {
|
|
625
|
-
result = (async () => {
|
|
626
|
-
const optionsFn = this.global.mdxOptions;
|
|
627
|
-
const options = typeof optionsFn === "function" ? await optionsFn() : optionsFn;
|
|
628
|
-
return applyMdxPreset(options)(environment);
|
|
629
|
-
})();
|
|
630
|
-
}
|
|
631
|
-
mdxOptionsCache.set(key, result);
|
|
632
|
-
return result;
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
var import_picomatch, SupportedFormats;
|
|
637
|
-
var init_build = __esm({
|
|
638
|
-
"src/config/build.ts"() {
|
|
639
|
-
"use strict";
|
|
640
|
-
import_picomatch = __toESM(require("picomatch"), 1);
|
|
641
|
-
init_preset();
|
|
642
|
-
SupportedFormats = {
|
|
643
|
-
doc: ["mdx", "md"],
|
|
644
|
-
meta: ["json", "yaml"]
|
|
645
|
-
};
|
|
646
|
-
}
|
|
647
|
-
});
|
|
648
|
-
|
|
649
|
-
// src/config/load-from-file.ts
|
|
650
|
-
var load_from_file_exports = {};
|
|
651
|
-
__export(load_from_file_exports, {
|
|
652
|
-
loadConfig: () => loadConfig
|
|
653
|
-
});
|
|
654
|
-
async function compileConfig(core2) {
|
|
655
|
-
const { build } = await import("esbuild");
|
|
656
|
-
const { configPath, outDir } = core2.getOptions();
|
|
657
|
-
const transformed = await build({
|
|
658
|
-
entryPoints: [{ in: configPath, out: "source.config" }],
|
|
659
|
-
bundle: true,
|
|
660
|
-
outdir: outDir,
|
|
661
|
-
target: "node20",
|
|
662
|
-
write: true,
|
|
663
|
-
platform: "node",
|
|
664
|
-
format: "esm",
|
|
665
|
-
packages: "external",
|
|
666
|
-
outExtension: {
|
|
667
|
-
".js": ".mjs"
|
|
668
|
-
},
|
|
669
|
-
allowOverwrite: true
|
|
670
|
-
});
|
|
671
|
-
if (transformed.errors.length > 0) {
|
|
672
|
-
throw new Error("failed to compile configuration file");
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
async function loadConfig(core2, build = false) {
|
|
676
|
-
if (build) await compileConfig(core2);
|
|
677
|
-
const url = (0, import_node_url2.pathToFileURL)(core2.getCompiledConfigPath());
|
|
678
|
-
url.searchParams.set("hash", Date.now().toString());
|
|
679
|
-
const config = import(url.href).then(
|
|
680
|
-
(loaded) => buildConfig(loaded)
|
|
681
|
-
);
|
|
682
|
-
return await config;
|
|
683
|
-
}
|
|
684
|
-
var import_node_url2;
|
|
685
|
-
var init_load_from_file = __esm({
|
|
686
|
-
"src/config/load-from-file.ts"() {
|
|
687
|
-
"use strict";
|
|
688
|
-
import_node_url2 = require("url");
|
|
689
|
-
init_build();
|
|
690
|
-
}
|
|
691
|
-
});
|
|
692
|
-
|
|
693
|
-
// src/node/loader.ts
|
|
694
|
-
var loader_exports = {};
|
|
695
|
-
__export(loader_exports, {
|
|
696
|
-
load: () => load3
|
|
697
|
-
});
|
|
698
|
-
module.exports = __toCommonJS(loader_exports);
|
|
699
|
-
|
|
700
|
-
// src/core.ts
|
|
701
|
-
var import_node_path2 = __toESM(require("path"), 1);
|
|
702
|
-
var import_promises = __toESM(require("fs/promises"), 1);
|
|
703
|
-
|
|
704
|
-
// src/utils/validation.ts
|
|
705
|
-
var ValidationError = class extends Error {
|
|
706
|
-
constructor(message, issues) {
|
|
707
|
-
super(
|
|
708
|
-
`${message}:
|
|
709
|
-
${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
|
|
710
|
-
);
|
|
711
|
-
this.title = message;
|
|
712
|
-
this.issues = issues;
|
|
713
|
-
}
|
|
714
|
-
async toStringFormatted() {
|
|
715
|
-
const picocolors = await import("picocolors");
|
|
716
|
-
return [
|
|
717
|
-
picocolors.bold(`[MDX] ${this.title}:`),
|
|
718
|
-
...this.issues.map(
|
|
719
|
-
(issue) => picocolors.redBright(
|
|
720
|
-
`- ${picocolors.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
|
|
721
|
-
)
|
|
722
|
-
)
|
|
723
|
-
].join("\n");
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
|
-
async function validate(schema, data, context, errorMessage) {
|
|
727
|
-
if (typeof schema === "function" && !("~standard" in schema)) {
|
|
728
|
-
schema = schema(context);
|
|
729
|
-
}
|
|
730
|
-
if ("~standard" in schema) {
|
|
731
|
-
const result = await schema["~standard"].validate(
|
|
732
|
-
data
|
|
733
|
-
);
|
|
734
|
-
if (result.issues) {
|
|
735
|
-
throw new ValidationError(errorMessage, result.issues);
|
|
736
|
-
}
|
|
737
|
-
return result.value;
|
|
738
|
-
}
|
|
739
|
-
return data;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
// src/utils/codegen.ts
|
|
743
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
744
|
-
var import_tinyglobby = require("tinyglobby");
|
|
745
|
-
function ident(code, tab = 1) {
|
|
746
|
-
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
// src/core.ts
|
|
750
|
-
var _Defaults = {
|
|
751
|
-
configPath: "source.config.ts",
|
|
752
|
-
outDir: ".source"
|
|
753
|
-
};
|
|
754
|
-
async function getPlugins(pluginOptions) {
|
|
755
|
-
const plugins = [];
|
|
756
|
-
for await (const option of pluginOptions) {
|
|
757
|
-
if (!option) continue;
|
|
758
|
-
if (Array.isArray(option)) plugins.push(...await getPlugins(option));
|
|
759
|
-
else plugins.push(option);
|
|
760
|
-
}
|
|
761
|
-
return plugins;
|
|
762
|
-
}
|
|
763
|
-
function createCore(options, defaultPlugins = []) {
|
|
764
|
-
let config;
|
|
765
|
-
let plugins;
|
|
766
|
-
async function transformMetadata({
|
|
767
|
-
collection,
|
|
768
|
-
filePath,
|
|
769
|
-
source
|
|
770
|
-
}, data) {
|
|
771
|
-
if (collection.schema) {
|
|
772
|
-
data = await validate(
|
|
773
|
-
collection.schema,
|
|
774
|
-
data,
|
|
775
|
-
{ path: filePath, source },
|
|
776
|
-
collection.type === "doc" ? `invalid frontmatter in ${filePath}` : `invalid data in ${filePath}`
|
|
777
|
-
);
|
|
778
|
-
}
|
|
779
|
-
return data;
|
|
780
|
-
}
|
|
781
|
-
const core2 = {
|
|
782
|
-
/**
|
|
783
|
-
* Convenient cache store, reset when config changes
|
|
784
|
-
*/
|
|
785
|
-
cache: /* @__PURE__ */ new Map(),
|
|
786
|
-
async init({ config: newConfig }) {
|
|
787
|
-
config = await newConfig;
|
|
788
|
-
this.cache.clear();
|
|
789
|
-
plugins = await getPlugins([
|
|
790
|
-
postprocessPlugin(),
|
|
791
|
-
...defaultPlugins,
|
|
792
|
-
...config.global.plugins ?? []
|
|
793
|
-
]);
|
|
794
|
-
for (const plugin of plugins) {
|
|
795
|
-
const out = await plugin.config?.call(pluginContext, config);
|
|
796
|
-
if (out) config = out;
|
|
797
|
-
}
|
|
798
|
-
},
|
|
799
|
-
getOptions() {
|
|
800
|
-
return options;
|
|
801
|
-
},
|
|
802
|
-
getConfig() {
|
|
803
|
-
return config;
|
|
804
|
-
},
|
|
805
|
-
/**
|
|
806
|
-
* The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
|
|
807
|
-
*/
|
|
808
|
-
getCompiledConfigPath() {
|
|
809
|
-
return import_node_path2.default.join(options.outDir, "source.config.mjs");
|
|
810
|
-
},
|
|
811
|
-
getPlugins() {
|
|
812
|
-
return plugins;
|
|
813
|
-
},
|
|
814
|
-
getPluginContext() {
|
|
815
|
-
return pluginContext;
|
|
816
|
-
},
|
|
817
|
-
async initServer(server) {
|
|
818
|
-
for (const plugin of plugins) {
|
|
819
|
-
await plugin.configureServer?.call(pluginContext, server);
|
|
820
|
-
}
|
|
821
|
-
},
|
|
822
|
-
async emit({ filterPlugin = () => true } = {}) {
|
|
823
|
-
return (await Promise.all(
|
|
824
|
-
plugins.map((plugin) => {
|
|
825
|
-
if (!filterPlugin(plugin) || !plugin.emit) return [];
|
|
826
|
-
return plugin.emit.call(pluginContext);
|
|
827
|
-
})
|
|
828
|
-
)).flat();
|
|
829
|
-
},
|
|
830
|
-
async emitAndWrite(emitOptions) {
|
|
831
|
-
const start = performance.now();
|
|
832
|
-
const out = await this.emit(emitOptions);
|
|
833
|
-
await Promise.all(
|
|
834
|
-
out.map(async (entry) => {
|
|
835
|
-
const file = import_node_path2.default.join(options.outDir, entry.path);
|
|
836
|
-
await import_promises.default.mkdir(import_node_path2.default.dirname(file), { recursive: true });
|
|
837
|
-
await import_promises.default.writeFile(file, entry.content);
|
|
838
|
-
})
|
|
839
|
-
);
|
|
840
|
-
console.log(`[MDX] generated files in ${performance.now() - start}ms`);
|
|
841
|
-
},
|
|
842
|
-
async transformMeta(options2, data) {
|
|
843
|
-
const ctx = {
|
|
844
|
-
...pluginContext,
|
|
845
|
-
...options2
|
|
846
|
-
};
|
|
847
|
-
data = await transformMetadata(options2, data);
|
|
848
|
-
for (const plugin of plugins) {
|
|
849
|
-
if (plugin.meta?.transform)
|
|
850
|
-
data = await plugin.meta.transform.call(ctx, data) ?? data;
|
|
851
|
-
}
|
|
852
|
-
return data;
|
|
853
|
-
},
|
|
854
|
-
async transformFrontmatter(options2, data) {
|
|
855
|
-
const ctx = {
|
|
856
|
-
...pluginContext,
|
|
857
|
-
...options2
|
|
858
|
-
};
|
|
859
|
-
data = await transformMetadata(options2, data);
|
|
860
|
-
for (const plugin of plugins) {
|
|
861
|
-
if (plugin.doc?.frontmatter)
|
|
862
|
-
data = await plugin.doc.frontmatter.call(ctx, data) ?? data;
|
|
863
|
-
}
|
|
864
|
-
return data;
|
|
865
|
-
},
|
|
866
|
-
async transformVFile(options2, file) {
|
|
867
|
-
const ctx = {
|
|
868
|
-
...pluginContext,
|
|
869
|
-
...options2
|
|
870
|
-
};
|
|
871
|
-
for (const plugin of plugins) {
|
|
872
|
-
if (plugin.doc?.vfile)
|
|
873
|
-
file = await plugin.doc.vfile.call(ctx, file) ?? file;
|
|
874
|
-
}
|
|
875
|
-
return file;
|
|
876
|
-
}
|
|
877
|
-
};
|
|
878
|
-
const pluginContext = {
|
|
879
|
-
core: core2,
|
|
880
|
-
...options
|
|
881
|
-
};
|
|
882
|
-
return core2;
|
|
883
|
-
}
|
|
884
|
-
function postprocessPlugin() {
|
|
885
|
-
const LinkReferenceTypes = `{
|
|
886
|
-
/**
|
|
887
|
-
* extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
|
|
888
|
-
*/
|
|
889
|
-
extractedReferences?: import('fumadocs-mdx').ExtractedReference[];
|
|
890
|
-
}`;
|
|
891
|
-
return {
|
|
892
|
-
"index-file": {
|
|
893
|
-
generateTypeConfig() {
|
|
894
|
-
const lines = [];
|
|
895
|
-
lines.push("{");
|
|
896
|
-
lines.push(" DocData: {");
|
|
897
|
-
for (const collection of this.core.getConfig().collectionList) {
|
|
898
|
-
let postprocessOptions;
|
|
899
|
-
switch (collection.type) {
|
|
900
|
-
case "doc":
|
|
901
|
-
postprocessOptions = collection.postprocess;
|
|
902
|
-
break;
|
|
903
|
-
case "docs":
|
|
904
|
-
postprocessOptions = collection.docs.postprocess;
|
|
905
|
-
break;
|
|
906
|
-
}
|
|
907
|
-
if (postprocessOptions?.extractLinkReferences) {
|
|
908
|
-
lines.push(ident(`${collection.name}: ${LinkReferenceTypes},`, 2));
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
lines.push(" }");
|
|
912
|
-
lines.push("}");
|
|
913
|
-
return lines.join("\n");
|
|
914
|
-
},
|
|
915
|
-
serverOptions(options) {
|
|
916
|
-
options.doc ??= {};
|
|
917
|
-
options.doc.passthroughs ??= [];
|
|
918
|
-
options.doc.passthroughs.push("extractedReferences");
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
};
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
// src/loaders/mdx/index.ts
|
|
925
|
-
init_fuma_matter();
|
|
926
|
-
var import_zod = require("zod");
|
|
927
|
-
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
928
|
-
var import_node_path3 = __toESM(require("path"), 1);
|
|
929
|
-
var import_node_crypto = require("crypto");
|
|
930
|
-
|
|
931
|
-
// src/loaders/index.ts
|
|
932
|
-
var metaLoaderGlob = /\.(json|yaml)(\?.+?)?$/;
|
|
933
|
-
var mdxLoaderGlob = /\.mdx?(\?.+?)?$/;
|
|
934
|
-
|
|
935
|
-
// src/loaders/mdx/index.ts
|
|
936
|
-
var querySchema = import_zod.z.object({
|
|
937
|
-
only: import_zod.z.literal(["frontmatter", "all"]).default("all"),
|
|
938
|
-
collection: import_zod.z.string().optional()
|
|
939
|
-
}).loose();
|
|
940
|
-
var cacheEntry = import_zod.z.object({
|
|
941
|
-
code: import_zod.z.string(),
|
|
942
|
-
map: import_zod.z.any().optional(),
|
|
943
|
-
hash: import_zod.z.string().optional()
|
|
944
|
-
});
|
|
945
|
-
function createMdxLoader(configLoader2) {
|
|
946
|
-
return {
|
|
947
|
-
test: mdxLoaderGlob,
|
|
948
|
-
async load({
|
|
949
|
-
getSource,
|
|
950
|
-
development: isDevelopment,
|
|
951
|
-
query,
|
|
952
|
-
compiler,
|
|
953
|
-
filePath
|
|
954
|
-
}) {
|
|
955
|
-
const config = await configLoader2.getConfig();
|
|
956
|
-
const value = await getSource();
|
|
957
|
-
const matter = fumaMatter(value);
|
|
958
|
-
const parsed = querySchema.parse(query);
|
|
959
|
-
let after;
|
|
960
|
-
if (!isDevelopment && config.global.experimentalBuildCache) {
|
|
961
|
-
const cacheDir = config.global.experimentalBuildCache;
|
|
962
|
-
const cacheKey = `${parsed.hash}_${parsed.collection ?? "global"}_${generateCacheHash(filePath)}`;
|
|
963
|
-
const cached = await import_promises2.default.readFile(import_node_path3.default.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
|
|
964
|
-
if (cached && cached.hash === generateCacheHash(value)) return cached;
|
|
965
|
-
after = async () => {
|
|
966
|
-
await import_promises2.default.mkdir(cacheDir, { recursive: true });
|
|
967
|
-
await import_promises2.default.writeFile(
|
|
968
|
-
import_node_path3.default.join(cacheDir, cacheKey),
|
|
969
|
-
JSON.stringify({
|
|
970
|
-
...out,
|
|
971
|
-
hash: generateCacheHash(value)
|
|
972
|
-
})
|
|
973
|
-
);
|
|
974
|
-
};
|
|
975
|
-
}
|
|
976
|
-
const collection = parsed.collection ? config.getCollection(parsed.collection) : void 0;
|
|
977
|
-
let docCollection;
|
|
978
|
-
switch (collection?.type) {
|
|
979
|
-
case "doc":
|
|
980
|
-
docCollection = collection;
|
|
981
|
-
break;
|
|
982
|
-
case "docs":
|
|
983
|
-
docCollection = collection.docs;
|
|
984
|
-
break;
|
|
985
|
-
}
|
|
986
|
-
if (docCollection) {
|
|
987
|
-
matter.data = await configLoader2.core.transformFrontmatter(
|
|
988
|
-
{ collection: docCollection, filePath, source: value },
|
|
989
|
-
matter.data
|
|
990
|
-
);
|
|
991
|
-
}
|
|
992
|
-
if (parsed.only === "frontmatter") {
|
|
993
|
-
return {
|
|
994
|
-
code: `export const frontmatter = ${JSON.stringify(matter.data)}`,
|
|
995
|
-
map: null
|
|
996
|
-
};
|
|
997
|
-
}
|
|
998
|
-
const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
|
|
999
|
-
const { buildMDX: buildMDX2 } = await Promise.resolve().then(() => (init_build_mdx(), build_mdx_exports));
|
|
1000
|
-
const compiled = await buildMDX2(configLoader2.core, docCollection, {
|
|
1001
|
-
isDevelopment,
|
|
1002
|
-
source: "\n".repeat(lineOffset) + matter.content,
|
|
1003
|
-
filePath,
|
|
1004
|
-
frontmatter: matter.data,
|
|
1005
|
-
_compiler: compiler,
|
|
1006
|
-
environment: "bundler"
|
|
1007
|
-
});
|
|
1008
|
-
const out = {
|
|
1009
|
-
code: String(compiled.value),
|
|
1010
|
-
map: compiled.map
|
|
1011
|
-
};
|
|
1012
|
-
await after?.();
|
|
1013
|
-
return out;
|
|
1014
|
-
}
|
|
1015
|
-
};
|
|
1016
|
-
}
|
|
1017
|
-
function generateCacheHash(input) {
|
|
1018
|
-
return (0, import_node_crypto.createHash)("md5").update(input).digest("hex");
|
|
1019
|
-
}
|
|
1020
|
-
function countLines(s) {
|
|
1021
|
-
let num = 0;
|
|
1022
|
-
for (const c of s) {
|
|
1023
|
-
if (c === "\n") num++;
|
|
1024
|
-
}
|
|
1025
|
-
return num;
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
// src/loaders/adapter.ts
|
|
1029
|
-
var import_node_url = require("url");
|
|
1030
|
-
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
1031
|
-
var import_node_querystring = require("querystring");
|
|
1032
|
-
var import_node_path4 = __toESM(require("path"), 1);
|
|
1033
|
-
var import_node_fs = require("fs");
|
|
1034
|
-
function toNode(loader) {
|
|
1035
|
-
return async (url, _context, nextLoad) => {
|
|
1036
|
-
if (url.startsWith("file:///") && (!loader.test || loader.test.test(url))) {
|
|
1037
|
-
const parsedUrl = new URL(url);
|
|
1038
|
-
const filePath = (0, import_node_url.fileURLToPath)(parsedUrl);
|
|
1039
|
-
const result = await loader.load({
|
|
1040
|
-
filePath,
|
|
1041
|
-
query: Object.fromEntries(parsedUrl.searchParams.entries()),
|
|
1042
|
-
async getSource() {
|
|
1043
|
-
return (await import_promises3.default.readFile(filePath)).toString();
|
|
1044
|
-
},
|
|
1045
|
-
development: false,
|
|
1046
|
-
compiler: {
|
|
1047
|
-
addDependency() {
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
});
|
|
1051
|
-
if (result) {
|
|
1052
|
-
return {
|
|
1053
|
-
source: result.code,
|
|
1054
|
-
format: "module",
|
|
1055
|
-
shortCircuit: true
|
|
1056
|
-
};
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
return nextLoad(url);
|
|
1060
|
-
};
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
// src/loaders/config.ts
|
|
1064
|
-
var import_promises4 = __toESM(require("fs/promises"), 1);
|
|
1065
|
-
function createStandaloneConfigLoader({
|
|
1066
|
-
core: core2,
|
|
1067
|
-
buildConfig: buildConfig2,
|
|
1068
|
-
mode
|
|
1069
|
-
}) {
|
|
1070
|
-
let loaded;
|
|
1071
|
-
async function getConfigHash() {
|
|
1072
|
-
if (mode === "production") return "static";
|
|
1073
|
-
const stats = await import_promises4.default.stat(core2.getOptions().configPath).catch(() => {
|
|
1074
|
-
throw new Error("Cannot find config file");
|
|
1075
|
-
});
|
|
1076
|
-
return stats.mtime.getTime().toString();
|
|
1077
|
-
}
|
|
1078
|
-
async function newConfig() {
|
|
1079
|
-
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_load_from_file(), load_from_file_exports));
|
|
1080
|
-
await core2.init({
|
|
1081
|
-
config: loadConfig2(core2, buildConfig2)
|
|
1082
|
-
});
|
|
1083
|
-
return core2.getConfig();
|
|
1084
|
-
}
|
|
1085
|
-
return {
|
|
1086
|
-
core: core2,
|
|
1087
|
-
async getConfig() {
|
|
1088
|
-
const hash = await getConfigHash();
|
|
1089
|
-
if (loaded && loaded.hash === hash) return loaded.config;
|
|
1090
|
-
loaded = {
|
|
1091
|
-
hash,
|
|
1092
|
-
config: newConfig()
|
|
1093
|
-
};
|
|
1094
|
-
return loaded.config;
|
|
1095
|
-
}
|
|
1096
|
-
};
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
// src/loaders/meta.ts
|
|
1100
|
-
var import_js_yaml2 = require("js-yaml");
|
|
1101
|
-
var import_zod2 = require("zod");
|
|
1102
|
-
var querySchema2 = import_zod2.z.object({
|
|
1103
|
-
collection: import_zod2.z.string().optional()
|
|
1104
|
-
}).loose();
|
|
1105
|
-
function createMetaLoader(configLoader2, resolve2 = {}) {
|
|
1106
|
-
const { json: resolveJson = "js", yaml: resolveYaml = "js" } = resolve2;
|
|
1107
|
-
function parse2(filePath, source) {
|
|
1108
|
-
try {
|
|
1109
|
-
if (filePath.endsWith(".json")) return JSON.parse(source);
|
|
1110
|
-
if (filePath.endsWith(".yaml")) return (0, import_js_yaml2.load)(source);
|
|
1111
|
-
} catch (e) {
|
|
1112
|
-
throw new Error(`invalid data in ${filePath}`, { cause: e });
|
|
1113
|
-
}
|
|
1114
|
-
throw new Error("Unknown file type " + filePath);
|
|
1115
|
-
}
|
|
1116
|
-
function onMeta(source, { filePath, query }) {
|
|
1117
|
-
const parsed = querySchema2.safeParse(query);
|
|
1118
|
-
if (!parsed.success || !parsed.data.collection) return null;
|
|
1119
|
-
const collectionName = parsed.data.collection;
|
|
1120
|
-
return async () => {
|
|
1121
|
-
const config = await configLoader2.getConfig();
|
|
1122
|
-
const collection = config.getCollection(collectionName);
|
|
1123
|
-
let metaCollection;
|
|
1124
|
-
switch (collection?.type) {
|
|
1125
|
-
case "meta":
|
|
1126
|
-
metaCollection = collection;
|
|
1127
|
-
break;
|
|
1128
|
-
case "docs":
|
|
1129
|
-
metaCollection = collection.meta;
|
|
1130
|
-
break;
|
|
1131
|
-
}
|
|
1132
|
-
const data = parse2(filePath, source);
|
|
1133
|
-
if (!metaCollection) return data;
|
|
1134
|
-
return configLoader2.core.transformMeta(
|
|
1135
|
-
{
|
|
1136
|
-
collection: metaCollection,
|
|
1137
|
-
filePath,
|
|
1138
|
-
source
|
|
1139
|
-
},
|
|
1140
|
-
data
|
|
1141
|
-
);
|
|
1142
|
-
};
|
|
1143
|
-
}
|
|
1144
|
-
return {
|
|
1145
|
-
test: metaLoaderGlob,
|
|
1146
|
-
async load(input) {
|
|
1147
|
-
const result = onMeta(await input.getSource(), input);
|
|
1148
|
-
if (result === null) return null;
|
|
1149
|
-
const data = await result();
|
|
1150
|
-
if (input.filePath.endsWith(".json")) {
|
|
1151
|
-
return {
|
|
1152
|
-
code: resolveJson === "json" ? JSON.stringify(data) : `export default ${JSON.stringify(data)}`
|
|
1153
|
-
};
|
|
1154
|
-
} else {
|
|
1155
|
-
return {
|
|
1156
|
-
code: resolveYaml === "yaml" ? (0, import_js_yaml2.dump)(data) : `export default ${JSON.stringify(data)}`
|
|
1157
|
-
};
|
|
1158
|
-
}
|
|
1159
|
-
},
|
|
1160
|
-
bun: {
|
|
1161
|
-
load(source, input) {
|
|
1162
|
-
const result = onMeta(source, input);
|
|
1163
|
-
if (result === null)
|
|
1164
|
-
return {
|
|
1165
|
-
loader: "object",
|
|
1166
|
-
exports: parse2(input.filePath, source)
|
|
1167
|
-
};
|
|
1168
|
-
return result().then((data) => ({
|
|
1169
|
-
loader: "object",
|
|
1170
|
-
exports: { default: data }
|
|
1171
|
-
}));
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
};
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
// src/node/loader.ts
|
|
1178
|
-
var core = createCore({
|
|
1179
|
-
environment: "node",
|
|
1180
|
-
configPath: _Defaults.configPath,
|
|
1181
|
-
outDir: _Defaults.outDir
|
|
1182
|
-
});
|
|
1183
|
-
var configLoader = createStandaloneConfigLoader({
|
|
1184
|
-
core,
|
|
1185
|
-
buildConfig: true,
|
|
1186
|
-
mode: "production"
|
|
1187
|
-
});
|
|
1188
|
-
var mdxLoader = toNode(createMdxLoader(configLoader));
|
|
1189
|
-
var metaLoader = toNode(createMetaLoader(configLoader));
|
|
1190
|
-
var load3 = (url, context, nextLoad) => {
|
|
1191
|
-
return mdxLoader(
|
|
1192
|
-
url,
|
|
1193
|
-
context,
|
|
1194
|
-
(v, ctx) => metaLoader(v, { ...context, ...ctx }, nextLoad)
|
|
1195
|
-
);
|
|
1196
|
-
};
|
|
1197
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1198
|
-
0 && (module.exports = {
|
|
1199
|
-
load
|
|
1200
|
-
});
|