fumadocs-mdx 11.7.5 → 11.8.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/build-mdx-DMe0r3s_.d.cts +44 -0
- package/dist/build-mdx-DMe0r3s_.d.ts +44 -0
- package/dist/{chunk-OWZSTKKX.js → chunk-6Y5JDZHD.js} +8 -1
- package/dist/{chunk-HWSF4OGZ.js → chunk-7JFPDRW7.js} +1 -1
- package/dist/{chunk-XZR5QXVY.js → chunk-BCOXAJMC.js} +1 -1
- package/dist/{chunk-GYWPPGFD.js → chunk-DJNS22RO.js} +18 -1
- package/dist/{chunk-3XN4P23K.js → chunk-IGXZS2W6.js} +1 -1
- package/dist/{chunk-XVL4ZQFK.js → chunk-S73DGUHI.js} +1 -1
- package/dist/{chunk-KVWX6THC.js → chunk-VWJKRQZR.js} +2 -2
- package/dist/config/index.cjs +22 -5
- package/dist/config/index.js +3 -3
- package/dist/config/zod-3.cjs +22 -5
- package/dist/config/zod-3.js +3 -3
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/loader-mdx.cjs +29 -5
- package/dist/loader-mdx.js +7 -7
- package/dist/{mdx-options-3NB74EMB.js → mdx-options-ILHLYYTL.js} +1 -1
- package/dist/next/index.cjs +36 -5
- package/dist/next/index.js +5 -5
- package/dist/runtime/async.cjs +35 -10
- package/dist/runtime/async.d.cts +3 -2
- package/dist/runtime/async.d.ts +3 -2
- package/dist/runtime/async.js +12 -11
- package/dist/runtime/vite.cjs +49 -41
- package/dist/runtime/vite.d.cts +27 -28
- package/dist/runtime/vite.d.ts +27 -28
- package/dist/runtime/vite.js +49 -41
- package/dist/{types-C-WXTx1W.d.cts → types-DvnkeVI3.d.cts} +12 -15
- package/dist/{types-CU9nn_je.d.ts → types-zBRxlyaM.d.ts} +12 -15
- package/dist/vite/index.cjs +101 -54
- package/dist/vite/index.d.cts +6 -1
- package/dist/vite/index.d.ts +6 -1
- package/dist/vite/index.js +51 -35
- package/package.json +11 -11
|
@@ -2,10 +2,7 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
|
2
2
|
import { Source, PageData, MetaData } from 'fumadocs-core/source';
|
|
3
3
|
import { a as DocCollection, M as MetaCollection, b as DocsCollection, G as GlobalConfig } from './define-DnJzAZrj.js';
|
|
4
4
|
import { ProcessorOptions } from '@mdx-js/mdx';
|
|
5
|
-
import {
|
|
6
|
-
import { MDXProps } from 'mdx/types';
|
|
7
|
-
import { StructuredData } from 'fumadocs-core/mdx-plugins';
|
|
8
|
-
import { TableOfContents } from 'fumadocs-core/server';
|
|
5
|
+
import { C as CompiledMDXProperties } from './build-mdx-DMe0r3s_.js';
|
|
9
6
|
|
|
10
7
|
interface LoadedConfig {
|
|
11
8
|
collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
|
|
@@ -23,15 +20,8 @@ interface FileInfo {
|
|
|
23
20
|
path: string;
|
|
24
21
|
absolutePath: string;
|
|
25
22
|
}
|
|
26
|
-
interface MarkdownProps {
|
|
27
|
-
body:
|
|
28
|
-
structuredData: StructuredData;
|
|
29
|
-
toc: TableOfContents;
|
|
30
|
-
_exports: Record<string, unknown>;
|
|
31
|
-
/**
|
|
32
|
-
* Only available when `lastModifiedTime` is enabled on MDX loader
|
|
33
|
-
*/
|
|
34
|
-
lastModified?: Date;
|
|
23
|
+
interface MarkdownProps extends Omit<CompiledMDXProperties, 'frontmatter' | 'default'> {
|
|
24
|
+
body: CompiledMDXProperties['default'];
|
|
35
25
|
}
|
|
36
26
|
interface RuntimeFile {
|
|
37
27
|
info: FileInfo;
|
|
@@ -40,10 +30,17 @@ interface RuntimeFile {
|
|
|
40
30
|
interface AsyncRuntimeFile {
|
|
41
31
|
info: FileInfo;
|
|
42
32
|
data: Record<string, unknown>;
|
|
43
|
-
content:
|
|
33
|
+
content: {
|
|
34
|
+
matter: string;
|
|
35
|
+
body: string;
|
|
36
|
+
};
|
|
44
37
|
lastModified?: Date;
|
|
45
38
|
}
|
|
46
39
|
type DocOut<Schema extends StandardSchemaV1> = Override<MarkdownProps & {
|
|
40
|
+
/**
|
|
41
|
+
* Other exports in the compiled Markdown/MDX file
|
|
42
|
+
*/
|
|
43
|
+
_exports: Record<string, unknown>;
|
|
47
44
|
/**
|
|
48
45
|
* Read the original content of file from file system.
|
|
49
46
|
*/
|
|
@@ -65,7 +62,7 @@ interface Runtime {
|
|
|
65
62
|
}
|
|
66
63
|
type AsyncDocOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry & {
|
|
67
64
|
content: string;
|
|
68
|
-
load: () => Promise<MarkdownProps
|
|
65
|
+
load: () => Promise<MarkdownProps & Record<string, unknown>>;
|
|
69
66
|
};
|
|
70
67
|
interface RuntimeAsync {
|
|
71
68
|
doc: <C>(files: AsyncRuntimeFile[], collection: string, config: LoadedConfig) => C extends DocCollection<infer Schema, true> ? AsyncDocOut<Schema>[] : never;
|
package/dist/vite/index.cjs
CHANGED
|
@@ -34,7 +34,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
34
34
|
function remarkMdxExport({ values }) {
|
|
35
35
|
return (tree, vfile) => {
|
|
36
36
|
for (const name of values) {
|
|
37
|
-
if (!(name in vfile.data))
|
|
37
|
+
if (!(name in vfile.data)) continue;
|
|
38
38
|
tree.children.unshift(getMdastExport(name, vfile.data[name]));
|
|
39
39
|
}
|
|
40
40
|
};
|
|
@@ -80,6 +80,27 @@ var init_remark_exports = __esm({
|
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
+
// src/mdx-plugins/remark-extract.ts
|
|
84
|
+
function remarkExtract() {
|
|
85
|
+
return (tree, file) => {
|
|
86
|
+
const urls = [];
|
|
87
|
+
(0, import_unist_util_visit.visit)(tree, "link", (node) => {
|
|
88
|
+
urls.push({
|
|
89
|
+
href: node.url
|
|
90
|
+
});
|
|
91
|
+
return "skip";
|
|
92
|
+
});
|
|
93
|
+
file.data.extractedReferences = urls;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
var import_unist_util_visit;
|
|
97
|
+
var init_remark_extract = __esm({
|
|
98
|
+
"src/mdx-plugins/remark-extract.ts"() {
|
|
99
|
+
"use strict";
|
|
100
|
+
import_unist_util_visit = require("unist-util-visit");
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
83
104
|
// src/utils/mdx-options.ts
|
|
84
105
|
var mdx_options_exports = {};
|
|
85
106
|
__export(mdx_options_exports, {
|
|
@@ -107,6 +128,7 @@ function getDefaultMDXOptions({
|
|
|
107
128
|
}) {
|
|
108
129
|
const mdxExports = [
|
|
109
130
|
"structuredData",
|
|
131
|
+
"extractedReferences",
|
|
110
132
|
"frontmatter",
|
|
111
133
|
"lastModified",
|
|
112
134
|
...valueToExport
|
|
@@ -134,6 +156,7 @@ function getDefaultMDXOptions({
|
|
|
134
156
|
],
|
|
135
157
|
"remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
|
|
136
158
|
...v,
|
|
159
|
+
remarkExtract,
|
|
137
160
|
remarkStructureOptions !== false && [
|
|
138
161
|
plugins.remarkStructure,
|
|
139
162
|
remarkStructureOptions
|
|
@@ -163,6 +186,7 @@ var init_mdx_options = __esm({
|
|
|
163
186
|
"use strict";
|
|
164
187
|
plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
|
|
165
188
|
init_remark_exports();
|
|
189
|
+
init_remark_extract();
|
|
166
190
|
}
|
|
167
191
|
});
|
|
168
192
|
|
|
@@ -227,7 +251,7 @@ function buildConfig(config) {
|
|
|
227
251
|
var import_mdx = require("@mdx-js/mdx");
|
|
228
252
|
|
|
229
253
|
// src/mdx-plugins/remark-include.ts
|
|
230
|
-
var
|
|
254
|
+
var import_unist_util_visit2 = require("unist-util-visit");
|
|
231
255
|
var path = __toESM(require("path"), 1);
|
|
232
256
|
var fs = __toESM(require("fs/promises"), 1);
|
|
233
257
|
|
|
@@ -240,9 +264,9 @@ function fumaMatter(input) {
|
|
|
240
264
|
if (!match) {
|
|
241
265
|
return output;
|
|
242
266
|
}
|
|
243
|
-
output.matter = match[
|
|
267
|
+
output.matter = match[0];
|
|
244
268
|
output.content = input.slice(match[0].length);
|
|
245
|
-
const loaded = (0, import_js_yaml.load)(
|
|
269
|
+
const loaded = (0, import_js_yaml.load)(match[1]);
|
|
246
270
|
output.data = loaded ?? {};
|
|
247
271
|
return output;
|
|
248
272
|
}
|
|
@@ -278,7 +302,7 @@ function remarkInclude() {
|
|
|
278
302
|
const TagName = "include";
|
|
279
303
|
async function update(tree, directory, data) {
|
|
280
304
|
const queue = [];
|
|
281
|
-
(0,
|
|
305
|
+
(0, import_unist_util_visit2.visit)(
|
|
282
306
|
tree,
|
|
283
307
|
["mdxJsxFlowElement", "mdxJsxTextElement"],
|
|
284
308
|
(node, _, parent) => {
|
|
@@ -447,7 +471,14 @@ var import_zod = require("zod");
|
|
|
447
471
|
var import_node_path = __toESM(require("path"), 1);
|
|
448
472
|
function toImportPath(file, config) {
|
|
449
473
|
const ext = import_node_path.default.extname(file);
|
|
450
|
-
|
|
474
|
+
let filename;
|
|
475
|
+
if (ext === ".ts" && config.jsExtension) {
|
|
476
|
+
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
477
|
+
} else if (ext === ".ts") {
|
|
478
|
+
filename = file.substring(0, file.length - ext.length);
|
|
479
|
+
} else {
|
|
480
|
+
filename = file;
|
|
481
|
+
}
|
|
451
482
|
let importPath;
|
|
452
483
|
if ("relativeTo" in config) {
|
|
453
484
|
importPath = import_node_path.default.relative(config.relativeTo, filename);
|
|
@@ -468,6 +499,29 @@ var fs2 = __toESM(require("fs/promises"), 1);
|
|
|
468
499
|
var path4 = __toESM(require("path"), 1);
|
|
469
500
|
var import_js_yaml2 = require("js-yaml");
|
|
470
501
|
|
|
502
|
+
// src/utils/git-timestamp.ts
|
|
503
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
504
|
+
var import_tinyexec = require("tinyexec");
|
|
505
|
+
var cache2 = /* @__PURE__ */ new Map();
|
|
506
|
+
async function getGitTimestamp(file) {
|
|
507
|
+
const cached = cache2.get(file);
|
|
508
|
+
if (cached) return cached;
|
|
509
|
+
try {
|
|
510
|
+
const out = await (0, import_tinyexec.x)(
|
|
511
|
+
"git",
|
|
512
|
+
["log", "-1", '--pretty="%ai"', import_node_path2.default.relative(process.cwd(), file)],
|
|
513
|
+
{
|
|
514
|
+
throwOnError: true
|
|
515
|
+
}
|
|
516
|
+
);
|
|
517
|
+
const time = new Date(out.stdout);
|
|
518
|
+
cache2.set(file, time);
|
|
519
|
+
return time;
|
|
520
|
+
} catch {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
471
525
|
// src/utils/collections.ts
|
|
472
526
|
function getSupportedFormats(collection) {
|
|
473
527
|
return {
|
|
@@ -481,17 +535,16 @@ function getGlobPatterns(collection) {
|
|
|
481
535
|
}
|
|
482
536
|
|
|
483
537
|
// src/vite/generate-glob.ts
|
|
484
|
-
function generateGlob(name, collection) {
|
|
538
|
+
function generateGlob(name, collection, globOptions) {
|
|
485
539
|
const patterns = mapGlobPatterns(getGlobPatterns(collection));
|
|
486
540
|
const options = {
|
|
541
|
+
...globOptions,
|
|
487
542
|
query: {
|
|
543
|
+
...globOptions?.query,
|
|
488
544
|
collection: name
|
|
489
545
|
},
|
|
490
546
|
base: getGlobBase(collection)
|
|
491
547
|
};
|
|
492
|
-
if (collection.type === "meta") {
|
|
493
|
-
options.import = "default";
|
|
494
|
-
}
|
|
495
548
|
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(options, null, 2)})`;
|
|
496
549
|
}
|
|
497
550
|
function mapGlobPatterns(patterns) {
|
|
@@ -516,31 +569,38 @@ function getGlobBase(collection) {
|
|
|
516
569
|
return dir;
|
|
517
570
|
}
|
|
518
571
|
|
|
519
|
-
// src/
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
} catch {
|
|
538
|
-
return;
|
|
572
|
+
// src/vite/generate.ts
|
|
573
|
+
function docs(name, collection) {
|
|
574
|
+
const obj = [
|
|
575
|
+
ident(`doc: ${doc(name, collection.docs)}`),
|
|
576
|
+
ident(`meta: ${meta(name, collection.meta)}`)
|
|
577
|
+
].join(",\n");
|
|
578
|
+
return `{
|
|
579
|
+
${obj}
|
|
580
|
+
}`;
|
|
581
|
+
}
|
|
582
|
+
function doc(name, collection) {
|
|
583
|
+
if (collection.async) {
|
|
584
|
+
return `create.docLazy("${name}", ${generateGlob(name, collection, {
|
|
585
|
+
query: {
|
|
586
|
+
only: "frontmatter"
|
|
587
|
+
},
|
|
588
|
+
import: "frontmatter"
|
|
589
|
+
})}, ${generateGlob(name, collection)})`;
|
|
539
590
|
}
|
|
591
|
+
return `create.doc("${name}", ${generateGlob(name, collection)})`;
|
|
592
|
+
}
|
|
593
|
+
function meta(name, collection) {
|
|
594
|
+
return `create.meta("${name}", ${generateGlob(name, collection, {
|
|
595
|
+
import: "default"
|
|
596
|
+
})})`;
|
|
540
597
|
}
|
|
541
598
|
|
|
542
599
|
// src/vite/index.ts
|
|
543
|
-
var
|
|
600
|
+
var querySchema = import_zod.z.object({
|
|
601
|
+
only: import_zod.z.literal(["frontmatter", "all"]).default("all"),
|
|
602
|
+
collection: import_zod.z.string().optional()
|
|
603
|
+
}).loose();
|
|
544
604
|
function mdx(config, options = {}) {
|
|
545
605
|
const { generateIndexFile = true, configPath = "source.config.ts" } = options;
|
|
546
606
|
const loaded = buildConfig(config);
|
|
@@ -579,9 +639,8 @@ function mdx(config, options = {}) {
|
|
|
579
639
|
async function transformContent(file, query, value) {
|
|
580
640
|
const matter = fumaMatter(value);
|
|
581
641
|
const isDevelopment = this.environment.mode === "dev";
|
|
582
|
-
const parsed = (0, import_node_querystring.parse)(query);
|
|
642
|
+
const parsed = querySchema.parse((0, import_node_querystring.parse)(query));
|
|
583
643
|
const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
|
|
584
|
-
const only = parsed.only ? onlySchema.parse(parsed.only) : "all";
|
|
585
644
|
let schema;
|
|
586
645
|
let mdxOptions;
|
|
587
646
|
switch (collection?.type) {
|
|
@@ -605,7 +664,7 @@ function mdx(config, options = {}) {
|
|
|
605
664
|
`invalid frontmatter in ${file}`
|
|
606
665
|
);
|
|
607
666
|
}
|
|
608
|
-
if (only === "frontmatter") {
|
|
667
|
+
if (parsed.only === "frontmatter") {
|
|
609
668
|
return {
|
|
610
669
|
code: `export const frontmatter = ${JSON.stringify(matter.data)}`,
|
|
611
670
|
map: null
|
|
@@ -651,35 +710,23 @@ function mdx(config, options = {}) {
|
|
|
651
710
|
'/// <reference types="vite/client" />',
|
|
652
711
|
`import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
|
|
653
712
|
`import type * as Config from '${toImportPath(configPath, {
|
|
654
|
-
relativeTo: outdir
|
|
713
|
+
relativeTo: outdir,
|
|
714
|
+
jsExtension: typeof generateIndexFile === "object" ? generateIndexFile.addJsExtension : void 0
|
|
655
715
|
})}';`,
|
|
656
716
|
"",
|
|
657
717
|
`export const create = fromConfig<typeof Config>();`
|
|
658
718
|
];
|
|
659
|
-
function docs(name, collection) {
|
|
660
|
-
const args = [
|
|
661
|
-
ident(`doc: ${generateGlob(name, collection.docs)}`),
|
|
662
|
-
ident(`meta: ${generateGlob(name, collection.meta)}`)
|
|
663
|
-
].join(",\n");
|
|
664
|
-
return `export const ${name} = create.docs("${name}", {
|
|
665
|
-
${args}
|
|
666
|
-
});`;
|
|
667
|
-
}
|
|
668
|
-
function doc(name, collection) {
|
|
669
|
-
return `export const ${name} = create.doc("${name}", ${generateGlob(name, collection)});`;
|
|
670
|
-
}
|
|
671
|
-
function meta(name, collection) {
|
|
672
|
-
return `export const ${name} = create.meta("${name}", ${generateGlob(name, collection)});`;
|
|
673
|
-
}
|
|
674
719
|
for (const [name, collection] of loaded.collections.entries()) {
|
|
675
|
-
|
|
720
|
+
let body;
|
|
676
721
|
if (collection.type === "docs") {
|
|
677
|
-
|
|
722
|
+
body = docs(name, collection);
|
|
678
723
|
} else if (collection.type === "meta") {
|
|
679
|
-
|
|
724
|
+
body = meta(name, collection);
|
|
680
725
|
} else {
|
|
681
|
-
|
|
726
|
+
body = doc(name, collection);
|
|
682
727
|
}
|
|
728
|
+
lines.push("");
|
|
729
|
+
lines.push(`export const ${name} = ${body};`);
|
|
683
730
|
}
|
|
684
731
|
await fs2.writeFile(path4.join(outdir, outFile), lines.join("\n"));
|
|
685
732
|
},
|
package/dist/vite/index.d.cts
CHANGED
|
@@ -6,7 +6,12 @@ interface PluginOptions {
|
|
|
6
6
|
*
|
|
7
7
|
* @defaultValue true
|
|
8
8
|
*/
|
|
9
|
-
generateIndexFile?: boolean
|
|
9
|
+
generateIndexFile?: boolean | {
|
|
10
|
+
/**
|
|
11
|
+
* add `.js` extensions to imports, needed for ESM without bundler resolution
|
|
12
|
+
*/
|
|
13
|
+
addJsExtension?: boolean;
|
|
14
|
+
};
|
|
10
15
|
/**
|
|
11
16
|
* @defaultValue source.config.ts
|
|
12
17
|
*/
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -6,7 +6,12 @@ interface PluginOptions {
|
|
|
6
6
|
*
|
|
7
7
|
* @defaultValue true
|
|
8
8
|
*/
|
|
9
|
-
generateIndexFile?: boolean
|
|
9
|
+
generateIndexFile?: boolean | {
|
|
10
|
+
/**
|
|
11
|
+
* add `.js` extensions to imports, needed for ESM without bundler resolution
|
|
12
|
+
*/
|
|
13
|
+
addJsExtension?: boolean;
|
|
14
|
+
};
|
|
10
15
|
/**
|
|
11
16
|
* @defaultValue source.config.ts
|
|
12
17
|
*/
|
package/dist/vite/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
countLines
|
|
3
3
|
} from "../chunk-UCY7OBZG.js";
|
|
4
|
-
import {
|
|
5
|
-
buildMDX
|
|
6
|
-
} from "../chunk-HWSF4OGZ.js";
|
|
7
|
-
import "../chunk-3XN4P23K.js";
|
|
8
4
|
import {
|
|
9
5
|
getGlobPatterns,
|
|
10
6
|
ident,
|
|
11
7
|
toImportPath
|
|
12
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-6Y5JDZHD.js";
|
|
13
9
|
import {
|
|
14
10
|
ValidationError,
|
|
15
11
|
getGitTimestamp,
|
|
16
12
|
validate
|
|
17
13
|
} from "../chunk-GX3THK2Q.js";
|
|
14
|
+
import {
|
|
15
|
+
buildMDX
|
|
16
|
+
} from "../chunk-7JFPDRW7.js";
|
|
17
|
+
import "../chunk-IGXZS2W6.js";
|
|
18
18
|
import {
|
|
19
19
|
buildConfig
|
|
20
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-S73DGUHI.js";
|
|
21
21
|
import {
|
|
22
22
|
fumaMatter
|
|
23
|
-
} from "../chunk-
|
|
23
|
+
} from "../chunk-VWJKRQZR.js";
|
|
24
24
|
|
|
25
25
|
// src/vite/index.ts
|
|
26
26
|
import { parse } from "querystring";
|
|
@@ -30,17 +30,16 @@ import * as path from "path";
|
|
|
30
30
|
import { load } from "js-yaml";
|
|
31
31
|
|
|
32
32
|
// src/vite/generate-glob.ts
|
|
33
|
-
function generateGlob(name, collection) {
|
|
33
|
+
function generateGlob(name, collection, globOptions) {
|
|
34
34
|
const patterns = mapGlobPatterns(getGlobPatterns(collection));
|
|
35
35
|
const options = {
|
|
36
|
+
...globOptions,
|
|
36
37
|
query: {
|
|
38
|
+
...globOptions?.query,
|
|
37
39
|
collection: name
|
|
38
40
|
},
|
|
39
41
|
base: getGlobBase(collection)
|
|
40
42
|
};
|
|
41
|
-
if (collection.type === "meta") {
|
|
42
|
-
options.import = "default";
|
|
43
|
-
}
|
|
44
43
|
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(options, null, 2)})`;
|
|
45
44
|
}
|
|
46
45
|
function mapGlobPatterns(patterns) {
|
|
@@ -65,8 +64,38 @@ function getGlobBase(collection) {
|
|
|
65
64
|
return dir;
|
|
66
65
|
}
|
|
67
66
|
|
|
67
|
+
// src/vite/generate.ts
|
|
68
|
+
function docs(name, collection) {
|
|
69
|
+
const obj = [
|
|
70
|
+
ident(`doc: ${doc(name, collection.docs)}`),
|
|
71
|
+
ident(`meta: ${meta(name, collection.meta)}`)
|
|
72
|
+
].join(",\n");
|
|
73
|
+
return `{
|
|
74
|
+
${obj}
|
|
75
|
+
}`;
|
|
76
|
+
}
|
|
77
|
+
function doc(name, collection) {
|
|
78
|
+
if (collection.async) {
|
|
79
|
+
return `create.docLazy("${name}", ${generateGlob(name, collection, {
|
|
80
|
+
query: {
|
|
81
|
+
only: "frontmatter"
|
|
82
|
+
},
|
|
83
|
+
import: "frontmatter"
|
|
84
|
+
})}, ${generateGlob(name, collection)})`;
|
|
85
|
+
}
|
|
86
|
+
return `create.doc("${name}", ${generateGlob(name, collection)})`;
|
|
87
|
+
}
|
|
88
|
+
function meta(name, collection) {
|
|
89
|
+
return `create.meta("${name}", ${generateGlob(name, collection, {
|
|
90
|
+
import: "default"
|
|
91
|
+
})})`;
|
|
92
|
+
}
|
|
93
|
+
|
|
68
94
|
// src/vite/index.ts
|
|
69
|
-
var
|
|
95
|
+
var querySchema = z.object({
|
|
96
|
+
only: z.literal(["frontmatter", "all"]).default("all"),
|
|
97
|
+
collection: z.string().optional()
|
|
98
|
+
}).loose();
|
|
70
99
|
function mdx(config, options = {}) {
|
|
71
100
|
const { generateIndexFile = true, configPath = "source.config.ts" } = options;
|
|
72
101
|
const loaded = buildConfig(config);
|
|
@@ -105,9 +134,8 @@ function mdx(config, options = {}) {
|
|
|
105
134
|
async function transformContent(file, query, value) {
|
|
106
135
|
const matter = fumaMatter(value);
|
|
107
136
|
const isDevelopment = this.environment.mode === "dev";
|
|
108
|
-
const parsed = parse(query);
|
|
137
|
+
const parsed = querySchema.parse(parse(query));
|
|
109
138
|
const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
|
|
110
|
-
const only = parsed.only ? onlySchema.parse(parsed.only) : "all";
|
|
111
139
|
let schema;
|
|
112
140
|
let mdxOptions;
|
|
113
141
|
switch (collection?.type) {
|
|
@@ -131,7 +159,7 @@ function mdx(config, options = {}) {
|
|
|
131
159
|
`invalid frontmatter in ${file}`
|
|
132
160
|
);
|
|
133
161
|
}
|
|
134
|
-
if (only === "frontmatter") {
|
|
162
|
+
if (parsed.only === "frontmatter") {
|
|
135
163
|
return {
|
|
136
164
|
code: `export const frontmatter = ${JSON.stringify(matter.data)}`,
|
|
137
165
|
map: null
|
|
@@ -177,35 +205,23 @@ function mdx(config, options = {}) {
|
|
|
177
205
|
'/// <reference types="vite/client" />',
|
|
178
206
|
`import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
|
|
179
207
|
`import type * as Config from '${toImportPath(configPath, {
|
|
180
|
-
relativeTo: outdir
|
|
208
|
+
relativeTo: outdir,
|
|
209
|
+
jsExtension: typeof generateIndexFile === "object" ? generateIndexFile.addJsExtension : void 0
|
|
181
210
|
})}';`,
|
|
182
211
|
"",
|
|
183
212
|
`export const create = fromConfig<typeof Config>();`
|
|
184
213
|
];
|
|
185
|
-
function docs(name, collection) {
|
|
186
|
-
const args = [
|
|
187
|
-
ident(`doc: ${generateGlob(name, collection.docs)}`),
|
|
188
|
-
ident(`meta: ${generateGlob(name, collection.meta)}`)
|
|
189
|
-
].join(",\n");
|
|
190
|
-
return `export const ${name} = create.docs("${name}", {
|
|
191
|
-
${args}
|
|
192
|
-
});`;
|
|
193
|
-
}
|
|
194
|
-
function doc(name, collection) {
|
|
195
|
-
return `export const ${name} = create.doc("${name}", ${generateGlob(name, collection)});`;
|
|
196
|
-
}
|
|
197
|
-
function meta(name, collection) {
|
|
198
|
-
return `export const ${name} = create.meta("${name}", ${generateGlob(name, collection)});`;
|
|
199
|
-
}
|
|
200
214
|
for (const [name, collection] of loaded.collections.entries()) {
|
|
201
|
-
|
|
215
|
+
let body;
|
|
202
216
|
if (collection.type === "docs") {
|
|
203
|
-
|
|
217
|
+
body = docs(name, collection);
|
|
204
218
|
} else if (collection.type === "meta") {
|
|
205
|
-
|
|
219
|
+
body = meta(name, collection);
|
|
206
220
|
} else {
|
|
207
|
-
|
|
221
|
+
body = doc(name, collection);
|
|
208
222
|
}
|
|
223
|
+
lines.push("");
|
|
224
|
+
lines.push(`export const ${name} = ${body};`);
|
|
209
225
|
}
|
|
210
226
|
await fs.writeFile(path.join(outdir, outFile), lines.join("\n"));
|
|
211
227
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-mdx",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.8.1",
|
|
4
4
|
"description": "The built-in source for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@mdx-js/mdx": "^3.1.0",
|
|
60
60
|
"@standard-schema/spec": "^1.0.0",
|
|
61
61
|
"chokidar": "^4.0.3",
|
|
62
|
-
"esbuild": "^0.25.
|
|
62
|
+
"esbuild": "^0.25.9",
|
|
63
63
|
"estree-util-value-to-estree": "^3.4.0",
|
|
64
64
|
"js-yaml": "^4.1.0",
|
|
65
65
|
"lru-cache": "^11.1.0",
|
|
@@ -67,25 +67,25 @@
|
|
|
67
67
|
"tinyexec": "^1.0.1",
|
|
68
68
|
"tinyglobby": "^0.2.14",
|
|
69
69
|
"unist-util-visit": "^5.0.0",
|
|
70
|
-
"zod": "^4.0
|
|
70
|
+
"zod": "^4.1.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@types/js-yaml": "^4.0.9",
|
|
74
74
|
"@types/mdast": "^4.0.3",
|
|
75
75
|
"@types/mdx": "^2.0.13",
|
|
76
|
-
"@types/node": "^24.
|
|
77
|
-
"@types/react": "^19.1.
|
|
76
|
+
"@types/node": "^24.3.0",
|
|
77
|
+
"@types/react": "^19.1.11",
|
|
78
78
|
"mdast-util-mdx-jsx": "^3.2.0",
|
|
79
|
-
"next": "^15.
|
|
79
|
+
"next": "^15.5.0",
|
|
80
80
|
"react": "^19.1.1",
|
|
81
|
-
"rollup": "^4.
|
|
81
|
+
"rollup": "^4.48.0",
|
|
82
82
|
"unified": "^11.0.5",
|
|
83
83
|
"vfile": "^6.0.3",
|
|
84
|
-
"vite": "^7.1.
|
|
85
|
-
"webpack": "^5.101.
|
|
86
|
-
"fumadocs-core": "15.6.10",
|
|
87
|
-
"eslint-config-custom": "0.0.0",
|
|
84
|
+
"vite": "^7.1.3",
|
|
85
|
+
"webpack": "^5.101.3",
|
|
88
86
|
"@fumadocs/mdx-remote": "1.4.0",
|
|
87
|
+
"eslint-config-custom": "0.0.0",
|
|
88
|
+
"fumadocs-core": "15.7.3",
|
|
89
89
|
"tsconfig": "0.0.0"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|