fumadocs-mdx 11.10.1 → 12.0.1
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/bin.cjs +126 -218
- package/dist/bin.js +1 -1
- package/dist/{browser-B2G8uAF2.d.cts → browser-D5lvL8vv.d.ts} +51 -4
- package/dist/{browser-DrH7tKRi.d.ts → browser-DjWADqp8.d.cts} +51 -4
- package/dist/bun/index.cjs +274 -230
- package/dist/bun/index.js +8 -8
- package/dist/chunk-ADR6R7HM.js +29 -0
- package/dist/{chunk-UOOPSLFY.js → chunk-AUOOMFAI.js} +27 -21
- package/dist/chunk-FSZMKRVH.js +80 -0
- package/dist/{chunk-766EAFX6.js → chunk-LGYVNESJ.js} +2 -36
- package/dist/chunk-LMG6UWCL.js +167 -0
- package/dist/chunk-QAUWMR5D.js +142 -0
- package/dist/{chunk-QJCCVMBJ.js → chunk-SP7CHRTS.js} +17 -47
- package/dist/{chunk-QVZ7JH4H.js → chunk-U4MQ44TS.js} +1 -1
- package/dist/{chunk-CNKI574E.js → chunk-VXEBLM4X.js} +1 -1
- package/dist/chunk-XMFLD5J6.js +30 -0
- package/dist/chunk-ZLCSVXCD.js +10 -0
- package/dist/{chunk-XXSKWWMB.js → chunk-ZX7TM4AR.js} +4 -2
- package/dist/config/index.cjs +97 -148
- package/dist/config/index.d.cts +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +48 -9
- package/dist/{define-BH4bnHQl.d.ts → define--6HQ1ehX.d.cts} +18 -3
- package/dist/{define-BH4bnHQl.d.cts → define--6HQ1ehX.d.ts} +18 -3
- package/dist/load-UUXLUBHL.js +9 -0
- package/dist/loader-mdx.cjs +336 -305
- package/dist/loader-mdx.js +8 -8
- package/dist/next/index.cjs +152 -242
- package/dist/next/index.js +52 -66
- package/dist/node/loader.cjs +274 -243
- package/dist/node/loader.js +7 -8
- package/dist/postinstall-SCSXM4IM.js +10 -0
- package/dist/{mdx-options-T73E4LQB.js → preset-ZMP6U62C.js} +1 -1
- package/dist/runtime/next/async.cjs +304 -204
- package/dist/runtime/next/async.d.cts +3 -3
- package/dist/runtime/next/async.d.ts +3 -3
- package/dist/runtime/next/async.js +59 -32
- package/dist/runtime/next/index.cjs +32 -21
- package/dist/runtime/next/index.d.cts +11 -7
- package/dist/runtime/next/index.d.ts +11 -7
- package/dist/runtime/next/index.js +2 -1
- package/dist/runtime/vite/browser.d.cts +2 -3
- package/dist/runtime/vite/browser.d.ts +2 -3
- package/dist/runtime/vite/server.cjs +67 -21
- package/dist/runtime/vite/server.d.cts +14 -28
- package/dist/runtime/vite/server.d.ts +14 -28
- package/dist/runtime/vite/server.js +61 -21
- package/dist/shared-0QIuV0XZ.d.ts +70 -0
- package/dist/shared-CqgMnt9h.d.cts +70 -0
- package/dist/{types-DN9KrG7R.d.ts → types-CFlQxTN8.d.ts} +10 -37
- package/dist/{types-DT83Ijs6.d.cts → types-DkGjw-Uo.d.cts} +10 -37
- package/dist/vite/index.cjs +299 -279
- package/dist/vite/index.d.cts +1 -0
- package/dist/vite/index.d.ts +1 -0
- package/dist/vite/index.js +15 -20
- package/dist/{watcher-4NDMOH4R.js → watcher-HGOH3APP.js} +1 -1
- package/package.json +16 -16
- package/dist/build-mdx-DnC1jKvn.d.cts +0 -46
- package/dist/build-mdx-DnC1jKvn.d.ts +0 -46
- package/dist/chunk-GBMFGEC7.js +0 -57
- package/dist/chunk-QQWCBFFE.js +0 -40
- package/dist/chunk-SMSNZ6N5.js +0 -155
- package/dist/chunk-SVTXMVLQ.js +0 -139
- package/dist/config/zod-3.cjs +0 -422
- package/dist/config/zod-3.d.cts +0 -53
- package/dist/config/zod-3.d.ts +0 -53
- package/dist/config/zod-3.js +0 -40
- package/dist/postinstall-XV4WSHZP.js +0 -9
|
@@ -1,23 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
missingProcessedMarkdown
|
|
3
|
+
} from "./chunk-ZLCSVXCD.js";
|
|
4
|
+
|
|
1
5
|
// src/runtime/next/index.ts
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
var cache = /* @__PURE__ */ new Map();
|
|
6
|
+
import * as fs from "fs/promises";
|
|
4
7
|
var _runtime = {
|
|
5
8
|
doc(files) {
|
|
6
9
|
return files.map((file) => {
|
|
7
|
-
const
|
|
10
|
+
const data = file.data;
|
|
11
|
+
const filePath = file.info.fullPath;
|
|
8
12
|
return {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
info: file.info,
|
|
14
|
+
_exports: data,
|
|
15
|
+
body: data.default,
|
|
16
|
+
lastModified: data.lastModified,
|
|
17
|
+
toc: data.toc,
|
|
18
|
+
structuredData: data.structuredData,
|
|
19
|
+
extractedReferences: data.extractedReferences,
|
|
20
|
+
...data.frontmatter,
|
|
21
|
+
async getText(type) {
|
|
22
|
+
if (type === "raw") {
|
|
23
|
+
return (await fs.readFile(filePath)).toString();
|
|
24
|
+
}
|
|
25
|
+
if (typeof data._markdown !== "string") missingProcessedMarkdown();
|
|
26
|
+
return data._markdown;
|
|
21
27
|
}
|
|
22
28
|
};
|
|
23
29
|
});
|
|
@@ -25,8 +31,8 @@ var _runtime = {
|
|
|
25
31
|
meta(files) {
|
|
26
32
|
return files.map((file) => {
|
|
27
33
|
return {
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
info: file.info,
|
|
35
|
+
...file.data
|
|
30
36
|
};
|
|
31
37
|
});
|
|
32
38
|
},
|
|
@@ -55,16 +61,16 @@ function resolveFiles({ docs, meta }) {
|
|
|
55
61
|
for (const entry of docs) {
|
|
56
62
|
outputs.push({
|
|
57
63
|
type: "page",
|
|
58
|
-
absolutePath: entry.
|
|
59
|
-
path: entry.
|
|
64
|
+
absolutePath: entry.info.fullPath,
|
|
65
|
+
path: entry.info.path,
|
|
60
66
|
data: entry
|
|
61
67
|
});
|
|
62
68
|
}
|
|
63
69
|
for (const entry of meta) {
|
|
64
70
|
outputs.push({
|
|
65
71
|
type: "meta",
|
|
66
|
-
absolutePath: entry.
|
|
67
|
-
path: entry.
|
|
72
|
+
absolutePath: entry.info.fullPath,
|
|
73
|
+
path: entry.info.path,
|
|
68
74
|
data: entry
|
|
69
75
|
});
|
|
70
76
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/loaders/mdx/preset.ts
|
|
2
|
+
import * as plugins from "fumadocs-core/mdx-plugins";
|
|
3
|
+
function pluginOption(def, options = []) {
|
|
4
|
+
const list = def(Array.isArray(options) ? options : []).filter(
|
|
5
|
+
Boolean
|
|
6
|
+
);
|
|
7
|
+
if (typeof options === "function") {
|
|
8
|
+
return options(list);
|
|
9
|
+
}
|
|
10
|
+
return list;
|
|
11
|
+
}
|
|
12
|
+
function getDefaultMDXOptions({
|
|
13
|
+
valueToExport = [],
|
|
14
|
+
rehypeCodeOptions,
|
|
15
|
+
remarkImageOptions,
|
|
16
|
+
remarkHeadingOptions,
|
|
17
|
+
remarkStructureOptions,
|
|
18
|
+
remarkCodeTabOptions,
|
|
19
|
+
remarkNpmOptions,
|
|
20
|
+
_withoutBundler = false,
|
|
21
|
+
...mdxOptions
|
|
22
|
+
}) {
|
|
23
|
+
const remarkPlugins = pluginOption(
|
|
24
|
+
(v) => [
|
|
25
|
+
plugins.remarkGfm,
|
|
26
|
+
[
|
|
27
|
+
plugins.remarkHeading,
|
|
28
|
+
{
|
|
29
|
+
generateToc: false,
|
|
30
|
+
...remarkHeadingOptions
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
remarkImageOptions !== false && [
|
|
34
|
+
plugins.remarkImage,
|
|
35
|
+
{
|
|
36
|
+
...remarkImageOptions,
|
|
37
|
+
useImport: _withoutBundler ? false : remarkImageOptions?.useImport
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
|
|
41
|
+
plugins.remarkCodeTab,
|
|
42
|
+
remarkCodeTabOptions
|
|
43
|
+
],
|
|
44
|
+
"remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
|
|
45
|
+
...v,
|
|
46
|
+
remarkStructureOptions !== false && [
|
|
47
|
+
plugins.remarkStructure,
|
|
48
|
+
remarkStructureOptions
|
|
49
|
+
],
|
|
50
|
+
() => {
|
|
51
|
+
return (_, file) => {
|
|
52
|
+
file.data["mdx-export"] ??= [];
|
|
53
|
+
for (const name of valueToExport) {
|
|
54
|
+
if (name in file.data)
|
|
55
|
+
file.data["mdx-export"].push({ name, value: file.data[name] });
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
mdxOptions.remarkPlugins
|
|
61
|
+
);
|
|
62
|
+
const rehypePlugins = pluginOption(
|
|
63
|
+
(v) => [
|
|
64
|
+
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
|
65
|
+
...v,
|
|
66
|
+
plugins.rehypeToc
|
|
67
|
+
],
|
|
68
|
+
mdxOptions.rehypePlugins
|
|
69
|
+
);
|
|
70
|
+
return {
|
|
71
|
+
...mdxOptions,
|
|
72
|
+
outputFormat: _withoutBundler ? "function-body" : mdxOptions.outputFormat,
|
|
73
|
+
remarkPlugins,
|
|
74
|
+
rehypePlugins
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export {
|
|
79
|
+
getDefaultMDXOptions
|
|
80
|
+
};
|
|
@@ -1,44 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildConfig
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-U4MQ44TS.js";
|
|
4
4
|
|
|
5
|
-
// src/
|
|
5
|
+
// src/loaders/config/load.ts
|
|
6
6
|
import * as fs from "fs/promises";
|
|
7
7
|
import * as path from "path";
|
|
8
8
|
import { pathToFileURL } from "url";
|
|
9
|
-
function findConfigFile() {
|
|
10
|
-
return path.resolve("source.config.ts");
|
|
11
|
-
}
|
|
12
9
|
var cache = null;
|
|
13
|
-
async function isZod3() {
|
|
14
|
-
try {
|
|
15
|
-
const content = JSON.parse(
|
|
16
|
-
(await fs.readFile("node_modules/zod/package.json")).toString()
|
|
17
|
-
);
|
|
18
|
-
const version = content.version;
|
|
19
|
-
return typeof version === "string" && version.startsWith("3.");
|
|
20
|
-
} catch {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function createCompatZodPlugin() {
|
|
25
|
-
return {
|
|
26
|
-
name: "replace-zod-import",
|
|
27
|
-
async setup(build) {
|
|
28
|
-
const usingZod3 = await isZod3();
|
|
29
|
-
if (!usingZod3) return;
|
|
30
|
-
console.warn(
|
|
31
|
-
"[Fumadocs MDX] Noticed Zod v3 in your node_modules, we recommend upgrading to Zod v4 for better compatibility."
|
|
32
|
-
);
|
|
33
|
-
build.onResolve({ filter: /^fumadocs-mdx\/config$/ }, () => {
|
|
34
|
-
return {
|
|
35
|
-
path: "fumadocs-mdx/config/zod-3",
|
|
36
|
-
external: true
|
|
37
|
-
};
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
10
|
async function compileConfig(configPath, outDir) {
|
|
43
11
|
const { build } = await import("esbuild");
|
|
44
12
|
const transformed = await build({
|
|
@@ -50,7 +18,6 @@ async function compileConfig(configPath, outDir) {
|
|
|
50
18
|
platform: "node",
|
|
51
19
|
format: "esm",
|
|
52
20
|
packages: "external",
|
|
53
|
-
plugins: [createCompatZodPlugin()],
|
|
54
21
|
outExtension: {
|
|
55
22
|
".js": ".mjs"
|
|
56
23
|
},
|
|
@@ -84,7 +51,6 @@ async function getConfigHash(configPath) {
|
|
|
84
51
|
}
|
|
85
52
|
|
|
86
53
|
export {
|
|
87
|
-
findConfigFile,
|
|
88
54
|
loadConfig,
|
|
89
55
|
getConfigHash
|
|
90
56
|
};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fumaMatter
|
|
3
|
+
} from "./chunk-VWJKRQZR.js";
|
|
4
|
+
|
|
5
|
+
// src/loaders/mdx/remark-include.ts
|
|
6
|
+
import { unified } from "unified";
|
|
7
|
+
import { visit } from "unist-util-visit";
|
|
8
|
+
import * as path from "path";
|
|
9
|
+
import * as fs from "fs/promises";
|
|
10
|
+
import remarkParse from "remark-parse";
|
|
11
|
+
import remarkMdx from "remark-mdx";
|
|
12
|
+
import { remarkHeading } from "fumadocs-core/mdx-plugins";
|
|
13
|
+
var ElementLikeTypes = [
|
|
14
|
+
"mdxJsxFlowElement",
|
|
15
|
+
"mdxJsxTextElement",
|
|
16
|
+
"containerDirective",
|
|
17
|
+
"textDirective",
|
|
18
|
+
"leafDirective"
|
|
19
|
+
];
|
|
20
|
+
function isElementLike(node) {
|
|
21
|
+
return ElementLikeTypes.includes(node.type);
|
|
22
|
+
}
|
|
23
|
+
function parseElementAttributes(element) {
|
|
24
|
+
if (Array.isArray(element.attributes)) {
|
|
25
|
+
const attributes = {};
|
|
26
|
+
for (const attr of element.attributes) {
|
|
27
|
+
if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
|
|
28
|
+
attributes[attr.name] = attr.value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return attributes;
|
|
32
|
+
}
|
|
33
|
+
return element.attributes ?? {};
|
|
34
|
+
}
|
|
35
|
+
function flattenNode(node) {
|
|
36
|
+
if ("children" in node)
|
|
37
|
+
return node.children.map((child) => flattenNode(child)).join("");
|
|
38
|
+
if ("value" in node) return node.value;
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
function parseSpecifier(specifier) {
|
|
42
|
+
const idx = specifier.lastIndexOf("#");
|
|
43
|
+
if (idx === -1) return { file: specifier };
|
|
44
|
+
return {
|
|
45
|
+
file: specifier.slice(0, idx),
|
|
46
|
+
section: specifier.slice(idx + 1)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function extractSection(root, section) {
|
|
50
|
+
let nodes;
|
|
51
|
+
let capturingHeadingContent = false;
|
|
52
|
+
visit(root, (node) => {
|
|
53
|
+
if (node.type === "heading") {
|
|
54
|
+
if (capturingHeadingContent) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (node.data?.hProperties?.id === section) {
|
|
58
|
+
capturingHeadingContent = true;
|
|
59
|
+
nodes = [node];
|
|
60
|
+
return "skip";
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (capturingHeadingContent) {
|
|
65
|
+
nodes?.push(node);
|
|
66
|
+
return "skip";
|
|
67
|
+
}
|
|
68
|
+
if (isElementLike(node) && node.name === "section") {
|
|
69
|
+
const attributes = parseElementAttributes(node);
|
|
70
|
+
if (attributes.id === section) {
|
|
71
|
+
nodes = node.children;
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
if (nodes)
|
|
77
|
+
return {
|
|
78
|
+
type: "root",
|
|
79
|
+
children: nodes
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function remarkInclude() {
|
|
83
|
+
const TagName = "include";
|
|
84
|
+
async function embedContent(file, heading, params, data) {
|
|
85
|
+
let content;
|
|
86
|
+
try {
|
|
87
|
+
content = (await fs.readFile(file)).toString();
|
|
88
|
+
} catch (e) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`failed to read file ${file}
|
|
91
|
+
${e instanceof Error ? e.message : String(e)}`,
|
|
92
|
+
{ cause: e }
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const ext = path.extname(file);
|
|
96
|
+
data._compiler?.addDependency(file);
|
|
97
|
+
if (params.lang || ext !== ".md" && ext !== ".mdx") {
|
|
98
|
+
const lang = params.lang ?? ext.slice(1);
|
|
99
|
+
return {
|
|
100
|
+
type: "code",
|
|
101
|
+
lang,
|
|
102
|
+
meta: params.meta,
|
|
103
|
+
value: content,
|
|
104
|
+
data: {}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const parser = (data._getProcessor ?? getDefaultProcessor)(
|
|
108
|
+
ext === ".mdx" ? "mdx" : "md"
|
|
109
|
+
);
|
|
110
|
+
const parsed = fumaMatter(content);
|
|
111
|
+
let mdast = parser.parse({
|
|
112
|
+
path: file,
|
|
113
|
+
value: parsed.content,
|
|
114
|
+
data: { frontmatter: parsed.data }
|
|
115
|
+
});
|
|
116
|
+
if (heading) {
|
|
117
|
+
const extracted = extractSection(
|
|
118
|
+
await unified().use(remarkHeading).run(mdast),
|
|
119
|
+
heading
|
|
120
|
+
);
|
|
121
|
+
if (!extracted)
|
|
122
|
+
throw new Error(
|
|
123
|
+
`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.`
|
|
124
|
+
);
|
|
125
|
+
mdast = extracted;
|
|
126
|
+
}
|
|
127
|
+
await update(mdast, path.dirname(file), data);
|
|
128
|
+
return mdast;
|
|
129
|
+
}
|
|
130
|
+
async function update(tree, directory, data) {
|
|
131
|
+
const queue = [];
|
|
132
|
+
visit(tree, ElementLikeTypes, (_node, _, parent) => {
|
|
133
|
+
const node = _node;
|
|
134
|
+
if (node.name !== TagName) return;
|
|
135
|
+
const specifier = flattenNode(node);
|
|
136
|
+
if (specifier.length === 0) return "skip";
|
|
137
|
+
const attributes = parseElementAttributes(node);
|
|
138
|
+
const { file: relativePath, section } = parseSpecifier(specifier);
|
|
139
|
+
const file = path.resolve(
|
|
140
|
+
"cwd" in attributes ? process.cwd() : directory,
|
|
141
|
+
relativePath
|
|
142
|
+
);
|
|
143
|
+
queue.push(
|
|
144
|
+
embedContent(file, section, attributes, data).then((replace) => {
|
|
145
|
+
Object.assign(
|
|
146
|
+
parent && parent.type === "paragraph" ? parent : node,
|
|
147
|
+
replace
|
|
148
|
+
);
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
return "skip";
|
|
152
|
+
});
|
|
153
|
+
await Promise.all(queue);
|
|
154
|
+
}
|
|
155
|
+
return async (tree, file) => {
|
|
156
|
+
await update(tree, path.dirname(file.path), file.data);
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function getDefaultProcessor(format) {
|
|
160
|
+
const mdProcessor = unified().use(remarkParse);
|
|
161
|
+
if (format === "md") return mdProcessor;
|
|
162
|
+
return mdProcessor.use(remarkMdx);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export {
|
|
166
|
+
remarkInclude
|
|
167
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {
|
|
2
|
+
remarkInclude
|
|
3
|
+
} from "./chunk-LMG6UWCL.js";
|
|
4
|
+
|
|
5
|
+
// src/loaders/mdx/build-mdx.ts
|
|
6
|
+
import { createProcessor } from "@mdx-js/mdx";
|
|
7
|
+
|
|
8
|
+
// src/loaders/mdx/remark-postprocess.ts
|
|
9
|
+
import { visit } from "unist-util-visit";
|
|
10
|
+
import { toMarkdown } from "mdast-util-to-markdown";
|
|
11
|
+
import { valueToEstree } from "estree-util-value-to-estree";
|
|
12
|
+
function remarkPostprocess({
|
|
13
|
+
includeProcessedMarkdown = false,
|
|
14
|
+
valueToExport = []
|
|
15
|
+
} = {}) {
|
|
16
|
+
return (tree, file) => {
|
|
17
|
+
let title;
|
|
18
|
+
const urls = [];
|
|
19
|
+
visit(tree, ["heading", "link"], (node) => {
|
|
20
|
+
if (node.type === "heading" && node.depth === 1) {
|
|
21
|
+
title = flattenNode(node);
|
|
22
|
+
}
|
|
23
|
+
if (node.type !== "link") return;
|
|
24
|
+
urls.push({
|
|
25
|
+
href: node.url
|
|
26
|
+
});
|
|
27
|
+
return "skip";
|
|
28
|
+
});
|
|
29
|
+
if (title) {
|
|
30
|
+
file.data.frontmatter ??= {};
|
|
31
|
+
if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
|
|
32
|
+
}
|
|
33
|
+
file.data.extractedReferences = urls;
|
|
34
|
+
if (includeProcessedMarkdown) {
|
|
35
|
+
file.data._markdown = toMarkdown(tree, {
|
|
36
|
+
...this.data("settings"),
|
|
37
|
+
// from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
|
|
38
|
+
extensions: this.data("toMarkdownExtensions") || []
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
for (const { name, value } of file.data["mdx-export"] ?? []) {
|
|
42
|
+
tree.children.unshift(getMdastExport(name, value));
|
|
43
|
+
}
|
|
44
|
+
for (const name of valueToExport) {
|
|
45
|
+
if (!(name in file.data)) continue;
|
|
46
|
+
tree.children.unshift(getMdastExport(name, file.data[name]));
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function getMdastExport(name, value) {
|
|
51
|
+
return {
|
|
52
|
+
type: "mdxjsEsm",
|
|
53
|
+
value: "",
|
|
54
|
+
data: {
|
|
55
|
+
estree: {
|
|
56
|
+
type: "Program",
|
|
57
|
+
sourceType: "module",
|
|
58
|
+
body: [
|
|
59
|
+
{
|
|
60
|
+
type: "ExportNamedDeclaration",
|
|
61
|
+
attributes: [],
|
|
62
|
+
specifiers: [],
|
|
63
|
+
source: null,
|
|
64
|
+
declaration: {
|
|
65
|
+
type: "VariableDeclaration",
|
|
66
|
+
kind: "let",
|
|
67
|
+
declarations: [
|
|
68
|
+
{
|
|
69
|
+
type: "VariableDeclarator",
|
|
70
|
+
id: {
|
|
71
|
+
type: "Identifier",
|
|
72
|
+
name
|
|
73
|
+
},
|
|
74
|
+
init: valueToEstree(value)
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function flattenNode(node) {
|
|
85
|
+
if ("children" in node)
|
|
86
|
+
return node.children.map((child) => flattenNode(child)).join("");
|
|
87
|
+
if ("value" in node) return node.value;
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/loaders/mdx/build-mdx.ts
|
|
92
|
+
var cache = /* @__PURE__ */ new Map();
|
|
93
|
+
async function buildMDX(cacheKey, source, options) {
|
|
94
|
+
const { filePath, frontmatter, data, _compiler, ...rest } = options;
|
|
95
|
+
function getProcessor(format) {
|
|
96
|
+
const key = `${cacheKey}:${format}`;
|
|
97
|
+
let processor = cache.get(key);
|
|
98
|
+
if (!processor) {
|
|
99
|
+
processor = createProcessor({
|
|
100
|
+
outputFormat: "program",
|
|
101
|
+
...rest,
|
|
102
|
+
remarkPlugins: [
|
|
103
|
+
remarkInclude,
|
|
104
|
+
...rest.remarkPlugins ?? [],
|
|
105
|
+
[
|
|
106
|
+
remarkPostprocess,
|
|
107
|
+
{
|
|
108
|
+
...options.postprocess,
|
|
109
|
+
valueToExport: [
|
|
110
|
+
...options.postprocess?.valueToExport ?? [],
|
|
111
|
+
"structuredData",
|
|
112
|
+
"extractedReferences",
|
|
113
|
+
"frontmatter",
|
|
114
|
+
"lastModified",
|
|
115
|
+
"_markdown"
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
],
|
|
120
|
+
format
|
|
121
|
+
});
|
|
122
|
+
cache.set(key, processor);
|
|
123
|
+
}
|
|
124
|
+
return processor;
|
|
125
|
+
}
|
|
126
|
+
return getProcessor(
|
|
127
|
+
options.format ?? (filePath.endsWith(".mdx") ? "mdx" : "md")
|
|
128
|
+
).process({
|
|
129
|
+
value: source,
|
|
130
|
+
path: filePath,
|
|
131
|
+
data: {
|
|
132
|
+
...data,
|
|
133
|
+
frontmatter,
|
|
134
|
+
_compiler,
|
|
135
|
+
_getProcessor: getProcessor
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
buildMDX
|
|
142
|
+
};
|
|
@@ -1,28 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildMDX
|
|
3
|
-
} from "./chunk-QQWCBFFE.js";
|
|
4
1
|
import {
|
|
5
2
|
getGitTimestamp,
|
|
6
3
|
validate
|
|
7
4
|
} from "./chunk-IQAEAI4P.js";
|
|
8
5
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from "./chunk-766EAFX6.js";
|
|
6
|
+
buildMDX
|
|
7
|
+
} from "./chunk-QAUWMR5D.js";
|
|
12
8
|
import {
|
|
13
9
|
fumaMatter
|
|
14
10
|
} from "./chunk-VWJKRQZR.js";
|
|
15
11
|
|
|
16
|
-
// src/
|
|
17
|
-
function countLines(s) {
|
|
18
|
-
let num = 0;
|
|
19
|
-
for (const c of s) {
|
|
20
|
-
if (c === "\n") num++;
|
|
21
|
-
}
|
|
22
|
-
return num;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// src/loaders/mdx.ts
|
|
12
|
+
// src/loaders/mdx/index.ts
|
|
26
13
|
import { z } from "zod";
|
|
27
14
|
import fs from "fs/promises";
|
|
28
15
|
import path from "path";
|
|
@@ -57,21 +44,18 @@ function createMdxLoader(configLoader) {
|
|
|
57
44
|
if (cached && cached.hash === generateCacheHash(value)) return cached;
|
|
58
45
|
}
|
|
59
46
|
const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
|
|
60
|
-
let
|
|
61
|
-
let mdxOptions;
|
|
47
|
+
let docCollection;
|
|
62
48
|
switch (collection?.type) {
|
|
63
49
|
case "doc":
|
|
64
|
-
|
|
65
|
-
schema = collection.schema;
|
|
50
|
+
docCollection = collection;
|
|
66
51
|
break;
|
|
67
52
|
case "docs":
|
|
68
|
-
|
|
69
|
-
schema = collection.docs.schema;
|
|
53
|
+
docCollection = collection.docs;
|
|
70
54
|
break;
|
|
71
55
|
}
|
|
72
|
-
if (schema) {
|
|
56
|
+
if (docCollection?.schema) {
|
|
73
57
|
matter.data = await validate(
|
|
74
|
-
schema,
|
|
58
|
+
docCollection.schema,
|
|
75
59
|
matter.data,
|
|
76
60
|
{
|
|
77
61
|
source: value,
|
|
@@ -96,7 +80,8 @@ function createMdxLoader(configLoader) {
|
|
|
96
80
|
"\n".repeat(lineOffset) + matter.content,
|
|
97
81
|
{
|
|
98
82
|
development: isDevelopment,
|
|
99
|
-
...mdxOptions ?? await loaded.getDefaultMDXOptions(),
|
|
83
|
+
...docCollection?.mdxOptions ?? await loaded.getDefaultMDXOptions(),
|
|
84
|
+
postprocess: docCollection?.postprocess,
|
|
100
85
|
data,
|
|
101
86
|
filePath,
|
|
102
87
|
frontmatter: matter.data,
|
|
@@ -123,29 +108,14 @@ function createMdxLoader(configLoader) {
|
|
|
123
108
|
function generateCacheHash(input) {
|
|
124
109
|
return createHash("md5").update(input).digest("hex");
|
|
125
110
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
function dynamicConfig(configPath, outDir) {
|
|
136
|
-
return {
|
|
137
|
-
async getConfig(hash) {
|
|
138
|
-
return loadConfig(
|
|
139
|
-
configPath,
|
|
140
|
-
outDir,
|
|
141
|
-
hash ?? await getConfigHash(configPath)
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
111
|
+
function countLines(s) {
|
|
112
|
+
let num = 0;
|
|
113
|
+
for (const c of s) {
|
|
114
|
+
if (c === "\n") num++;
|
|
115
|
+
}
|
|
116
|
+
return num;
|
|
145
117
|
}
|
|
146
118
|
|
|
147
119
|
export {
|
|
148
|
-
createMdxLoader
|
|
149
|
-
resolvedConfig,
|
|
150
|
-
dynamicConfig
|
|
120
|
+
createMdxLoader
|
|
151
121
|
};
|
|
@@ -34,7 +34,7 @@ function buildConfig(config) {
|
|
|
34
34
|
const input = this.global.mdxOptions;
|
|
35
35
|
async function uncached() {
|
|
36
36
|
const options = typeof input === "function" ? await input() : input;
|
|
37
|
-
const { getDefaultMDXOptions } = await import("./
|
|
37
|
+
const { getDefaultMDXOptions } = await import("./preset-ZMP6U62C.js");
|
|
38
38
|
if (options?.preset === "minimal") return options;
|
|
39
39
|
return getDefaultMDXOptions({
|
|
40
40
|
...options,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/loaders/config/index.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
function findConfigFile() {
|
|
4
|
+
return path.resolve("source.config.ts");
|
|
5
|
+
}
|
|
6
|
+
function resolvedConfig(loaded) {
|
|
7
|
+
return {
|
|
8
|
+
getConfig() {
|
|
9
|
+
return loaded;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function dynamicConfig(configPath, outDir) {
|
|
14
|
+
return {
|
|
15
|
+
async getConfig(hash) {
|
|
16
|
+
const { loadConfig, getConfigHash } = await import("./load-UUXLUBHL.js");
|
|
17
|
+
return loadConfig(
|
|
18
|
+
configPath,
|
|
19
|
+
outDir,
|
|
20
|
+
hash ?? await getConfigHash(configPath)
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
findConfigFile,
|
|
28
|
+
resolvedConfig,
|
|
29
|
+
dynamicConfig
|
|
30
|
+
};
|