fumadocs-mdx 11.10.1 → 12.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 +29 -139
- 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 +126 -108
- package/dist/bun/index.js +5 -5
- package/dist/chunk-3M4SHY6K.js +80 -0
- package/dist/{chunk-UOOPSLFY.js → chunk-AUOOMFAI.js} +27 -21
- package/dist/{chunk-QJCCVMBJ.js → chunk-KGUBBRL6.js} +11 -13
- package/dist/{chunk-SVTXMVLQ.js → chunk-KTDVTBMH.js} +1 -1
- package/dist/{chunk-766EAFX6.js → chunk-POXTQZ4D.js} +1 -31
- package/dist/chunk-SWNOXPYJ.js +142 -0
- package/dist/{chunk-XXSKWWMB.js → chunk-TLD6JMT6.js} +1 -1
- package/dist/{chunk-CNKI574E.js → chunk-VXEBLM4X.js} +1 -1
- package/dist/{chunk-QVZ7JH4H.js → chunk-YC25YEBF.js} +1 -1
- package/dist/chunk-ZLCSVXCD.js +10 -0
- package/dist/config/index.cjs +18 -97
- 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/loader-mdx.cjs +127 -139
- package/dist/loader-mdx.js +6 -6
- package/dist/next/index.cjs +29 -139
- package/dist/next/index.js +16 -16
- package/dist/node/loader.cjs +131 -143
- package/dist/node/loader.js +6 -6
- package/dist/postinstall-U7VROOY7.js +9 -0
- package/dist/{mdx-options-T73E4LQB.js → preset-WFEORCAB.js} +1 -1
- package/dist/runtime/next/async.cjs +198 -150
- package/dist/runtime/next/async.d.cts +3 -3
- package/dist/runtime/next/async.d.ts +3 -3
- package/dist/runtime/next/async.js +50 -30
- 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-DLIAvrgC.d.ts} +6 -32
- package/dist/{types-DT83Ijs6.d.cts → types-Dl8HLbm5.d.cts} +6 -32
- package/dist/vite/index.cjs +131 -143
- package/dist/vite/index.js +7 -7
- package/package.json +2 -6
- 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/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,8 +1,8 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import { Source, PageData, MetaData } from 'fumadocs-core/source';
|
|
3
|
-
import { a as DocCollection, M as MetaCollection, b as DocsCollection, G as GlobalConfig } from './define
|
|
3
|
+
import { a as DocCollection, M as MetaCollection, b as DocsCollection, G as GlobalConfig } from './define--6HQ1ehX.js';
|
|
4
4
|
import { ProcessorOptions } from '@mdx-js/mdx';
|
|
5
|
-
import {
|
|
5
|
+
import { F as FileInfo, A as AsyncDocCollectionEntry, M as MetaCollectionEntry, D as DocCollectionEntry } from './shared-0QIuV0XZ.js';
|
|
6
6
|
|
|
7
7
|
interface LoadedConfig {
|
|
8
8
|
collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
|
|
@@ -10,19 +10,6 @@ interface LoadedConfig {
|
|
|
10
10
|
getDefaultMDXOptions(mode?: 'default' | 'remote'): Promise<ProcessorOptions>;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
interface BaseCollectionEntry {
|
|
14
|
-
/**
|
|
15
|
-
* Raw file path of collection entry, including absolute path (not normalized).
|
|
16
|
-
*/
|
|
17
|
-
_file: FileInfo;
|
|
18
|
-
}
|
|
19
|
-
interface FileInfo {
|
|
20
|
-
path: string;
|
|
21
|
-
absolutePath: string;
|
|
22
|
-
}
|
|
23
|
-
interface MarkdownProps extends Omit<CompiledMDXProperties, 'frontmatter' | 'default'> {
|
|
24
|
-
body: CompiledMDXProperties['default'];
|
|
25
|
-
}
|
|
26
13
|
interface RuntimeFile {
|
|
27
14
|
info: FileInfo;
|
|
28
15
|
data: Record<string, unknown>;
|
|
@@ -36,18 +23,8 @@ interface AsyncRuntimeFile {
|
|
|
36
23
|
};
|
|
37
24
|
lastModified?: Date;
|
|
38
25
|
}
|
|
39
|
-
type DocOut<Schema extends StandardSchemaV1> =
|
|
40
|
-
|
|
41
|
-
* Other exports in the compiled Markdown/MDX file
|
|
42
|
-
*/
|
|
43
|
-
_exports: Record<string, unknown>;
|
|
44
|
-
/**
|
|
45
|
-
* Read the original content of file from file system.
|
|
46
|
-
*/
|
|
47
|
-
get content(): string;
|
|
48
|
-
}, StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry>;
|
|
49
|
-
type Override<A, B> = Omit<A, keyof B> & B;
|
|
50
|
-
type MetaOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry;
|
|
26
|
+
type DocOut<Schema extends StandardSchemaV1 = StandardSchemaV1> = DocCollectionEntry<StandardSchemaV1.InferOutput<Schema>>;
|
|
27
|
+
type MetaOut<Schema extends StandardSchemaV1 = StandardSchemaV1> = MetaCollectionEntry<StandardSchemaV1.InferOutput<Schema>>;
|
|
51
28
|
interface Runtime {
|
|
52
29
|
doc: <C>(files: RuntimeFile[]) => C extends DocCollection<infer Schema, false> ? DocOut<Schema>[] : never;
|
|
53
30
|
meta: <C>(files: RuntimeFile[]) => C extends MetaCollection<infer Schema> ? MetaOut<Schema>[] : never;
|
|
@@ -60,10 +37,7 @@ interface Runtime {
|
|
|
60
37
|
}>;
|
|
61
38
|
} : never;
|
|
62
39
|
}
|
|
63
|
-
type AsyncDocOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema
|
|
64
|
-
content: string;
|
|
65
|
-
load: () => Promise<MarkdownProps & Record<string, unknown>>;
|
|
66
|
-
};
|
|
40
|
+
type AsyncDocOut<Schema extends StandardSchemaV1 = StandardSchemaV1> = AsyncDocCollectionEntry<StandardSchemaV1.InferOutput<Schema>>;
|
|
67
41
|
interface RuntimeAsync {
|
|
68
42
|
doc: <C>(files: AsyncRuntimeFile[], collection: string, config: LoadedConfig) => C extends DocCollection<infer Schema, true> ? AsyncDocOut<Schema>[] : never;
|
|
69
43
|
docs: <C>(docs: AsyncRuntimeFile[], metas: RuntimeFile[], collection: string, config: LoadedConfig) => C extends DocsCollection<infer DocSchema, infer MetaSchema, true> ? {
|
|
@@ -76,4 +50,4 @@ interface RuntimeAsync {
|
|
|
76
50
|
} : never;
|
|
77
51
|
}
|
|
78
52
|
|
|
79
|
-
export type {
|
|
53
|
+
export type { AsyncRuntimeFile as A, DocOut as D, LoadedConfig as L, MetaOut as M, Runtime as R, RuntimeFile as a, AsyncDocOut as b, RuntimeAsync as c };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import { Source, PageData, MetaData } from 'fumadocs-core/source';
|
|
3
|
-
import { a as DocCollection, M as MetaCollection, b as DocsCollection, G as GlobalConfig } from './define
|
|
3
|
+
import { a as DocCollection, M as MetaCollection, b as DocsCollection, G as GlobalConfig } from './define--6HQ1ehX.cjs';
|
|
4
4
|
import { ProcessorOptions } from '@mdx-js/mdx';
|
|
5
|
-
import {
|
|
5
|
+
import { F as FileInfo, A as AsyncDocCollectionEntry, M as MetaCollectionEntry, D as DocCollectionEntry } from './shared-CqgMnt9h.cjs';
|
|
6
6
|
|
|
7
7
|
interface LoadedConfig {
|
|
8
8
|
collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
|
|
@@ -10,19 +10,6 @@ interface LoadedConfig {
|
|
|
10
10
|
getDefaultMDXOptions(mode?: 'default' | 'remote'): Promise<ProcessorOptions>;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
interface BaseCollectionEntry {
|
|
14
|
-
/**
|
|
15
|
-
* Raw file path of collection entry, including absolute path (not normalized).
|
|
16
|
-
*/
|
|
17
|
-
_file: FileInfo;
|
|
18
|
-
}
|
|
19
|
-
interface FileInfo {
|
|
20
|
-
path: string;
|
|
21
|
-
absolutePath: string;
|
|
22
|
-
}
|
|
23
|
-
interface MarkdownProps extends Omit<CompiledMDXProperties, 'frontmatter' | 'default'> {
|
|
24
|
-
body: CompiledMDXProperties['default'];
|
|
25
|
-
}
|
|
26
13
|
interface RuntimeFile {
|
|
27
14
|
info: FileInfo;
|
|
28
15
|
data: Record<string, unknown>;
|
|
@@ -36,18 +23,8 @@ interface AsyncRuntimeFile {
|
|
|
36
23
|
};
|
|
37
24
|
lastModified?: Date;
|
|
38
25
|
}
|
|
39
|
-
type DocOut<Schema extends StandardSchemaV1> =
|
|
40
|
-
|
|
41
|
-
* Other exports in the compiled Markdown/MDX file
|
|
42
|
-
*/
|
|
43
|
-
_exports: Record<string, unknown>;
|
|
44
|
-
/**
|
|
45
|
-
* Read the original content of file from file system.
|
|
46
|
-
*/
|
|
47
|
-
get content(): string;
|
|
48
|
-
}, StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry>;
|
|
49
|
-
type Override<A, B> = Omit<A, keyof B> & B;
|
|
50
|
-
type MetaOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry;
|
|
26
|
+
type DocOut<Schema extends StandardSchemaV1 = StandardSchemaV1> = DocCollectionEntry<StandardSchemaV1.InferOutput<Schema>>;
|
|
27
|
+
type MetaOut<Schema extends StandardSchemaV1 = StandardSchemaV1> = MetaCollectionEntry<StandardSchemaV1.InferOutput<Schema>>;
|
|
51
28
|
interface Runtime {
|
|
52
29
|
doc: <C>(files: RuntimeFile[]) => C extends DocCollection<infer Schema, false> ? DocOut<Schema>[] : never;
|
|
53
30
|
meta: <C>(files: RuntimeFile[]) => C extends MetaCollection<infer Schema> ? MetaOut<Schema>[] : never;
|
|
@@ -60,10 +37,7 @@ interface Runtime {
|
|
|
60
37
|
}>;
|
|
61
38
|
} : never;
|
|
62
39
|
}
|
|
63
|
-
type AsyncDocOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema
|
|
64
|
-
content: string;
|
|
65
|
-
load: () => Promise<MarkdownProps & Record<string, unknown>>;
|
|
66
|
-
};
|
|
40
|
+
type AsyncDocOut<Schema extends StandardSchemaV1 = StandardSchemaV1> = AsyncDocCollectionEntry<StandardSchemaV1.InferOutput<Schema>>;
|
|
67
41
|
interface RuntimeAsync {
|
|
68
42
|
doc: <C>(files: AsyncRuntimeFile[], collection: string, config: LoadedConfig) => C extends DocCollection<infer Schema, true> ? AsyncDocOut<Schema>[] : never;
|
|
69
43
|
docs: <C>(docs: AsyncRuntimeFile[], metas: RuntimeFile[], collection: string, config: LoadedConfig) => C extends DocsCollection<infer DocSchema, infer MetaSchema, true> ? {
|
|
@@ -76,4 +50,4 @@ interface RuntimeAsync {
|
|
|
76
50
|
} : never;
|
|
77
51
|
}
|
|
78
52
|
|
|
79
|
-
export type {
|
|
53
|
+
export type { AsyncRuntimeFile as A, DocOut as D, LoadedConfig as L, MetaOut as M, Runtime as R, RuntimeFile as a, AsyncDocOut as b, RuntimeAsync as c };
|
package/dist/vite/index.cjs
CHANGED
|
@@ -30,86 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
-
// src/mdx
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}) {
|
|
37
|
-
return (tree, file) => {
|
|
38
|
-
let title;
|
|
39
|
-
const urls = [];
|
|
40
|
-
(0, import_unist_util_visit.visit)(tree, ["heading", "link"], (node) => {
|
|
41
|
-
if (node.type === "heading" && node.depth === 1) {
|
|
42
|
-
title = flattenNode(node);
|
|
43
|
-
}
|
|
44
|
-
if (node.type !== "link") return;
|
|
45
|
-
urls.push({
|
|
46
|
-
href: node.url
|
|
47
|
-
});
|
|
48
|
-
return "skip";
|
|
49
|
-
});
|
|
50
|
-
if (title) {
|
|
51
|
-
file.data.frontmatter ??= {};
|
|
52
|
-
if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
|
|
53
|
-
}
|
|
54
|
-
file.data.extractedReferences = urls;
|
|
55
|
-
for (const name of injectExports) {
|
|
56
|
-
if (!(name in file.data)) continue;
|
|
57
|
-
tree.children.unshift(getMdastExport(name, file.data[name]));
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function flattenNode(node) {
|
|
62
|
-
if ("children" in node)
|
|
63
|
-
return node.children.map((child) => flattenNode(child)).join("");
|
|
64
|
-
if ("value" in node) return node.value;
|
|
65
|
-
return "";
|
|
66
|
-
}
|
|
67
|
-
function getMdastExport(name, value) {
|
|
68
|
-
return {
|
|
69
|
-
type: "mdxjsEsm",
|
|
70
|
-
value: "",
|
|
71
|
-
data: {
|
|
72
|
-
estree: {
|
|
73
|
-
type: "Program",
|
|
74
|
-
sourceType: "module",
|
|
75
|
-
body: [
|
|
76
|
-
{
|
|
77
|
-
type: "ExportNamedDeclaration",
|
|
78
|
-
attributes: [],
|
|
79
|
-
specifiers: [],
|
|
80
|
-
source: null,
|
|
81
|
-
declaration: {
|
|
82
|
-
type: "VariableDeclaration",
|
|
83
|
-
kind: "let",
|
|
84
|
-
declarations: [
|
|
85
|
-
{
|
|
86
|
-
type: "VariableDeclarator",
|
|
87
|
-
id: {
|
|
88
|
-
type: "Identifier",
|
|
89
|
-
name
|
|
90
|
-
},
|
|
91
|
-
init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
|
|
92
|
-
}
|
|
93
|
-
]
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
]
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
var import_unist_util_visit, import_estree_util_value_to_estree;
|
|
102
|
-
var init_remark_postprocess = __esm({
|
|
103
|
-
"src/mdx-plugins/remark-postprocess.ts"() {
|
|
104
|
-
"use strict";
|
|
105
|
-
import_unist_util_visit = require("unist-util-visit");
|
|
106
|
-
import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// src/utils/mdx-options.ts
|
|
111
|
-
var mdx_options_exports = {};
|
|
112
|
-
__export(mdx_options_exports, {
|
|
33
|
+
// src/mdx/preset.ts
|
|
34
|
+
var preset_exports = {};
|
|
35
|
+
__export(preset_exports, {
|
|
113
36
|
getDefaultMDXOptions: () => getDefaultMDXOptions
|
|
114
37
|
});
|
|
115
38
|
function pluginOption(def, options = []) {
|
|
@@ -132,13 +55,6 @@ function getDefaultMDXOptions({
|
|
|
132
55
|
_withoutBundler = false,
|
|
133
56
|
...mdxOptions
|
|
134
57
|
}) {
|
|
135
|
-
const mdxExports = [
|
|
136
|
-
"structuredData",
|
|
137
|
-
"extractedReferences",
|
|
138
|
-
"frontmatter",
|
|
139
|
-
"lastModified",
|
|
140
|
-
...valueToExport
|
|
141
|
-
];
|
|
142
58
|
const remarkPlugins = pluginOption(
|
|
143
59
|
(v) => [
|
|
144
60
|
plugins.remarkGfm,
|
|
@@ -166,10 +82,15 @@ function getDefaultMDXOptions({
|
|
|
166
82
|
plugins.remarkStructure,
|
|
167
83
|
remarkStructureOptions
|
|
168
84
|
],
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
85
|
+
() => {
|
|
86
|
+
return (_, file) => {
|
|
87
|
+
file.data["mdx-export"] ??= [];
|
|
88
|
+
for (const name of valueToExport) {
|
|
89
|
+
if (name in file.data)
|
|
90
|
+
file.data["mdx-export"].push({ name, value: file.data[name] });
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
173
94
|
],
|
|
174
95
|
mdxOptions.remarkPlugins
|
|
175
96
|
);
|
|
@@ -189,11 +110,10 @@ function getDefaultMDXOptions({
|
|
|
189
110
|
};
|
|
190
111
|
}
|
|
191
112
|
var plugins;
|
|
192
|
-
var
|
|
193
|
-
"src/
|
|
113
|
+
var init_preset = __esm({
|
|
114
|
+
"src/mdx/preset.ts"() {
|
|
194
115
|
"use strict";
|
|
195
116
|
plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
|
|
196
|
-
init_remark_postprocess();
|
|
197
117
|
}
|
|
198
118
|
});
|
|
199
119
|
|
|
@@ -242,7 +162,7 @@ function buildConfig(config) {
|
|
|
242
162
|
const input = this.global.mdxOptions;
|
|
243
163
|
async function uncached() {
|
|
244
164
|
const options = typeof input === "function" ? await input() : input;
|
|
245
|
-
const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (
|
|
165
|
+
const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_preset(), preset_exports));
|
|
246
166
|
if (options?.preset === "minimal") return options;
|
|
247
167
|
return getDefaultMDXOptions2({
|
|
248
168
|
...options,
|
|
@@ -482,21 +402,21 @@ function countLines(s) {
|
|
|
482
402
|
return num;
|
|
483
403
|
}
|
|
484
404
|
|
|
485
|
-
// src/
|
|
405
|
+
// src/mdx/build-mdx.ts
|
|
486
406
|
var import_mdx = require("@mdx-js/mdx");
|
|
487
407
|
|
|
488
|
-
// src/mdx
|
|
408
|
+
// src/mdx/remark-include.ts
|
|
489
409
|
var import_unified = require("unified");
|
|
490
|
-
var
|
|
410
|
+
var import_unist_util_visit = require("unist-util-visit");
|
|
491
411
|
var path3 = __toESM(require("path"), 1);
|
|
492
412
|
var fs = __toESM(require("fs/promises"), 1);
|
|
493
413
|
var import_remark_parse = __toESM(require("remark-parse"), 1);
|
|
494
414
|
var import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
495
415
|
var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
496
416
|
var baseProcessor = (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading);
|
|
497
|
-
function
|
|
417
|
+
function flattenNode(node) {
|
|
498
418
|
if ("children" in node)
|
|
499
|
-
return node.children.map((child) =>
|
|
419
|
+
return node.children.map((child) => flattenNode(child)).join("");
|
|
500
420
|
if ("value" in node) return node.value;
|
|
501
421
|
return "";
|
|
502
422
|
}
|
|
@@ -575,14 +495,14 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
575
495
|
}
|
|
576
496
|
async function update(tree, directory, data) {
|
|
577
497
|
const queue = [];
|
|
578
|
-
(0,
|
|
498
|
+
(0, import_unist_util_visit.visit)(
|
|
579
499
|
tree,
|
|
580
500
|
["mdxJsxFlowElement", "mdxJsxTextElement"],
|
|
581
501
|
(_node, _, parent) => {
|
|
582
502
|
const node = _node;
|
|
583
503
|
if (node.name !== TagName) return;
|
|
584
504
|
const params = {};
|
|
585
|
-
const specifier =
|
|
505
|
+
const specifier = flattenNode(node);
|
|
586
506
|
if (specifier.length === 0) return "skip";
|
|
587
507
|
for (const attr of node.attributes) {
|
|
588
508
|
if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
|
|
@@ -617,7 +537,90 @@ function getDefaultProcessor(format) {
|
|
|
617
537
|
return mdProcessor.use(import_remark_mdx.default);
|
|
618
538
|
}
|
|
619
539
|
|
|
620
|
-
// src/
|
|
540
|
+
// src/mdx/remark-postprocess.ts
|
|
541
|
+
var import_unist_util_visit2 = require("unist-util-visit");
|
|
542
|
+
var import_mdast_util_to_markdown = require("mdast-util-to-markdown");
|
|
543
|
+
var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
544
|
+
function remarkPostprocess({
|
|
545
|
+
includeProcessedMarkdown = false,
|
|
546
|
+
valueToExport = []
|
|
547
|
+
} = {}) {
|
|
548
|
+
return (tree, file) => {
|
|
549
|
+
let title;
|
|
550
|
+
const urls = [];
|
|
551
|
+
(0, import_unist_util_visit2.visit)(tree, ["heading", "link"], (node) => {
|
|
552
|
+
if (node.type === "heading" && node.depth === 1) {
|
|
553
|
+
title = flattenNode2(node);
|
|
554
|
+
}
|
|
555
|
+
if (node.type !== "link") return;
|
|
556
|
+
urls.push({
|
|
557
|
+
href: node.url
|
|
558
|
+
});
|
|
559
|
+
return "skip";
|
|
560
|
+
});
|
|
561
|
+
if (title) {
|
|
562
|
+
file.data.frontmatter ??= {};
|
|
563
|
+
if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
|
|
564
|
+
}
|
|
565
|
+
file.data.extractedReferences = urls;
|
|
566
|
+
if (includeProcessedMarkdown) {
|
|
567
|
+
file.data._markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
|
|
568
|
+
...this.data("settings"),
|
|
569
|
+
// @ts-expect-error - from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
|
|
570
|
+
extensions: this.data("toMarkdownExtensions") || []
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
for (const { name, value } of file.data["mdx-export"] ?? []) {
|
|
574
|
+
tree.children.unshift(getMdastExport(name, value));
|
|
575
|
+
}
|
|
576
|
+
for (const name of valueToExport) {
|
|
577
|
+
if (!(name in file.data)) continue;
|
|
578
|
+
tree.children.unshift(getMdastExport(name, file.data[name]));
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
function getMdastExport(name, value) {
|
|
583
|
+
return {
|
|
584
|
+
type: "mdxjsEsm",
|
|
585
|
+
value: "",
|
|
586
|
+
data: {
|
|
587
|
+
estree: {
|
|
588
|
+
type: "Program",
|
|
589
|
+
sourceType: "module",
|
|
590
|
+
body: [
|
|
591
|
+
{
|
|
592
|
+
type: "ExportNamedDeclaration",
|
|
593
|
+
attributes: [],
|
|
594
|
+
specifiers: [],
|
|
595
|
+
source: null,
|
|
596
|
+
declaration: {
|
|
597
|
+
type: "VariableDeclaration",
|
|
598
|
+
kind: "let",
|
|
599
|
+
declarations: [
|
|
600
|
+
{
|
|
601
|
+
type: "VariableDeclarator",
|
|
602
|
+
id: {
|
|
603
|
+
type: "Identifier",
|
|
604
|
+
name
|
|
605
|
+
},
|
|
606
|
+
init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
|
|
607
|
+
}
|
|
608
|
+
]
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
]
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
function flattenNode2(node) {
|
|
617
|
+
if ("children" in node)
|
|
618
|
+
return node.children.map((child) => flattenNode2(child)).join("");
|
|
619
|
+
if ("value" in node) return node.value;
|
|
620
|
+
return "";
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// src/mdx/build-mdx.ts
|
|
621
624
|
var cache2 = /* @__PURE__ */ new Map();
|
|
622
625
|
async function buildMDX(cacheKey, source, options) {
|
|
623
626
|
const { filePath, frontmatter, data, _compiler, ...rest } = options;
|
|
@@ -628,7 +631,24 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
628
631
|
processor = (0, import_mdx.createProcessor)({
|
|
629
632
|
outputFormat: "program",
|
|
630
633
|
...rest,
|
|
631
|
-
remarkPlugins: [
|
|
634
|
+
remarkPlugins: [
|
|
635
|
+
remarkInclude,
|
|
636
|
+
...rest.remarkPlugins ?? [],
|
|
637
|
+
[
|
|
638
|
+
remarkPostprocess,
|
|
639
|
+
{
|
|
640
|
+
...options.postprocess,
|
|
641
|
+
valueToExport: [
|
|
642
|
+
...options.postprocess?.valueToExport ?? [],
|
|
643
|
+
"structuredData",
|
|
644
|
+
"extractedReferences",
|
|
645
|
+
"frontmatter",
|
|
646
|
+
"lastModified",
|
|
647
|
+
"_markdown"
|
|
648
|
+
]
|
|
649
|
+
}
|
|
650
|
+
]
|
|
651
|
+
],
|
|
632
652
|
format
|
|
633
653
|
});
|
|
634
654
|
cache2.set(key, processor);
|
|
@@ -684,21 +704,18 @@ function createMdxLoader(configLoader) {
|
|
|
684
704
|
if (cached && cached.hash === generateCacheHash(value)) return cached;
|
|
685
705
|
}
|
|
686
706
|
const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
|
|
687
|
-
let
|
|
688
|
-
let mdxOptions;
|
|
707
|
+
let docCollection;
|
|
689
708
|
switch (collection?.type) {
|
|
690
709
|
case "doc":
|
|
691
|
-
|
|
692
|
-
schema = collection.schema;
|
|
710
|
+
docCollection = collection;
|
|
693
711
|
break;
|
|
694
712
|
case "docs":
|
|
695
|
-
|
|
696
|
-
schema = collection.docs.schema;
|
|
713
|
+
docCollection = collection.docs;
|
|
697
714
|
break;
|
|
698
715
|
}
|
|
699
|
-
if (schema) {
|
|
716
|
+
if (docCollection?.schema) {
|
|
700
717
|
matter.data = await validate(
|
|
701
|
-
schema,
|
|
718
|
+
docCollection.schema,
|
|
702
719
|
matter.data,
|
|
703
720
|
{
|
|
704
721
|
source: value,
|
|
@@ -723,7 +740,8 @@ function createMdxLoader(configLoader) {
|
|
|
723
740
|
"\n".repeat(lineOffset) + matter.content,
|
|
724
741
|
{
|
|
725
742
|
development: isDevelopment,
|
|
726
|
-
...mdxOptions ?? await loaded.getDefaultMDXOptions(),
|
|
743
|
+
...docCollection?.mdxOptions ?? await loaded.getDefaultMDXOptions(),
|
|
744
|
+
postprocess: docCollection?.postprocess,
|
|
727
745
|
data,
|
|
728
746
|
filePath,
|
|
729
747
|
frontmatter: matter.data,
|
|
@@ -759,35 +777,6 @@ function findConfigFile() {
|
|
|
759
777
|
return path5.resolve("source.config.ts");
|
|
760
778
|
}
|
|
761
779
|
var cache3 = null;
|
|
762
|
-
async function isZod3() {
|
|
763
|
-
try {
|
|
764
|
-
const content = JSON.parse(
|
|
765
|
-
(await fs3.readFile("node_modules/zod/package.json")).toString()
|
|
766
|
-
);
|
|
767
|
-
const version = content.version;
|
|
768
|
-
return typeof version === "string" && version.startsWith("3.");
|
|
769
|
-
} catch {
|
|
770
|
-
return false;
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
function createCompatZodPlugin() {
|
|
774
|
-
return {
|
|
775
|
-
name: "replace-zod-import",
|
|
776
|
-
async setup(build) {
|
|
777
|
-
const usingZod3 = await isZod3();
|
|
778
|
-
if (!usingZod3) return;
|
|
779
|
-
console.warn(
|
|
780
|
-
"[Fumadocs MDX] Noticed Zod v3 in your node_modules, we recommend upgrading to Zod v4 for better compatibility."
|
|
781
|
-
);
|
|
782
|
-
build.onResolve({ filter: /^fumadocs-mdx\/config$/ }, () => {
|
|
783
|
-
return {
|
|
784
|
-
path: "fumadocs-mdx/config/zod-3",
|
|
785
|
-
external: true
|
|
786
|
-
};
|
|
787
|
-
});
|
|
788
|
-
}
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
780
|
async function compileConfig(configPath, outDir) {
|
|
792
781
|
const { build } = await import("esbuild");
|
|
793
782
|
const transformed = await build({
|
|
@@ -799,7 +788,6 @@ async function compileConfig(configPath, outDir) {
|
|
|
799
788
|
platform: "node",
|
|
800
789
|
format: "esm",
|
|
801
790
|
packages: "external",
|
|
802
|
-
plugins: [createCompatZodPlugin()],
|
|
803
791
|
outExtension: {
|
|
804
792
|
".js": ".mjs"
|
|
805
793
|
},
|
package/dist/vite/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
2
|
entry,
|
|
3
3
|
postInstall
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-TLD6JMT6.js";
|
|
5
5
|
import "../chunk-6Y5JDZHD.js";
|
|
6
6
|
import {
|
|
7
7
|
toVite
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-VXEBLM4X.js";
|
|
9
9
|
import {
|
|
10
10
|
createMdxLoader,
|
|
11
11
|
resolvedConfig
|
|
12
|
-
} from "../chunk-
|
|
13
|
-
import "../chunk-QQWCBFFE.js";
|
|
14
|
-
import "../chunk-SVTXMVLQ.js";
|
|
12
|
+
} from "../chunk-KGUBBRL6.js";
|
|
15
13
|
import {
|
|
16
14
|
ValidationError,
|
|
17
15
|
validate
|
|
18
16
|
} from "../chunk-IQAEAI4P.js";
|
|
19
|
-
import "../chunk-
|
|
17
|
+
import "../chunk-POXTQZ4D.js";
|
|
18
|
+
import "../chunk-SWNOXPYJ.js";
|
|
19
|
+
import "../chunk-KTDVTBMH.js";
|
|
20
20
|
import {
|
|
21
21
|
buildConfig
|
|
22
|
-
} from "../chunk-
|
|
22
|
+
} from "../chunk-YC25YEBF.js";
|
|
23
23
|
import "../chunk-VWJKRQZR.js";
|
|
24
24
|
|
|
25
25
|
// src/vite/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-mdx",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "The built-in source for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -18,11 +18,6 @@
|
|
|
18
18
|
"types": "./dist/config/index.d.ts",
|
|
19
19
|
"require": "./dist/config/index.cjs"
|
|
20
20
|
},
|
|
21
|
-
"./config/zod-3": {
|
|
22
|
-
"import": "./dist/config/zod-3.js",
|
|
23
|
-
"types": "./dist/config/zod-3.d.ts",
|
|
24
|
-
"require": "./dist/config/zod-3.cjs"
|
|
25
|
-
},
|
|
26
21
|
"./next": {
|
|
27
22
|
"import": "./dist/next/index.js",
|
|
28
23
|
"types": "./dist/next/index.d.ts",
|
|
@@ -70,6 +65,7 @@
|
|
|
70
65
|
"estree-util-value-to-estree": "^3.4.0",
|
|
71
66
|
"js-yaml": "^4.1.0",
|
|
72
67
|
"lru-cache": "^11.2.1",
|
|
68
|
+
"mdast-util-to-markdown": "^2.1.2",
|
|
73
69
|
"picocolors": "^1.1.1",
|
|
74
70
|
"remark-mdx": "^3.1.1",
|
|
75
71
|
"remark-parse": "^11.0.0",
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { createProcessor } from '@mdx-js/mdx';
|
|
2
|
-
import { StructuredData } from 'fumadocs-core/mdx-plugins';
|
|
3
|
-
import { TableOfContents } from 'fumadocs-core/server';
|
|
4
|
-
import { FC } from 'react';
|
|
5
|
-
import { MDXProps } from 'mdx/types';
|
|
6
|
-
|
|
7
|
-
declare module 'vfile' {
|
|
8
|
-
interface DataMap {
|
|
9
|
-
extractedReferences: ExtractedReference[];
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
interface ExtractedReference {
|
|
13
|
-
href: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type Processor = ReturnType<typeof createProcessor>;
|
|
17
|
-
interface CompilerOptions {
|
|
18
|
-
addDependency: (file: string) => void;
|
|
19
|
-
}
|
|
20
|
-
interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {
|
|
21
|
-
frontmatter: Frontmatter;
|
|
22
|
-
structuredData: StructuredData;
|
|
23
|
-
toc: TableOfContents;
|
|
24
|
-
default: FC<MDXProps>;
|
|
25
|
-
/**
|
|
26
|
-
* Only available when `lastModifiedTime` is enabled on MDX loader
|
|
27
|
-
*/
|
|
28
|
-
lastModified?: Date;
|
|
29
|
-
extractedReferences?: ExtractedReference[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
declare module 'vfile' {
|
|
33
|
-
interface DataMap {
|
|
34
|
-
/**
|
|
35
|
-
* [Fumadocs MDX] raw frontmatter, you can modify it
|
|
36
|
-
*/
|
|
37
|
-
frontmatter?: Record<string, unknown>;
|
|
38
|
-
/**
|
|
39
|
-
* [Fumadocs MDX] The compiler object from loader
|
|
40
|
-
*/
|
|
41
|
-
_compiler?: CompilerOptions;
|
|
42
|
-
_getProcessor?: (format: 'md' | 'mdx') => Processor;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type { CompiledMDXProperties as C };
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { createProcessor } from '@mdx-js/mdx';
|
|
2
|
-
import { StructuredData } from 'fumadocs-core/mdx-plugins';
|
|
3
|
-
import { TableOfContents } from 'fumadocs-core/server';
|
|
4
|
-
import { FC } from 'react';
|
|
5
|
-
import { MDXProps } from 'mdx/types';
|
|
6
|
-
|
|
7
|
-
declare module 'vfile' {
|
|
8
|
-
interface DataMap {
|
|
9
|
-
extractedReferences: ExtractedReference[];
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
interface ExtractedReference {
|
|
13
|
-
href: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type Processor = ReturnType<typeof createProcessor>;
|
|
17
|
-
interface CompilerOptions {
|
|
18
|
-
addDependency: (file: string) => void;
|
|
19
|
-
}
|
|
20
|
-
interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {
|
|
21
|
-
frontmatter: Frontmatter;
|
|
22
|
-
structuredData: StructuredData;
|
|
23
|
-
toc: TableOfContents;
|
|
24
|
-
default: FC<MDXProps>;
|
|
25
|
-
/**
|
|
26
|
-
* Only available when `lastModifiedTime` is enabled on MDX loader
|
|
27
|
-
*/
|
|
28
|
-
lastModified?: Date;
|
|
29
|
-
extractedReferences?: ExtractedReference[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
declare module 'vfile' {
|
|
33
|
-
interface DataMap {
|
|
34
|
-
/**
|
|
35
|
-
* [Fumadocs MDX] raw frontmatter, you can modify it
|
|
36
|
-
*/
|
|
37
|
-
frontmatter?: Record<string, unknown>;
|
|
38
|
-
/**
|
|
39
|
-
* [Fumadocs MDX] The compiler object from loader
|
|
40
|
-
*/
|
|
41
|
-
_compiler?: CompilerOptions;
|
|
42
|
-
_getProcessor?: (format: 'md' | 'mdx') => Processor;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type { CompiledMDXProperties as C };
|