fumadocs-mdx 13.0.7 → 14.0.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/bin.cjs +927 -904
- package/dist/bin.js +3 -3
- package/dist/build-mdx-6UAK5FF5.js +8 -0
- package/dist/bun/index.cjs +592 -481
- package/dist/bun/index.d.cts +3 -2
- package/dist/bun/index.d.ts +3 -2
- package/dist/bun/index.js +12 -12
- package/dist/chunk-4JSFLXXT.js +8 -0
- package/dist/chunk-5UMZCWKV.js +17 -0
- package/dist/chunk-5YXP7JLN.js +138 -0
- package/dist/{chunk-2E2JCOSO.js → chunk-6NISOLQ6.js} +16 -44
- package/dist/chunk-7L2KNF6B.js +180 -0
- package/dist/chunk-E5DJTSIM.js +86 -0
- package/dist/{chunk-K5ZLPEIQ.js → chunk-FBLMK4RS.js} +9 -6
- package/dist/{chunk-QXHN25N3.js → chunk-OXSRIWQW.js} +7 -8
- package/dist/chunk-PKI7ZDA5.js +29 -0
- package/dist/{chunk-3J3WL7WN.js → chunk-SLY7WXTX.js} +71 -58
- package/dist/{chunk-ETIN2W7C.js → chunk-SRSRFOVI.js} +22 -19
- package/dist/chunk-TYJDYTKH.js +85 -0
- package/dist/chunk-XHJCLBZ4.js +406 -0
- package/dist/{chunk-2HXTGJBI.js → chunk-ZY6UZ7NH.js} +22 -19
- package/dist/config/index.cjs +79 -71
- package/dist/config/index.d.cts +2 -1
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.js +5 -5
- package/dist/index-BlVBvy-z.d.ts +8 -0
- package/dist/{core-HkAVGq_a.d.cts → index-D7JdSMpp.d.cts} +99 -61
- package/dist/{core-HkAVGq_a.d.ts → index-D7JdSMpp.d.ts} +99 -61
- package/dist/index-P2NNUkHn.d.cts +8 -0
- package/dist/index.d.cts +3 -74
- package/dist/index.d.ts +3 -74
- package/dist/load-from-file-I3ALLIVB.js +8 -0
- package/dist/next/index.cjs +698 -476
- package/dist/next/index.d.cts +11 -1
- package/dist/next/index.d.ts +11 -1
- package/dist/next/index.js +78 -281
- package/dist/node/loader.cjs +705 -603
- package/dist/node/loader.js +10 -11
- package/dist/plugins/index-file.cjs +471 -0
- package/dist/plugins/index-file.d.cts +29 -0
- package/dist/plugins/index-file.d.ts +29 -0
- package/dist/plugins/index-file.js +8 -0
- package/dist/plugins/json-schema.d.cts +3 -2
- package/dist/plugins/json-schema.d.ts +3 -2
- package/dist/plugins/last-modified.cjs +75 -0
- package/dist/plugins/last-modified.d.cts +27 -0
- package/dist/plugins/last-modified.d.ts +27 -0
- package/dist/plugins/last-modified.js +44 -0
- package/dist/runtime/{vite/browser.cjs → browser.cjs} +40 -53
- package/dist/runtime/browser.d.cts +50 -0
- package/dist/runtime/browser.d.ts +50 -0
- package/dist/runtime/browser.js +68 -0
- package/dist/runtime/dynamic.cjs +985 -0
- package/dist/runtime/dynamic.d.cts +27 -0
- package/dist/runtime/dynamic.d.ts +27 -0
- package/dist/runtime/dynamic.js +78 -0
- package/dist/runtime/server.cjs +173 -0
- package/dist/runtime/server.d.cts +161 -0
- package/dist/runtime/server.d.ts +161 -0
- package/dist/runtime/server.js +8 -0
- package/dist/vite/index.cjs +935 -639
- package/dist/vite/index.d.cts +12 -22
- package/dist/vite/index.d.ts +12 -22
- package/dist/vite/index.js +30 -221
- package/dist/webpack/mdx.cjs +614 -515
- package/dist/webpack/mdx.d.cts +9 -1
- package/dist/webpack/mdx.d.ts +9 -1
- package/dist/webpack/mdx.js +12 -17
- package/dist/webpack/meta.cjs +328 -234
- package/dist/webpack/meta.d.cts +9 -1
- package/dist/webpack/meta.d.ts +9 -1
- package/dist/webpack/meta.js +13 -15
- package/package.json +15 -32
- package/dist/build-mdx-BnJhW5O1.d.cts +0 -53
- package/dist/build-mdx-DNzfRRlY.d.ts +0 -53
- package/dist/chunk-2AQRQXSO.js +0 -119
- package/dist/chunk-4757L6ST.js +0 -77
- package/dist/chunk-CXA4JO4Z.js +0 -45
- package/dist/chunk-FSZMKRVH.js +0 -80
- package/dist/chunk-II3H5ZVZ.js +0 -77
- package/dist/chunk-KILFIBVW.js +0 -75
- package/dist/chunk-NVRDCY6Z.js +0 -30
- package/dist/chunk-VUEZTR2H.js +0 -26
- package/dist/index-D7s7kCc2.d.cts +0 -7
- package/dist/index-D7s7kCc2.d.ts +0 -7
- package/dist/load-from-file-AVYOFOI7.js +0 -7
- package/dist/preset-ZMP6U62C.js +0 -6
- package/dist/runtime/next/async.cjs +0 -760
- package/dist/runtime/next/async.d.cts +0 -19
- package/dist/runtime/next/async.d.ts +0 -19
- package/dist/runtime/next/async.js +0 -86
- package/dist/runtime/next/index.cjs +0 -136
- package/dist/runtime/next/index.d.cts +0 -33
- package/dist/runtime/next/index.d.ts +0 -33
- package/dist/runtime/next/index.js +0 -11
- package/dist/runtime/vite/browser.d.cts +0 -59
- package/dist/runtime/vite/browser.d.ts +0 -59
- package/dist/runtime/vite/browser.js +0 -11
- package/dist/runtime/vite/server.cjs +0 -243
- package/dist/runtime/vite/server.d.cts +0 -30
- package/dist/runtime/vite/server.d.ts +0 -30
- package/dist/runtime/vite/server.js +0 -111
- package/dist/types-By6wKOnT.d.cts +0 -45
- package/dist/types-DgD5Omj2.d.ts +0 -45
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readFileWithCache
|
|
3
|
+
} from "./chunk-PKI7ZDA5.js";
|
|
4
|
+
import {
|
|
5
|
+
fumaMatter
|
|
6
|
+
} from "./chunk-VWJKRQZR.js";
|
|
7
|
+
|
|
8
|
+
// src/plugins/index-file.ts
|
|
9
|
+
import path2 from "path";
|
|
10
|
+
|
|
11
|
+
// src/utils/codegen/index.ts
|
|
12
|
+
import path from "path";
|
|
13
|
+
import { glob } from "tinyglobby";
|
|
14
|
+
function createCodegen({
|
|
15
|
+
target = "default",
|
|
16
|
+
outDir = "",
|
|
17
|
+
jsExtension = false,
|
|
18
|
+
globCache = /* @__PURE__ */ new Map()
|
|
19
|
+
}) {
|
|
20
|
+
let eagerImportId = 0;
|
|
21
|
+
const banner = ["// @ts-nocheck"];
|
|
22
|
+
if (target === "vite") {
|
|
23
|
+
banner.push('/// <reference types="vite/client" />');
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
options: {
|
|
27
|
+
target,
|
|
28
|
+
outDir
|
|
29
|
+
},
|
|
30
|
+
lines: [],
|
|
31
|
+
addImport(statement) {
|
|
32
|
+
this.lines.unshift(statement);
|
|
33
|
+
},
|
|
34
|
+
async pushAsync(insert) {
|
|
35
|
+
for (const line of await Promise.all(insert)) {
|
|
36
|
+
if (line === void 0) continue;
|
|
37
|
+
this.lines.push(line);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
async generateGlobImport(patterns, options) {
|
|
41
|
+
if (target === "vite") {
|
|
42
|
+
return this.generateViteGlobImport(patterns, options);
|
|
43
|
+
}
|
|
44
|
+
return this.generateNodeGlobImport(patterns, options);
|
|
45
|
+
},
|
|
46
|
+
generateViteGlobImport(patterns, { base, ...rest }) {
|
|
47
|
+
patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
|
|
48
|
+
normalizeViteGlobPath
|
|
49
|
+
);
|
|
50
|
+
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
51
|
+
{
|
|
52
|
+
base: normalizeViteGlobPath(path.relative(outDir, base)),
|
|
53
|
+
...rest
|
|
54
|
+
},
|
|
55
|
+
null,
|
|
56
|
+
2
|
|
57
|
+
)})`;
|
|
58
|
+
},
|
|
59
|
+
async generateNodeGlobImport(patterns, {
|
|
60
|
+
base,
|
|
61
|
+
eager = false,
|
|
62
|
+
query = {},
|
|
63
|
+
import: importName
|
|
64
|
+
}) {
|
|
65
|
+
const cacheKey = JSON.stringify({ patterns, base });
|
|
66
|
+
let files = globCache.get(cacheKey);
|
|
67
|
+
if (!files) {
|
|
68
|
+
files = glob(patterns, {
|
|
69
|
+
cwd: base
|
|
70
|
+
});
|
|
71
|
+
globCache.set(cacheKey, files);
|
|
72
|
+
}
|
|
73
|
+
let code = "{";
|
|
74
|
+
for (const item of await files) {
|
|
75
|
+
const fullPath = path.join(base, item);
|
|
76
|
+
const searchParams = new URLSearchParams();
|
|
77
|
+
for (const [k, v] of Object.entries(query)) {
|
|
78
|
+
searchParams.set(k, v);
|
|
79
|
+
}
|
|
80
|
+
const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
|
|
81
|
+
if (eager) {
|
|
82
|
+
const name = `__fd_glob_${eagerImportId++}`;
|
|
83
|
+
this.lines.unshift(
|
|
84
|
+
importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
|
|
85
|
+
);
|
|
86
|
+
code += `${JSON.stringify(item)}: ${name}, `;
|
|
87
|
+
} else {
|
|
88
|
+
let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
|
|
89
|
+
if (importName) {
|
|
90
|
+
line += `.then(mod => mod.${importName})`;
|
|
91
|
+
}
|
|
92
|
+
code += `${line}, `;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
code += "}";
|
|
96
|
+
return code;
|
|
97
|
+
},
|
|
98
|
+
formatImportPath(file) {
|
|
99
|
+
const ext = path.extname(file);
|
|
100
|
+
let filename;
|
|
101
|
+
if (ext === ".ts" && jsExtension) {
|
|
102
|
+
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
103
|
+
} else if (ext === ".ts") {
|
|
104
|
+
filename = file.substring(0, file.length - ext.length);
|
|
105
|
+
} else {
|
|
106
|
+
filename = file;
|
|
107
|
+
}
|
|
108
|
+
const importPath = slash(path.relative(outDir, filename));
|
|
109
|
+
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
110
|
+
},
|
|
111
|
+
toString() {
|
|
112
|
+
return [...banner, ...this.lines].join("\n");
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function normalizeViteGlobPath(file) {
|
|
117
|
+
file = slash(file);
|
|
118
|
+
if (file.startsWith("./")) return file;
|
|
119
|
+
if (file.startsWith("/")) return `.${file}`;
|
|
120
|
+
return `./${file}`;
|
|
121
|
+
}
|
|
122
|
+
function slash(path3) {
|
|
123
|
+
const isExtendedLengthPath = path3.startsWith("\\\\?\\");
|
|
124
|
+
if (isExtendedLengthPath) {
|
|
125
|
+
return path3;
|
|
126
|
+
}
|
|
127
|
+
return path3.replaceAll("\\", "/");
|
|
128
|
+
}
|
|
129
|
+
function ident(code, tab = 1) {
|
|
130
|
+
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/plugins/index-file.ts
|
|
134
|
+
import { glob as glob2 } from "tinyglobby";
|
|
135
|
+
import { createHash } from "crypto";
|
|
136
|
+
function indexFile(options = {}) {
|
|
137
|
+
const {
|
|
138
|
+
target = "default",
|
|
139
|
+
addJsExtension,
|
|
140
|
+
browser = true,
|
|
141
|
+
dynamic = true
|
|
142
|
+
} = options;
|
|
143
|
+
let config;
|
|
144
|
+
let dynamicCollections;
|
|
145
|
+
function isDynamic(collection) {
|
|
146
|
+
return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
name: "index-file",
|
|
150
|
+
config(v) {
|
|
151
|
+
config = v;
|
|
152
|
+
dynamicCollections = config.collectionList.filter(isDynamic);
|
|
153
|
+
},
|
|
154
|
+
configureServer(server) {
|
|
155
|
+
if (!server.watcher) return;
|
|
156
|
+
server.watcher.on("all", async (event, file) => {
|
|
157
|
+
if (dynamicCollections.length === 0) {
|
|
158
|
+
if (target === "vite") return;
|
|
159
|
+
if (target === "default" && event === "change") return;
|
|
160
|
+
}
|
|
161
|
+
const updatedCollection = config.collectionList.find(
|
|
162
|
+
(collection) => collection.hasFile(file)
|
|
163
|
+
);
|
|
164
|
+
if (!updatedCollection) return;
|
|
165
|
+
if (!isDynamic(updatedCollection)) {
|
|
166
|
+
if (target === "vite") return;
|
|
167
|
+
if (target === "default" && event === "change") return;
|
|
168
|
+
}
|
|
169
|
+
await this.core.emitAndWrite({
|
|
170
|
+
filterPlugin: (plugin) => plugin.name === "index-file"
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
async emit() {
|
|
175
|
+
const globCache = /* @__PURE__ */ new Map();
|
|
176
|
+
const makeCodeGen = () => createCodegen({
|
|
177
|
+
target,
|
|
178
|
+
outDir: this.outDir,
|
|
179
|
+
jsExtension: addJsExtension,
|
|
180
|
+
globCache
|
|
181
|
+
});
|
|
182
|
+
async function toEmitEntry(path3, content) {
|
|
183
|
+
return {
|
|
184
|
+
path: path3,
|
|
185
|
+
content: await content
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const out = [
|
|
189
|
+
toEmitEntry(
|
|
190
|
+
"server.ts",
|
|
191
|
+
generateServerIndexFile(makeCodeGen(), config, this.configPath)
|
|
192
|
+
)
|
|
193
|
+
];
|
|
194
|
+
if (dynamic)
|
|
195
|
+
out.push(
|
|
196
|
+
toEmitEntry(
|
|
197
|
+
"dynamic.ts",
|
|
198
|
+
generateDynamicIndexFile(this.core, makeCodeGen())
|
|
199
|
+
)
|
|
200
|
+
);
|
|
201
|
+
if (browser)
|
|
202
|
+
out.push(
|
|
203
|
+
toEmitEntry(
|
|
204
|
+
"browser.ts",
|
|
205
|
+
generateBrowserIndexFile(makeCodeGen(), config, this.configPath)
|
|
206
|
+
)
|
|
207
|
+
);
|
|
208
|
+
return await Promise.all(out);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
async function generateServerIndexFile(codegen, config, configPath) {
|
|
213
|
+
codegen.lines.push(
|
|
214
|
+
`import { fromConfig } from 'fumadocs-mdx/runtime/server';`,
|
|
215
|
+
`import type * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
216
|
+
"",
|
|
217
|
+
`const create = fromConfig<typeof Config>();`
|
|
218
|
+
);
|
|
219
|
+
async function generateCollectionObject(collection) {
|
|
220
|
+
switch (collection.type) {
|
|
221
|
+
case "docs": {
|
|
222
|
+
if (collection.docs.dynamic) return;
|
|
223
|
+
if (collection.docs.async) {
|
|
224
|
+
const [metaGlob2, headGlob, bodyGlob] = await Promise.all([
|
|
225
|
+
generateMetaCollectionGlob(codegen, collection.meta, true),
|
|
226
|
+
generateDocCollectionFrontmatterGlob(
|
|
227
|
+
codegen,
|
|
228
|
+
collection.docs,
|
|
229
|
+
true
|
|
230
|
+
),
|
|
231
|
+
generateDocCollectionGlob(codegen, collection.docs)
|
|
232
|
+
]);
|
|
233
|
+
return `await create.docsLazy("${collection.name}", "${collection.dir}", ${metaGlob2}, ${headGlob}, ${bodyGlob})`;
|
|
234
|
+
}
|
|
235
|
+
const [metaGlob, docGlob] = await Promise.all([
|
|
236
|
+
generateMetaCollectionGlob(codegen, collection.meta, true),
|
|
237
|
+
generateDocCollectionGlob(codegen, collection.docs, true)
|
|
238
|
+
]);
|
|
239
|
+
return `await create.docs("${collection.name}", "${collection.dir}", ${metaGlob}, ${docGlob})`;
|
|
240
|
+
}
|
|
241
|
+
case "doc":
|
|
242
|
+
if (collection.dynamic) return;
|
|
243
|
+
if (collection.async) {
|
|
244
|
+
const [headGlob, bodyGlob] = await Promise.all([
|
|
245
|
+
generateDocCollectionFrontmatterGlob(codegen, collection, true),
|
|
246
|
+
generateDocCollectionGlob(codegen, collection)
|
|
247
|
+
]);
|
|
248
|
+
return `await create.docLazy("${collection.name}", "${collection.dir}", ${headGlob}, ${bodyGlob})`;
|
|
249
|
+
}
|
|
250
|
+
return `await create.doc("${collection.name}", "${collection.dir}", ${await generateDocCollectionGlob(
|
|
251
|
+
codegen,
|
|
252
|
+
collection,
|
|
253
|
+
true
|
|
254
|
+
)})`;
|
|
255
|
+
case "meta":
|
|
256
|
+
return `await create.meta("${collection.name}", "${collection.dir}", ${await generateMetaCollectionGlob(
|
|
257
|
+
codegen,
|
|
258
|
+
collection,
|
|
259
|
+
true
|
|
260
|
+
)})`;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
await codegen.pushAsync(
|
|
264
|
+
config.collectionList.map(async (collection) => {
|
|
265
|
+
const obj = await generateCollectionObject(collection);
|
|
266
|
+
if (!obj) return;
|
|
267
|
+
return `
|
|
268
|
+
export const ${collection.name} = ${obj};`;
|
|
269
|
+
})
|
|
270
|
+
);
|
|
271
|
+
return codegen.toString();
|
|
272
|
+
}
|
|
273
|
+
async function generateDynamicIndexFile(core, codegen) {
|
|
274
|
+
const { configPath } = core._options;
|
|
275
|
+
codegen.lines.push(
|
|
276
|
+
`import { fromConfigDynamic } from 'fumadocs-mdx/runtime/dynamic';`,
|
|
277
|
+
`import * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
278
|
+
"",
|
|
279
|
+
`const create = await fromConfigDynamic(Config);`
|
|
280
|
+
);
|
|
281
|
+
async function generateCollectionObjectEntry(collection, file) {
|
|
282
|
+
const fullPath = path2.join(collection.dir, file);
|
|
283
|
+
const content = await readFileWithCache(fullPath).catch(() => "");
|
|
284
|
+
const parsed = fumaMatter(content);
|
|
285
|
+
const data = await core.transformFrontmatter(
|
|
286
|
+
{
|
|
287
|
+
collection,
|
|
288
|
+
filePath: fullPath,
|
|
289
|
+
source: content
|
|
290
|
+
},
|
|
291
|
+
parsed.data
|
|
292
|
+
);
|
|
293
|
+
const hash = createHash("md5").update(content).digest("hex");
|
|
294
|
+
const infoStr = [
|
|
295
|
+
// make sure it's included in vercel/nft
|
|
296
|
+
`absolutePath: path.resolve(${JSON.stringify(fullPath)})`
|
|
297
|
+
];
|
|
298
|
+
for (const [k, v] of Object.entries({
|
|
299
|
+
info: {
|
|
300
|
+
fullPath,
|
|
301
|
+
path: file
|
|
302
|
+
},
|
|
303
|
+
data,
|
|
304
|
+
hash
|
|
305
|
+
})) {
|
|
306
|
+
infoStr.push(`${k}: ${JSON.stringify(v)}`);
|
|
307
|
+
}
|
|
308
|
+
return `{ ${infoStr.join(", ")} }`;
|
|
309
|
+
}
|
|
310
|
+
async function generateCollectionObject(parent) {
|
|
311
|
+
let collection;
|
|
312
|
+
if (parent.type === "doc") collection = parent;
|
|
313
|
+
else if (parent.type === "docs") collection = parent.docs;
|
|
314
|
+
if (!collection || !collection.dynamic) return;
|
|
315
|
+
const files = await glob2(collection.patterns, {
|
|
316
|
+
cwd: collection.dir
|
|
317
|
+
});
|
|
318
|
+
const entries = await Promise.all(
|
|
319
|
+
files.map((file) => generateCollectionObjectEntry(collection, file))
|
|
320
|
+
);
|
|
321
|
+
switch (parent.type) {
|
|
322
|
+
case "docs": {
|
|
323
|
+
const metaGlob = await generateMetaCollectionGlob(
|
|
324
|
+
codegen,
|
|
325
|
+
parent.meta,
|
|
326
|
+
true
|
|
327
|
+
);
|
|
328
|
+
return `await create.docs("${parent.name}", "${parent.dir}", ${metaGlob}, ${entries.join(", ")})`;
|
|
329
|
+
}
|
|
330
|
+
case "doc":
|
|
331
|
+
return `await create.doc("${collection.name}", "${collection.dir}", ${entries.join(", ")})`;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
await codegen.pushAsync(
|
|
335
|
+
core.getConfig().collectionList.map(async (collection) => {
|
|
336
|
+
const obj = await generateCollectionObject(collection);
|
|
337
|
+
if (!obj) return;
|
|
338
|
+
return `
|
|
339
|
+
export const ${collection.name} = ${obj};`;
|
|
340
|
+
})
|
|
341
|
+
);
|
|
342
|
+
return codegen.toString();
|
|
343
|
+
}
|
|
344
|
+
async function generateBrowserIndexFile(codegen, config, configPath) {
|
|
345
|
+
codegen.lines.push(
|
|
346
|
+
`import { fromConfig } from 'fumadocs-mdx/runtime/browser';`,
|
|
347
|
+
`import type * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
348
|
+
"",
|
|
349
|
+
`const create = fromConfig<typeof Config>();`
|
|
350
|
+
);
|
|
351
|
+
async function generateCollectionObject(collection) {
|
|
352
|
+
switch (collection.type) {
|
|
353
|
+
case "docs": {
|
|
354
|
+
if (collection.docs.dynamic) return;
|
|
355
|
+
return generateCollectionObject(collection.docs);
|
|
356
|
+
}
|
|
357
|
+
case "doc":
|
|
358
|
+
if (collection.dynamic) return;
|
|
359
|
+
return `create.doc("${collection.name}", ${await generateDocCollectionGlob(codegen, collection)})`;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
codegen.lines.push("const browserCollections = {");
|
|
363
|
+
await codegen.pushAsync(
|
|
364
|
+
config.collectionList.map(async (collection) => {
|
|
365
|
+
const obj = await generateCollectionObject(collection);
|
|
366
|
+
if (!obj) return;
|
|
367
|
+
return ident(`${collection.name}: ${obj},`);
|
|
368
|
+
})
|
|
369
|
+
);
|
|
370
|
+
codegen.lines.push("};", "export default browserCollections;");
|
|
371
|
+
return codegen.toString();
|
|
372
|
+
}
|
|
373
|
+
function generateDocCollectionFrontmatterGlob(codegen, collection, eager = false) {
|
|
374
|
+
return codegen.generateGlobImport(collection.patterns, {
|
|
375
|
+
query: {
|
|
376
|
+
collection: collection.name,
|
|
377
|
+
only: "frontmatter"
|
|
378
|
+
},
|
|
379
|
+
import: "frontmatter",
|
|
380
|
+
base: collection.dir,
|
|
381
|
+
eager
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
function generateDocCollectionGlob(codegen, collection, eager = false) {
|
|
385
|
+
return codegen.generateGlobImport(collection.patterns, {
|
|
386
|
+
query: {
|
|
387
|
+
collection: collection.name
|
|
388
|
+
},
|
|
389
|
+
base: collection.dir,
|
|
390
|
+
eager
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
function generateMetaCollectionGlob(codegen, collection, eager = false) {
|
|
394
|
+
return codegen.generateGlobImport(collection.patterns, {
|
|
395
|
+
query: {
|
|
396
|
+
collection: collection.name
|
|
397
|
+
},
|
|
398
|
+
import: "default",
|
|
399
|
+
base: collection.dir,
|
|
400
|
+
eager
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export {
|
|
405
|
+
indexFile
|
|
406
|
+
};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyMdxPreset
|
|
3
|
+
} from "./chunk-E5DJTSIM.js";
|
|
4
|
+
|
|
1
5
|
// src/config/build.ts
|
|
2
6
|
import picomatch from "picomatch";
|
|
3
7
|
var SupportedFormats = {
|
|
@@ -10,7 +14,10 @@ function buildCollection(name, config) {
|
|
|
10
14
|
...config,
|
|
11
15
|
name,
|
|
12
16
|
meta: buildPrimitiveCollection(name, config.meta),
|
|
13
|
-
docs: buildPrimitiveCollection(name, config.docs)
|
|
17
|
+
docs: buildPrimitiveCollection(name, config.docs),
|
|
18
|
+
hasFile(filePath) {
|
|
19
|
+
return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);
|
|
20
|
+
}
|
|
14
21
|
};
|
|
15
22
|
}
|
|
16
23
|
return buildPrimitiveCollection(name, config);
|
|
@@ -64,11 +71,6 @@ function buildConfig(config) {
|
|
|
64
71
|
`Unknown export "${k}", you can only export collections from source configuration file.`
|
|
65
72
|
);
|
|
66
73
|
}
|
|
67
|
-
if (loaded.collections) {
|
|
68
|
-
for (const [k, v] of Object.entries(loaded.collections)) {
|
|
69
|
-
collections.set(k, buildCollection(k, v));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
74
|
const mdxOptionsCache = /* @__PURE__ */ new Map();
|
|
73
75
|
return {
|
|
74
76
|
global: loaded,
|
|
@@ -76,21 +78,22 @@ function buildConfig(config) {
|
|
|
76
78
|
getCollection(name) {
|
|
77
79
|
return collections.get(name);
|
|
78
80
|
},
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
+
getMDXOptions(collection, environment = "bundler") {
|
|
82
|
+
const key = collection ? `${environment}:${collection.name}` : environment;
|
|
83
|
+
const cached = mdxOptionsCache.get(key);
|
|
81
84
|
if (cached) return cached;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
let result;
|
|
86
|
+
if (collection?.mdxOptions) {
|
|
87
|
+
const optionsFn = collection.mdxOptions;
|
|
88
|
+
result = typeof optionsFn === "function" ? optionsFn(environment) : optionsFn;
|
|
89
|
+
} else {
|
|
90
|
+
result = (async () => {
|
|
91
|
+
const optionsFn = this.global.mdxOptions;
|
|
92
|
+
const options = typeof optionsFn === "function" ? await optionsFn() : optionsFn;
|
|
93
|
+
return applyMdxPreset(options)(environment);
|
|
94
|
+
})();
|
|
91
95
|
}
|
|
92
|
-
|
|
93
|
-
mdxOptionsCache.set(mode, result);
|
|
96
|
+
mdxOptionsCache.set(key, result);
|
|
94
97
|
return result;
|
|
95
98
|
}
|
|
96
99
|
};
|
package/dist/config/index.cjs
CHANGED
|
@@ -30,11 +30,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/config/index.ts
|
|
31
31
|
var config_exports = {};
|
|
32
32
|
__export(config_exports, {
|
|
33
|
+
applyMdxPreset: () => applyMdxPreset,
|
|
33
34
|
defineCollections: () => defineCollections,
|
|
34
35
|
defineConfig: () => defineConfig,
|
|
35
36
|
defineDocs: () => defineDocs,
|
|
36
37
|
frontmatterSchema: () => frontmatterSchema,
|
|
37
|
-
getDefaultMDXOptions: () => getDefaultMDXOptions,
|
|
38
38
|
metaSchema: () => metaSchema,
|
|
39
39
|
remarkInclude: () => remarkInclude
|
|
40
40
|
});
|
|
@@ -86,8 +86,7 @@ function defineConfig(config = {}) {
|
|
|
86
86
|
return config;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
// src/
|
|
90
|
-
var plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
|
|
89
|
+
// src/config/preset.ts
|
|
91
90
|
function pluginOption(def, options = []) {
|
|
92
91
|
const list = def(Array.isArray(options) ? options : []).filter(
|
|
93
92
|
Boolean
|
|
@@ -97,69 +96,76 @@ function pluginOption(def, options = []) {
|
|
|
97
96
|
}
|
|
98
97
|
return list;
|
|
99
98
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
99
|
+
function applyMdxPreset(options = {}) {
|
|
100
|
+
return async (environment = "bundler") => {
|
|
101
|
+
if (options.preset === "minimal") return options;
|
|
102
|
+
const plugins = await import("fumadocs-core/mdx-plugins");
|
|
103
|
+
const {
|
|
104
|
+
valueToExport = [],
|
|
105
|
+
rehypeCodeOptions,
|
|
106
|
+
remarkImageOptions,
|
|
107
|
+
remarkHeadingOptions,
|
|
108
|
+
remarkStructureOptions,
|
|
109
|
+
remarkCodeTabOptions,
|
|
110
|
+
remarkNpmOptions,
|
|
111
|
+
...mdxOptions
|
|
112
|
+
} = options;
|
|
113
|
+
const remarkPlugins = pluginOption(
|
|
114
|
+
(v) => [
|
|
115
|
+
plugins.remarkGfm,
|
|
116
|
+
[
|
|
117
|
+
plugins.remarkHeading,
|
|
118
|
+
{
|
|
119
|
+
generateToc: false,
|
|
120
|
+
...remarkHeadingOptions
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
remarkImageOptions !== false && [
|
|
124
|
+
plugins.remarkImage,
|
|
125
|
+
{
|
|
126
|
+
...remarkImageOptions,
|
|
127
|
+
useImport: remarkImageOptions?.useImport ?? environment === "bundler"
|
|
128
|
+
}
|
|
129
|
+
],
|
|
130
|
+
"remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
|
|
131
|
+
plugins.remarkCodeTab,
|
|
132
|
+
remarkCodeTabOptions
|
|
133
|
+
],
|
|
134
|
+
"remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
|
|
135
|
+
...v,
|
|
136
|
+
remarkStructureOptions !== false && [
|
|
137
|
+
plugins.remarkStructure,
|
|
138
|
+
remarkStructureOptions
|
|
139
|
+
],
|
|
140
|
+
valueToExport.length > 0 && (() => {
|
|
141
|
+
return (_, file) => {
|
|
142
|
+
file.data["mdx-export"] ??= [];
|
|
143
|
+
for (const name of valueToExport) {
|
|
144
|
+
if (!(name in file.data)) continue;
|
|
145
|
+
file.data["mdx-export"].push({
|
|
146
|
+
name,
|
|
147
|
+
value: file.data[name]
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
})
|
|
131
152
|
],
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
153
|
+
mdxOptions.remarkPlugins
|
|
154
|
+
);
|
|
155
|
+
const rehypePlugins = pluginOption(
|
|
156
|
+
(v) => [
|
|
157
|
+
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
|
158
|
+
...v,
|
|
159
|
+
plugins.rehypeToc
|
|
137
160
|
],
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
],
|
|
148
|
-
mdxOptions.remarkPlugins
|
|
149
|
-
);
|
|
150
|
-
const rehypePlugins = pluginOption(
|
|
151
|
-
(v) => [
|
|
152
|
-
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
|
153
|
-
...v,
|
|
154
|
-
plugins.rehypeToc
|
|
155
|
-
],
|
|
156
|
-
mdxOptions.rehypePlugins
|
|
157
|
-
);
|
|
158
|
-
return {
|
|
159
|
-
...mdxOptions,
|
|
160
|
-
outputFormat: _withoutBundler ? "function-body" : mdxOptions.outputFormat,
|
|
161
|
-
remarkPlugins,
|
|
162
|
-
rehypePlugins
|
|
161
|
+
mdxOptions.rehypePlugins
|
|
162
|
+
);
|
|
163
|
+
return {
|
|
164
|
+
...mdxOptions,
|
|
165
|
+
outputFormat: environment === "runtime" ? "function-body" : mdxOptions.outputFormat,
|
|
166
|
+
remarkPlugins,
|
|
167
|
+
rehypePlugins
|
|
168
|
+
};
|
|
163
169
|
};
|
|
164
170
|
}
|
|
165
171
|
|
|
@@ -232,6 +238,14 @@ function remarkMarkAndUnravel() {
|
|
|
232
238
|
};
|
|
233
239
|
}
|
|
234
240
|
|
|
241
|
+
// src/loaders/mdx/mdast-utils.ts
|
|
242
|
+
function flattenNode(node) {
|
|
243
|
+
if ("children" in node)
|
|
244
|
+
return node.children.map((child) => flattenNode(child)).join("");
|
|
245
|
+
if ("value" in node) return node.value;
|
|
246
|
+
return "";
|
|
247
|
+
}
|
|
248
|
+
|
|
235
249
|
// src/loaders/mdx/remark-include.ts
|
|
236
250
|
var ElementLikeTypes = [
|
|
237
251
|
"mdxJsxFlowElement",
|
|
@@ -255,12 +269,6 @@ function parseElementAttributes(element) {
|
|
|
255
269
|
}
|
|
256
270
|
return element.attributes ?? {};
|
|
257
271
|
}
|
|
258
|
-
function flattenNode(node) {
|
|
259
|
-
if ("children" in node)
|
|
260
|
-
return node.children.map((child) => flattenNode(child)).join("");
|
|
261
|
-
if ("value" in node) return node.value;
|
|
262
|
-
return "";
|
|
263
|
-
}
|
|
264
272
|
function parseSpecifier(specifier) {
|
|
265
273
|
const idx = specifier.lastIndexOf("#");
|
|
266
274
|
if (idx === -1) return { file: specifier };
|
|
@@ -382,11 +390,11 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
382
390
|
}
|
|
383
391
|
// Annotate the CommonJS export names for ESM import in node:
|
|
384
392
|
0 && (module.exports = {
|
|
393
|
+
applyMdxPreset,
|
|
385
394
|
defineCollections,
|
|
386
395
|
defineConfig,
|
|
387
396
|
defineDocs,
|
|
388
397
|
frontmatterSchema,
|
|
389
|
-
getDefaultMDXOptions,
|
|
390
398
|
metaSchema,
|
|
391
399
|
remarkInclude
|
|
392
400
|
});
|
package/dist/config/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AnyCollection, B as BaseCollection,
|
|
1
|
+
export { A as AnyCollection, B as BaseCollection, a as CollectionSchema, f as DefaultMDXOptions, D as DocCollection, b as DocsCollection, G as GlobalConfig, g as MDXPresetOptions, M as MetaCollection, P as PostprocessOptions, h as applyMdxPreset, d as defineCollections, e as defineConfig, c as defineDocs, i as frontmatterSchema, m as metaSchema } from '../index-D7JdSMpp.cjs';
|
|
2
2
|
import { Processor, Transformer } from 'unified';
|
|
3
3
|
import { Root } from 'mdast';
|
|
4
4
|
import '@mdx-js/mdx';
|
|
@@ -6,6 +6,7 @@ import '@standard-schema/spec';
|
|
|
6
6
|
import 'fumadocs-core/mdx-plugins';
|
|
7
7
|
import 'zod';
|
|
8
8
|
import 'chokidar';
|
|
9
|
+
import 'vfile';
|
|
9
10
|
|
|
10
11
|
declare function remarkInclude(this: Processor): Transformer<Root, Root>;
|
|
11
12
|
|