fumadocs-mdx 11.2.2 → 11.3.0
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-SZwWfZMp.d.ts → build-mdx-C2hor32E.d.cts} +2 -1
- package/dist/build-mdx-C2hor32E.d.ts +106 -0
- package/dist/{chunk-2KEQHW7J.js → chunk-2ZPSMAUV.js} +33 -54
- package/dist/config/index.cjs +244 -0
- package/dist/config/index.d.cts +134 -0
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +1 -1
- package/dist/index.cjs +98 -0
- package/dist/index.d.cts +17 -0
- package/dist/index.d.ts +2 -10
- package/dist/loader-mdx.cjs +472 -0
- package/dist/loader-mdx.d.cts +18 -0
- package/dist/loader-mdx.d.ts +1 -10
- package/dist/loader-mdx.js +9 -18
- package/dist/mdx-options-L5C3NQRY.js +6 -0
- package/dist/next/index.cjs +556 -0
- package/dist/next/index.d.cts +21 -0
- package/dist/next/index.js +28 -24
- package/package.json +13 -10
- /package/dist/{chunk-MKWJLEE7.js → chunk-6LEQ23AC.js} +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createMDXSource: () => createMDXSource,
|
|
24
|
+
toRuntime: () => toRuntime,
|
|
25
|
+
toRuntimeAsync: () => toRuntimeAsync
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/runtime/resolve-files.ts
|
|
30
|
+
function resolveFiles({
|
|
31
|
+
docs,
|
|
32
|
+
meta,
|
|
33
|
+
rootDir = ""
|
|
34
|
+
}) {
|
|
35
|
+
const outputs = [];
|
|
36
|
+
for (const entry of docs) {
|
|
37
|
+
if (!entry._file.path.startsWith(rootDir)) continue;
|
|
38
|
+
outputs.push({
|
|
39
|
+
type: "page",
|
|
40
|
+
path: entry._file.path,
|
|
41
|
+
data: entry
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
for (const entry of meta) {
|
|
45
|
+
outputs.push({
|
|
46
|
+
type: "meta",
|
|
47
|
+
path: entry._file.path,
|
|
48
|
+
data: entry
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return outputs;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/runtime/index.ts
|
|
55
|
+
function toRuntime(type, file, info) {
|
|
56
|
+
if (type === "doc") {
|
|
57
|
+
const { default: body, frontmatter, ...exports2 } = file;
|
|
58
|
+
return {
|
|
59
|
+
body,
|
|
60
|
+
...exports2,
|
|
61
|
+
...frontmatter,
|
|
62
|
+
_exports: file,
|
|
63
|
+
_file: info
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
...file.default,
|
|
68
|
+
_file: info
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function toRuntimeAsync(frontmatter, load, info) {
|
|
72
|
+
return {
|
|
73
|
+
async load() {
|
|
74
|
+
const { default: body, ...res } = await load();
|
|
75
|
+
return {
|
|
76
|
+
body,
|
|
77
|
+
...res
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
...frontmatter,
|
|
81
|
+
_file: info
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function createMDXSource(docs, meta = []) {
|
|
85
|
+
return {
|
|
86
|
+
files: (rootDir) => resolveFiles({
|
|
87
|
+
docs,
|
|
88
|
+
meta,
|
|
89
|
+
rootDir
|
|
90
|
+
})
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
+
0 && (module.exports = {
|
|
95
|
+
createMDXSource,
|
|
96
|
+
toRuntime,
|
|
97
|
+
toRuntimeAsync
|
|
98
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PageData, MetaData, Source } from 'fumadocs-core/source';
|
|
2
|
+
import { F as FileInfo, B as BaseCollectionEntry } from './build-mdx-C2hor32E.cjs';
|
|
3
|
+
import 'zod';
|
|
4
|
+
import 'mdx/types';
|
|
5
|
+
import 'fumadocs-core/mdx-plugins';
|
|
6
|
+
import 'fumadocs-core/server';
|
|
7
|
+
import '@mdx-js/mdx';
|
|
8
|
+
import 'unified';
|
|
9
|
+
|
|
10
|
+
declare function toRuntime(type: 'doc' | 'meta', file: Record<string, unknown>, info: FileInfo): unknown;
|
|
11
|
+
declare function toRuntimeAsync(frontmatter: Record<string, unknown>, load: () => Promise<Record<string, unknown>>, info: FileInfo): unknown;
|
|
12
|
+
declare function createMDXSource<Doc extends PageData & BaseCollectionEntry, Meta extends MetaData & BaseCollectionEntry>(docs: Doc[], meta?: Meta[]): Source<{
|
|
13
|
+
pageData: Doc;
|
|
14
|
+
metaData: Meta;
|
|
15
|
+
}>;
|
|
16
|
+
|
|
17
|
+
export { createMDXSource, toRuntime, toRuntimeAsync };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { PageData, MetaData, Source } from 'fumadocs-core/source';
|
|
2
|
-
import { F as FileInfo, B as BaseCollectionEntry } from './build-mdx-
|
|
3
|
-
import { MetaFile } from './loader-mdx.js';
|
|
2
|
+
import { F as FileInfo, B as BaseCollectionEntry } from './build-mdx-C2hor32E.js';
|
|
4
3
|
import 'zod';
|
|
5
4
|
import 'mdx/types';
|
|
6
5
|
import 'fumadocs-core/mdx-plugins';
|
|
7
6
|
import 'fumadocs-core/server';
|
|
8
7
|
import '@mdx-js/mdx';
|
|
9
8
|
import 'unified';
|
|
10
|
-
import 'webpack';
|
|
11
9
|
|
|
12
10
|
declare function toRuntime(type: 'doc' | 'meta', file: Record<string, unknown>, info: FileInfo): unknown;
|
|
13
11
|
declare function toRuntimeAsync(frontmatter: Record<string, unknown>, load: () => Promise<Record<string, unknown>>, info: FileInfo): unknown;
|
|
@@ -16,10 +14,4 @@ declare function createMDXSource<Doc extends PageData & BaseCollectionEntry, Met
|
|
|
16
14
|
metaData: Meta;
|
|
17
15
|
}>;
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
files: (MetaFile & {
|
|
21
|
-
collection: string;
|
|
22
|
-
})[];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export { type Manifest, createMDXSource, toRuntime, toRuntimeAsync };
|
|
17
|
+
export { createMDXSource, toRuntime, toRuntimeAsync };
|
|
@@ -0,0 +1,472 @@
|
|
|
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/mdx-plugins/remark-exports.ts
|
|
34
|
+
function remarkMdxExport({ values }) {
|
|
35
|
+
return (tree, vfile) => {
|
|
36
|
+
for (const name of values) {
|
|
37
|
+
if (!(name in vfile.data)) return;
|
|
38
|
+
tree.children.unshift(getMdastExport(name, vfile.data[name]));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function getMdastExport(name, value) {
|
|
43
|
+
return {
|
|
44
|
+
type: "mdxjsEsm",
|
|
45
|
+
value: "",
|
|
46
|
+
data: {
|
|
47
|
+
estree: {
|
|
48
|
+
type: "Program",
|
|
49
|
+
sourceType: "module",
|
|
50
|
+
body: [
|
|
51
|
+
{
|
|
52
|
+
type: "ExportNamedDeclaration",
|
|
53
|
+
specifiers: [],
|
|
54
|
+
source: null,
|
|
55
|
+
declaration: {
|
|
56
|
+
type: "VariableDeclaration",
|
|
57
|
+
kind: "let",
|
|
58
|
+
declarations: [
|
|
59
|
+
{
|
|
60
|
+
type: "VariableDeclarator",
|
|
61
|
+
id: {
|
|
62
|
+
type: "Identifier",
|
|
63
|
+
name
|
|
64
|
+
},
|
|
65
|
+
init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
var import_estree_util_value_to_estree;
|
|
76
|
+
var init_remark_exports = __esm({
|
|
77
|
+
"src/mdx-plugins/remark-exports.ts"() {
|
|
78
|
+
"use strict";
|
|
79
|
+
import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// src/utils/mdx-options.ts
|
|
84
|
+
var mdx_options_exports = {};
|
|
85
|
+
__export(mdx_options_exports, {
|
|
86
|
+
getDefaultMDXOptions: () => getDefaultMDXOptions
|
|
87
|
+
});
|
|
88
|
+
function pluginOption(def, options = []) {
|
|
89
|
+
const list = def(Array.isArray(options) ? options : []).filter(
|
|
90
|
+
Boolean
|
|
91
|
+
);
|
|
92
|
+
if (typeof options === "function") {
|
|
93
|
+
return options(list);
|
|
94
|
+
}
|
|
95
|
+
return list;
|
|
96
|
+
}
|
|
97
|
+
function getDefaultMDXOptions({
|
|
98
|
+
valueToExport = [],
|
|
99
|
+
rehypeCodeOptions,
|
|
100
|
+
remarkImageOptions,
|
|
101
|
+
remarkHeadingOptions,
|
|
102
|
+
remarkStructureOptions,
|
|
103
|
+
...mdxOptions
|
|
104
|
+
}) {
|
|
105
|
+
const mdxExports = [
|
|
106
|
+
"structuredData",
|
|
107
|
+
"frontmatter",
|
|
108
|
+
"lastModified",
|
|
109
|
+
...valueToExport
|
|
110
|
+
];
|
|
111
|
+
const remarkPlugins = pluginOption(
|
|
112
|
+
(v) => [
|
|
113
|
+
import_mdx_plugins.remarkGfm,
|
|
114
|
+
[
|
|
115
|
+
import_mdx_plugins.remarkHeading,
|
|
116
|
+
{
|
|
117
|
+
generateToc: false,
|
|
118
|
+
...remarkHeadingOptions
|
|
119
|
+
}
|
|
120
|
+
],
|
|
121
|
+
remarkImageOptions !== false && [import_mdx_plugins.remarkImage, remarkImageOptions],
|
|
122
|
+
...v,
|
|
123
|
+
remarkStructureOptions !== false && [
|
|
124
|
+
import_mdx_plugins.remarkStructure,
|
|
125
|
+
remarkStructureOptions
|
|
126
|
+
],
|
|
127
|
+
[remarkMdxExport, { values: mdxExports }]
|
|
128
|
+
],
|
|
129
|
+
mdxOptions.remarkPlugins
|
|
130
|
+
);
|
|
131
|
+
const rehypePlugins = pluginOption(
|
|
132
|
+
(v) => [
|
|
133
|
+
rehypeCodeOptions !== false && [import_mdx_plugins.rehypeCode, rehypeCodeOptions],
|
|
134
|
+
...v,
|
|
135
|
+
[import_mdx_plugins.rehypeToc]
|
|
136
|
+
],
|
|
137
|
+
mdxOptions.rehypePlugins
|
|
138
|
+
);
|
|
139
|
+
return {
|
|
140
|
+
...mdxOptions,
|
|
141
|
+
remarkPlugins,
|
|
142
|
+
rehypePlugins
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
var import_mdx_plugins;
|
|
146
|
+
var init_mdx_options = __esm({
|
|
147
|
+
"src/utils/mdx-options.ts"() {
|
|
148
|
+
"use strict";
|
|
149
|
+
import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
150
|
+
init_remark_exports();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// src/loader-mdx.ts
|
|
155
|
+
var loader_mdx_exports = {};
|
|
156
|
+
__export(loader_mdx_exports, {
|
|
157
|
+
default: () => loader
|
|
158
|
+
});
|
|
159
|
+
module.exports = __toCommonJS(loader_mdx_exports);
|
|
160
|
+
var path4 = __toESM(require("path"), 1);
|
|
161
|
+
var import_node_querystring = require("querystring");
|
|
162
|
+
var import_gray_matter2 = __toESM(require("gray-matter"), 1);
|
|
163
|
+
|
|
164
|
+
// src/config/cached.ts
|
|
165
|
+
var import_node_crypto = require("crypto");
|
|
166
|
+
var fs = __toESM(require("fs"), 1);
|
|
167
|
+
|
|
168
|
+
// src/config/load.ts
|
|
169
|
+
var path = __toESM(require("path"), 1);
|
|
170
|
+
var import_node_url = require("url");
|
|
171
|
+
async function loadConfig(configPath) {
|
|
172
|
+
const { build } = await import("esbuild");
|
|
173
|
+
const url = (0, import_node_url.pathToFileURL)(path.resolve(".source/source.config.mjs"));
|
|
174
|
+
const transformed = await build({
|
|
175
|
+
entryPoints: [{ in: configPath, out: "source.config" }],
|
|
176
|
+
bundle: true,
|
|
177
|
+
outdir: ".source",
|
|
178
|
+
target: "node18",
|
|
179
|
+
write: true,
|
|
180
|
+
platform: "node",
|
|
181
|
+
format: "esm",
|
|
182
|
+
packages: "external",
|
|
183
|
+
outExtension: {
|
|
184
|
+
".js": ".mjs"
|
|
185
|
+
},
|
|
186
|
+
allowOverwrite: true
|
|
187
|
+
});
|
|
188
|
+
if (transformed.errors.length > 0) {
|
|
189
|
+
throw new Error("failed to compile configuration file");
|
|
190
|
+
}
|
|
191
|
+
const loaded = await import(`${url.href}?hash=${Date.now().toString()}`);
|
|
192
|
+
const [err, config] = buildConfig(
|
|
193
|
+
// every call to `loadConfig` will cause the previous cache to be ignored
|
|
194
|
+
loaded
|
|
195
|
+
);
|
|
196
|
+
if (err !== null) throw new Error(err);
|
|
197
|
+
return config;
|
|
198
|
+
}
|
|
199
|
+
function buildConfig(config) {
|
|
200
|
+
const collections = /* @__PURE__ */ new Map();
|
|
201
|
+
let globalConfig;
|
|
202
|
+
for (const [k, v] of Object.entries(config)) {
|
|
203
|
+
if (!v) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (typeof v === "object" && "_doc" in v && v._doc === "collections") {
|
|
207
|
+
collections.set(
|
|
208
|
+
k,
|
|
209
|
+
v
|
|
210
|
+
);
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (k === "default") {
|
|
214
|
+
globalConfig = v;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
return [
|
|
218
|
+
`Unknown export "${k}", you can only export collections from source configuration file.`,
|
|
219
|
+
null
|
|
220
|
+
];
|
|
221
|
+
}
|
|
222
|
+
let cachedMdxOptions;
|
|
223
|
+
return [
|
|
224
|
+
null,
|
|
225
|
+
{
|
|
226
|
+
global: globalConfig,
|
|
227
|
+
collections,
|
|
228
|
+
async getDefaultMDXOptions() {
|
|
229
|
+
if (cachedMdxOptions) return cachedMdxOptions;
|
|
230
|
+
const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
|
|
231
|
+
const mdxOptions = globalConfig?.mdxOptions ?? {};
|
|
232
|
+
if (typeof mdxOptions === "function") {
|
|
233
|
+
cachedMdxOptions = getDefaultMDXOptions2(await mdxOptions());
|
|
234
|
+
} else {
|
|
235
|
+
cachedMdxOptions = getDefaultMDXOptions2(mdxOptions);
|
|
236
|
+
}
|
|
237
|
+
return cachedMdxOptions;
|
|
238
|
+
},
|
|
239
|
+
_runtime: {
|
|
240
|
+
files: /* @__PURE__ */ new Map()
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// src/config/cached.ts
|
|
247
|
+
var cache = /* @__PURE__ */ new Map();
|
|
248
|
+
async function loadConfigCached(configPath, hash) {
|
|
249
|
+
const cached = cache.get(configPath);
|
|
250
|
+
if (cached && cached.hash === hash) {
|
|
251
|
+
return await cached.config;
|
|
252
|
+
}
|
|
253
|
+
const config = loadConfig(configPath);
|
|
254
|
+
cache.set(configPath, { config, hash });
|
|
255
|
+
return await config;
|
|
256
|
+
}
|
|
257
|
+
async function getConfigHash(configPath) {
|
|
258
|
+
const hash = (0, import_node_crypto.createHash)("md5");
|
|
259
|
+
const rs = fs.createReadStream(configPath);
|
|
260
|
+
for await (const chunk of rs) {
|
|
261
|
+
hash.update(chunk);
|
|
262
|
+
}
|
|
263
|
+
return hash.digest("hex");
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// src/utils/build-mdx.ts
|
|
267
|
+
var import_mdx = require("@mdx-js/mdx");
|
|
268
|
+
|
|
269
|
+
// src/mdx-plugins/remark-include.ts
|
|
270
|
+
var import_unist_util_visit = require("unist-util-visit");
|
|
271
|
+
var path2 = __toESM(require("path"), 1);
|
|
272
|
+
var fs2 = __toESM(require("fs/promises"), 1);
|
|
273
|
+
var import_gray_matter = __toESM(require("gray-matter"), 1);
|
|
274
|
+
function remarkInclude() {
|
|
275
|
+
return async (tree, file) => {
|
|
276
|
+
const queue = [];
|
|
277
|
+
(0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "paragraph"], (node) => {
|
|
278
|
+
let specifier;
|
|
279
|
+
if (node.type === "paragraph" && node.children.length === 3) {
|
|
280
|
+
const [open, content, closure] = node.children;
|
|
281
|
+
if (open.type === "html" && open.value === "<include>" && content.type === "text" && closure.type === "html" && closure.value === "</include>") {
|
|
282
|
+
specifier = content.value.trim();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (node.type === "mdxJsxFlowElement" && node.name === "include") {
|
|
286
|
+
const child = node.children.at(0);
|
|
287
|
+
if (!child || child.type !== "text") return;
|
|
288
|
+
specifier = child.value;
|
|
289
|
+
}
|
|
290
|
+
if (!specifier) return "skip";
|
|
291
|
+
const targetPath = path2.resolve(path2.dirname(file.path), specifier);
|
|
292
|
+
queue.push(
|
|
293
|
+
fs2.readFile(targetPath).then((content) => {
|
|
294
|
+
const parsed = this.parse((0, import_gray_matter.default)(content).content);
|
|
295
|
+
if (file.data._compiler) {
|
|
296
|
+
file.data._compiler.addDependency(targetPath);
|
|
297
|
+
}
|
|
298
|
+
Object.assign(node, parsed);
|
|
299
|
+
})
|
|
300
|
+
);
|
|
301
|
+
return "skip";
|
|
302
|
+
});
|
|
303
|
+
await Promise.all(queue);
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// src/utils/build-mdx.ts
|
|
308
|
+
var cache2 = /* @__PURE__ */ new Map();
|
|
309
|
+
function cacheKey(group, format) {
|
|
310
|
+
return `${group}:${format}`;
|
|
311
|
+
}
|
|
312
|
+
function buildMDX(group, configHash, source, options = {}) {
|
|
313
|
+
const { filePath, frontmatter, data, ...rest } = options;
|
|
314
|
+
let format = options.format;
|
|
315
|
+
if (!format && filePath) {
|
|
316
|
+
format = filePath.endsWith(".mdx") ? "mdx" : "md";
|
|
317
|
+
}
|
|
318
|
+
format ??= "mdx";
|
|
319
|
+
const key = cacheKey(group, format);
|
|
320
|
+
let cached = cache2.get(key);
|
|
321
|
+
if (cached === void 0 || cached.configHash !== configHash) {
|
|
322
|
+
cached = {
|
|
323
|
+
processor: (0, import_mdx.createProcessor)({
|
|
324
|
+
outputFormat: "program",
|
|
325
|
+
development: process.env.NODE_ENV === "development",
|
|
326
|
+
...rest,
|
|
327
|
+
remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
|
|
328
|
+
format
|
|
329
|
+
}),
|
|
330
|
+
configHash
|
|
331
|
+
};
|
|
332
|
+
cache2.set(key, cached);
|
|
333
|
+
}
|
|
334
|
+
return cached.processor.process({
|
|
335
|
+
value: source,
|
|
336
|
+
path: filePath,
|
|
337
|
+
data: {
|
|
338
|
+
...data,
|
|
339
|
+
frontmatter,
|
|
340
|
+
_compiler: options._compiler
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// src/utils/format-error.ts
|
|
346
|
+
function formatError(message, error) {
|
|
347
|
+
const lines = [];
|
|
348
|
+
function walk(key, { _errors, ...rest }, padStart = 0) {
|
|
349
|
+
if (key !== void 0 || _errors.length > 0) {
|
|
350
|
+
const text = key ? `${key}: ${_errors.join("\n ")}` : _errors.join("\n");
|
|
351
|
+
lines.push(
|
|
352
|
+
text.split("\n").map((line) => `${" ".repeat(padStart)}${line}`).join("\n")
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
for (const [k, v] of Object.entries(rest)) {
|
|
356
|
+
walk(key ? `${key}.${k}` : k, v, padStart + 2);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
walk(void 0, error.format());
|
|
360
|
+
return [message, ...lines].join("\n");
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// src/utils/git-timestamp.ts
|
|
364
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
365
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
366
|
+
var import_cross_spawn = require("cross-spawn");
|
|
367
|
+
var cache3 = /* @__PURE__ */ new Map();
|
|
368
|
+
function getGitTimestamp(file) {
|
|
369
|
+
const cachedTimestamp = cache3.get(file);
|
|
370
|
+
if (cachedTimestamp) return Promise.resolve(cachedTimestamp);
|
|
371
|
+
return new Promise((resolve3, reject) => {
|
|
372
|
+
const cwd = import_node_path.default.dirname(file);
|
|
373
|
+
if (!import_node_fs.default.existsSync(cwd)) {
|
|
374
|
+
resolve3(void 0);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
const fileName = import_node_path.default.basename(file);
|
|
378
|
+
const child = (0, import_cross_spawn.spawn)("git", ["log", "-1", '--pretty="%ai"', fileName], {
|
|
379
|
+
cwd
|
|
380
|
+
});
|
|
381
|
+
let output;
|
|
382
|
+
child.stdout.on("data", (d) => output = new Date(String(d)));
|
|
383
|
+
child.on("close", () => {
|
|
384
|
+
if (output) cache3.set(file, output);
|
|
385
|
+
resolve3(output);
|
|
386
|
+
});
|
|
387
|
+
child.on("error", reject);
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// src/loader-mdx.ts
|
|
392
|
+
function parseQuery(query) {
|
|
393
|
+
let collection;
|
|
394
|
+
let hash;
|
|
395
|
+
const parsed = (0, import_node_querystring.parse)(query.slice(1));
|
|
396
|
+
if (parsed.collection && typeof parsed.collection === "string")
|
|
397
|
+
collection = parsed.collection;
|
|
398
|
+
if (parsed.hash && typeof parsed.hash === "string") hash = parsed.hash;
|
|
399
|
+
return { collection, hash };
|
|
400
|
+
}
|
|
401
|
+
async function loader(source, callback) {
|
|
402
|
+
this.cacheable(true);
|
|
403
|
+
const context = this.context;
|
|
404
|
+
const filePath = this.resourcePath;
|
|
405
|
+
const { _ctx } = this.getOptions();
|
|
406
|
+
const matter2 = (0, import_gray_matter2.default)(source);
|
|
407
|
+
const {
|
|
408
|
+
hash: configHash = await getConfigHash(_ctx.configPath),
|
|
409
|
+
collection: collectionId
|
|
410
|
+
} = parseQuery(this.resourceQuery);
|
|
411
|
+
const config = await loadConfigCached(_ctx.configPath, configHash);
|
|
412
|
+
let collection = collectionId !== void 0 ? config.collections.get(collectionId) : void 0;
|
|
413
|
+
if (collection && collection.type !== "doc") {
|
|
414
|
+
collection = void 0;
|
|
415
|
+
}
|
|
416
|
+
const mdxOptions = collection?.mdxOptions ?? await config.getDefaultMDXOptions();
|
|
417
|
+
let frontmatter = matter2.data;
|
|
418
|
+
if (collection?.schema) {
|
|
419
|
+
let schema = collection.schema;
|
|
420
|
+
if (typeof schema === "function") {
|
|
421
|
+
schema = schema({
|
|
422
|
+
async buildMDX(v, options = mdxOptions) {
|
|
423
|
+
const res = await buildMDX(
|
|
424
|
+
collectionId ?? "global",
|
|
425
|
+
configHash,
|
|
426
|
+
v,
|
|
427
|
+
options
|
|
428
|
+
);
|
|
429
|
+
return String(res.value);
|
|
430
|
+
},
|
|
431
|
+
source,
|
|
432
|
+
path: filePath
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
const result = await schema.safeParseAsync(frontmatter);
|
|
436
|
+
if (result.error) {
|
|
437
|
+
callback(
|
|
438
|
+
new Error(
|
|
439
|
+
formatError(`invalid frontmatter in ${filePath}:`, result.error)
|
|
440
|
+
)
|
|
441
|
+
);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
frontmatter = result.data;
|
|
445
|
+
}
|
|
446
|
+
let timestamp;
|
|
447
|
+
if (config.global?.lastModifiedTime === "git")
|
|
448
|
+
timestamp = (await getGitTimestamp(filePath))?.getTime();
|
|
449
|
+
try {
|
|
450
|
+
const file = await buildMDX(
|
|
451
|
+
collectionId ?? "global",
|
|
452
|
+
configHash,
|
|
453
|
+
matter2.content,
|
|
454
|
+
{
|
|
455
|
+
development: this.mode === "development",
|
|
456
|
+
...mdxOptions,
|
|
457
|
+
filePath,
|
|
458
|
+
frontmatter,
|
|
459
|
+
data: {
|
|
460
|
+
lastModified: timestamp
|
|
461
|
+
},
|
|
462
|
+
_compiler: this
|
|
463
|
+
}
|
|
464
|
+
);
|
|
465
|
+
callback(void 0, String(file.value), file.map ?? void 0);
|
|
466
|
+
} catch (error) {
|
|
467
|
+
if (!(error instanceof Error)) throw error;
|
|
468
|
+
const fpath = path4.relative(context, filePath);
|
|
469
|
+
error.message = `${fpath}:${error.name}: ${error.message}`;
|
|
470
|
+
callback(error);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LoaderContext } from 'webpack';
|
|
2
|
+
|
|
3
|
+
interface Options {
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
_ctx: {
|
|
8
|
+
configPath: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Load MDX/markdown files
|
|
13
|
+
*
|
|
14
|
+
* it supports frontmatter by parsing and injecting the data in `vfile.data.frontmatter`
|
|
15
|
+
*/
|
|
16
|
+
declare function loader(this: LoaderContext<Options>, source: string, callback: LoaderContext<Options>['callback']): Promise<void>;
|
|
17
|
+
|
|
18
|
+
export { type Options, loader as default };
|
package/dist/loader-mdx.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { LoaderContext } from 'webpack';
|
|
2
|
-
import { StructuredData } from 'fumadocs-core/mdx-plugins';
|
|
3
2
|
|
|
4
3
|
interface Options {
|
|
5
4
|
/**
|
|
@@ -9,14 +8,6 @@ interface Options {
|
|
|
9
8
|
configPath: string;
|
|
10
9
|
};
|
|
11
10
|
}
|
|
12
|
-
interface MetaFile {
|
|
13
|
-
path: string;
|
|
14
|
-
data: {
|
|
15
|
-
frontmatter: Record<string, unknown>;
|
|
16
|
-
structuredData?: StructuredData;
|
|
17
|
-
[key: string]: unknown;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
11
|
/**
|
|
21
12
|
* Load MDX/markdown files
|
|
22
13
|
*
|
|
@@ -24,4 +15,4 @@ interface MetaFile {
|
|
|
24
15
|
*/
|
|
25
16
|
declare function loader(this: LoaderContext<Options>, source: string, callback: LoaderContext<Options>['callback']): Promise<void>;
|
|
26
17
|
|
|
27
|
-
export { type
|
|
18
|
+
export { type Options, loader as default };
|