fumadocs-mdx 11.10.0 → 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 +953 -0
- package/dist/bin.d.cts +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +16 -0
- 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 +129 -109
- package/dist/bun/index.js +9 -6
- package/dist/chunk-3M4SHY6K.js +80 -0
- package/dist/chunk-6Y5JDZHD.js +65 -0
- package/dist/{chunk-NUDEC6C5.js → chunk-AUOOMFAI.js} +28 -22
- package/dist/chunk-IQAEAI4P.js +66 -0
- package/dist/{chunk-5XJM5RPV.js → chunk-KGUBBRL6.js} +13 -13
- package/dist/{chunk-SVTXMVLQ.js → chunk-KTDVTBMH.js} +1 -1
- package/dist/chunk-POXTQZ4D.js +60 -0
- package/dist/chunk-SWNOXPYJ.js +142 -0
- package/dist/{chunk-COQ4VMK2.js → chunk-TLD6JMT6.js} +28 -61
- package/dist/{chunk-NVX3U5YE.js → chunk-VXEBLM4X.js} +2 -2
- 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.cts → define--6HQ1ehX.d.cts} +18 -3
- package/dist/{define-BH4bnHQl.d.ts → define--6HQ1ehX.d.ts} +18 -3
- package/dist/loader-mdx.cjs +127 -139
- package/dist/loader-mdx.js +7 -6
- package/dist/next/index.cjs +44 -269
- package/dist/next/index.js +30 -46
- package/dist/node/loader.cjs +131 -143
- package/dist/node/loader.js +7 -6
- package/dist/postinstall-U7VROOY7.js +9 -0
- package/dist/{mdx-options-T73E4LQB.js → preset-WFEORCAB.js} +1 -1
- package/dist/runtime/{async.cjs → next/async.cjs} +202 -154
- package/dist/runtime/{async.d.cts → next/async.d.cts} +3 -3
- package/dist/runtime/{async.d.ts → next/async.d.ts} +3 -3
- package/dist/runtime/next/async.js +92 -0
- package/dist/{index.cjs → runtime/next/index.cjs} +35 -26
- package/dist/runtime/next/index.d.cts +30 -0
- package/dist/runtime/next/index.d.ts +30 -0
- package/dist/{index.js → 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 +201 -123
- package/dist/vite/index.d.cts +4 -1
- package/dist/vite/index.d.ts +4 -1
- package/dist/vite/index.js +13 -9
- package/package.json +11 -17
- package/bin.js +0 -5
- package/dist/build-mdx-DnC1jKvn.d.cts +0 -46
- package/dist/build-mdx-DnC1jKvn.d.ts +0 -46
- package/dist/chunk-2HKRTQYP.js +0 -154
- 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/index.d.cts +0 -26
- package/dist/index.d.ts +0 -26
- package/dist/runtime/async.js +0 -72
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { StructuredData } from 'fumadocs-core/mdx-plugins';
|
|
2
|
+
import { TableOfContents } from 'fumadocs-core/server';
|
|
3
|
+
import { FC } from 'react';
|
|
4
|
+
import { MDXProps } from 'mdx/types';
|
|
5
|
+
import { E as ExtractedReference } from './define--6HQ1ehX.cjs';
|
|
6
|
+
|
|
7
|
+
interface FileInfo {
|
|
8
|
+
/**
|
|
9
|
+
* virtualized path for Source API
|
|
10
|
+
*/
|
|
11
|
+
path: string;
|
|
12
|
+
/**
|
|
13
|
+
* the file path in file system
|
|
14
|
+
*/
|
|
15
|
+
fullPath: string;
|
|
16
|
+
}
|
|
17
|
+
interface DocData {
|
|
18
|
+
/**
|
|
19
|
+
* Compiled MDX content (as component)
|
|
20
|
+
*/
|
|
21
|
+
body: FC<MDXProps>;
|
|
22
|
+
/**
|
|
23
|
+
* table of contents generated from content.
|
|
24
|
+
*/
|
|
25
|
+
toc: TableOfContents;
|
|
26
|
+
/**
|
|
27
|
+
* structured data for document search indexing.
|
|
28
|
+
*/
|
|
29
|
+
structuredData: StructuredData;
|
|
30
|
+
/**
|
|
31
|
+
* Raw exports from the compiled MDX file.
|
|
32
|
+
*/
|
|
33
|
+
_exports: Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Last modified date of document file, obtained from version control.
|
|
36
|
+
*
|
|
37
|
+
* Only available when `lastModifiedTime` is enabled on global config.
|
|
38
|
+
*/
|
|
39
|
+
lastModified?: Date;
|
|
40
|
+
/**
|
|
41
|
+
* extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
|
|
42
|
+
*/
|
|
43
|
+
extractedReferences?: ExtractedReference[];
|
|
44
|
+
}
|
|
45
|
+
interface DocMethods {
|
|
46
|
+
/**
|
|
47
|
+
* file info
|
|
48
|
+
*/
|
|
49
|
+
info: FileInfo;
|
|
50
|
+
/**
|
|
51
|
+
* get document as text.
|
|
52
|
+
*
|
|
53
|
+
* - `type: raw` - read the original content from file system.
|
|
54
|
+
* - `type: processed` - get the processed Markdown content, only available when `includeProcessedMarkdown` is enabled on collection config.
|
|
55
|
+
*/
|
|
56
|
+
getText: (type: 'raw' | 'processed') => Promise<string>;
|
|
57
|
+
}
|
|
58
|
+
type MetaCollectionEntry<Data> = Data & {
|
|
59
|
+
/**
|
|
60
|
+
* file info
|
|
61
|
+
*/
|
|
62
|
+
info: FileInfo;
|
|
63
|
+
};
|
|
64
|
+
type DocCollectionEntry<Frontmatter> = Override<DocData & DocMethods, Frontmatter>;
|
|
65
|
+
type AsyncDocCollectionEntry<Frontmatter> = Override<DocMethods & {
|
|
66
|
+
load: () => Promise<DocData>;
|
|
67
|
+
}, Frontmatter>;
|
|
68
|
+
type Override<A, B> = Omit<A, keyof B> & B;
|
|
69
|
+
|
|
70
|
+
export type { AsyncDocCollectionEntry as A, DocCollectionEntry as D, FileInfo as F, MetaCollectionEntry as M };
|
|
@@ -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,18 +110,18 @@ 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
|
|
|
200
120
|
// src/vite/index.ts
|
|
201
121
|
var vite_exports = {};
|
|
202
122
|
__export(vite_exports, {
|
|
203
|
-
default: () => mdx
|
|
123
|
+
default: () => mdx,
|
|
124
|
+
postInstall: () => postInstall
|
|
204
125
|
});
|
|
205
126
|
module.exports = __toCommonJS(vite_exports);
|
|
206
127
|
var import_vite = require("vite");
|
|
@@ -241,7 +162,7 @@ function buildConfig(config) {
|
|
|
241
162
|
const input = this.global.mdxOptions;
|
|
242
163
|
async function uncached() {
|
|
243
164
|
const options = typeof input === "function" ? await input() : input;
|
|
244
|
-
const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (
|
|
165
|
+
const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_preset(), preset_exports));
|
|
245
166
|
if (options?.preset === "minimal") return options;
|
|
246
167
|
return getDefaultMDXOptions2({
|
|
247
168
|
...options,
|
|
@@ -297,8 +218,8 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
297
218
|
}
|
|
298
219
|
|
|
299
220
|
// src/vite/index.ts
|
|
300
|
-
var
|
|
301
|
-
var
|
|
221
|
+
var fs6 = __toESM(require("fs/promises"), 1);
|
|
222
|
+
var path8 = __toESM(require("path"), 1);
|
|
302
223
|
var import_js_yaml2 = require("js-yaml");
|
|
303
224
|
|
|
304
225
|
// src/utils/import-formatter.ts
|
|
@@ -481,21 +402,21 @@ function countLines(s) {
|
|
|
481
402
|
return num;
|
|
482
403
|
}
|
|
483
404
|
|
|
484
|
-
// src/
|
|
405
|
+
// src/mdx/build-mdx.ts
|
|
485
406
|
var import_mdx = require("@mdx-js/mdx");
|
|
486
407
|
|
|
487
|
-
// src/mdx
|
|
408
|
+
// src/mdx/remark-include.ts
|
|
488
409
|
var import_unified = require("unified");
|
|
489
|
-
var
|
|
410
|
+
var import_unist_util_visit = require("unist-util-visit");
|
|
490
411
|
var path3 = __toESM(require("path"), 1);
|
|
491
412
|
var fs = __toESM(require("fs/promises"), 1);
|
|
492
413
|
var import_remark_parse = __toESM(require("remark-parse"), 1);
|
|
493
414
|
var import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
494
415
|
var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
495
416
|
var baseProcessor = (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading);
|
|
496
|
-
function
|
|
417
|
+
function flattenNode(node) {
|
|
497
418
|
if ("children" in node)
|
|
498
|
-
return node.children.map((child) =>
|
|
419
|
+
return node.children.map((child) => flattenNode(child)).join("");
|
|
499
420
|
if ("value" in node) return node.value;
|
|
500
421
|
return "";
|
|
501
422
|
}
|
|
@@ -574,14 +495,14 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
574
495
|
}
|
|
575
496
|
async function update(tree, directory, data) {
|
|
576
497
|
const queue = [];
|
|
577
|
-
(0,
|
|
498
|
+
(0, import_unist_util_visit.visit)(
|
|
578
499
|
tree,
|
|
579
500
|
["mdxJsxFlowElement", "mdxJsxTextElement"],
|
|
580
501
|
(_node, _, parent) => {
|
|
581
502
|
const node = _node;
|
|
582
503
|
if (node.name !== TagName) return;
|
|
583
504
|
const params = {};
|
|
584
|
-
const specifier =
|
|
505
|
+
const specifier = flattenNode(node);
|
|
585
506
|
if (specifier.length === 0) return "skip";
|
|
586
507
|
for (const attr of node.attributes) {
|
|
587
508
|
if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
|
|
@@ -616,7 +537,90 @@ function getDefaultProcessor(format) {
|
|
|
616
537
|
return mdProcessor.use(import_remark_mdx.default);
|
|
617
538
|
}
|
|
618
539
|
|
|
619
|
-
// 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
|
|
620
624
|
var cache2 = /* @__PURE__ */ new Map();
|
|
621
625
|
async function buildMDX(cacheKey, source, options) {
|
|
622
626
|
const { filePath, frontmatter, data, _compiler, ...rest } = options;
|
|
@@ -627,7 +631,24 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
627
631
|
processor = (0, import_mdx.createProcessor)({
|
|
628
632
|
outputFormat: "program",
|
|
629
633
|
...rest,
|
|
630
|
-
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
|
+
],
|
|
631
652
|
format
|
|
632
653
|
});
|
|
633
654
|
cache2.set(key, processor);
|
|
@@ -683,21 +704,18 @@ function createMdxLoader(configLoader) {
|
|
|
683
704
|
if (cached && cached.hash === generateCacheHash(value)) return cached;
|
|
684
705
|
}
|
|
685
706
|
const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
|
|
686
|
-
let
|
|
687
|
-
let mdxOptions;
|
|
707
|
+
let docCollection;
|
|
688
708
|
switch (collection?.type) {
|
|
689
709
|
case "doc":
|
|
690
|
-
|
|
691
|
-
schema = collection.schema;
|
|
710
|
+
docCollection = collection;
|
|
692
711
|
break;
|
|
693
712
|
case "docs":
|
|
694
|
-
|
|
695
|
-
schema = collection.docs.schema;
|
|
713
|
+
docCollection = collection.docs;
|
|
696
714
|
break;
|
|
697
715
|
}
|
|
698
|
-
if (schema) {
|
|
716
|
+
if (docCollection?.schema) {
|
|
699
717
|
matter.data = await validate(
|
|
700
|
-
schema,
|
|
718
|
+
docCollection.schema,
|
|
701
719
|
matter.data,
|
|
702
720
|
{
|
|
703
721
|
source: value,
|
|
@@ -722,7 +740,8 @@ function createMdxLoader(configLoader) {
|
|
|
722
740
|
"\n".repeat(lineOffset) + matter.content,
|
|
723
741
|
{
|
|
724
742
|
development: isDevelopment,
|
|
725
|
-
...mdxOptions ?? await loaded.getDefaultMDXOptions(),
|
|
743
|
+
...docCollection?.mdxOptions ?? await loaded.getDefaultMDXOptions(),
|
|
744
|
+
postprocess: docCollection?.postprocess,
|
|
726
745
|
data,
|
|
727
746
|
filePath,
|
|
728
747
|
frontmatter: matter.data,
|
|
@@ -754,6 +773,45 @@ function generateCacheHash(input) {
|
|
|
754
773
|
var fs3 = __toESM(require("fs/promises"), 1);
|
|
755
774
|
var path5 = __toESM(require("path"), 1);
|
|
756
775
|
var import_node_url = require("url");
|
|
776
|
+
function findConfigFile() {
|
|
777
|
+
return path5.resolve("source.config.ts");
|
|
778
|
+
}
|
|
779
|
+
var cache3 = null;
|
|
780
|
+
async function compileConfig(configPath, outDir) {
|
|
781
|
+
const { build } = await import("esbuild");
|
|
782
|
+
const transformed = await build({
|
|
783
|
+
entryPoints: [{ in: configPath, out: "source.config" }],
|
|
784
|
+
bundle: true,
|
|
785
|
+
outdir: outDir,
|
|
786
|
+
target: "node20",
|
|
787
|
+
write: true,
|
|
788
|
+
platform: "node",
|
|
789
|
+
format: "esm",
|
|
790
|
+
packages: "external",
|
|
791
|
+
outExtension: {
|
|
792
|
+
".js": ".mjs"
|
|
793
|
+
},
|
|
794
|
+
allowOverwrite: true
|
|
795
|
+
});
|
|
796
|
+
if (transformed.errors.length > 0) {
|
|
797
|
+
throw new Error("failed to compile configuration file");
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
async function loadConfig(configPath, outDir, hash, build = false) {
|
|
801
|
+
if (cache3 && cache3.hash === hash) {
|
|
802
|
+
return await cache3.config;
|
|
803
|
+
}
|
|
804
|
+
if (build) await compileConfig(configPath, outDir);
|
|
805
|
+
const url = (0, import_node_url.pathToFileURL)(path5.resolve(outDir, "source.config.mjs"));
|
|
806
|
+
const config = import(`${url.href}?hash=${hash}`).then((loaded) => {
|
|
807
|
+
return buildConfig(
|
|
808
|
+
// every call to `loadConfig` will cause the previous cache to be ignored
|
|
809
|
+
loaded
|
|
810
|
+
);
|
|
811
|
+
});
|
|
812
|
+
if (hash) cache3 = { config, hash };
|
|
813
|
+
return await config;
|
|
814
|
+
}
|
|
757
815
|
|
|
758
816
|
// src/loaders/config-loader.ts
|
|
759
817
|
function resolvedConfig(loaded) {
|
|
@@ -789,14 +847,30 @@ function toVite(loader) {
|
|
|
789
847
|
};
|
|
790
848
|
}
|
|
791
849
|
|
|
850
|
+
// src/vite/postinstall.ts
|
|
851
|
+
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
852
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
853
|
+
async function postInstall(configPath = findConfigFile(), outDir, addJsExtension = false) {
|
|
854
|
+
const config = await loadConfig(configPath, "node_modules", void 0, true);
|
|
855
|
+
const outFile = "source.generated.ts";
|
|
856
|
+
if (outDir) {
|
|
857
|
+
await import_promises3.default.mkdir(outDir, { recursive: true });
|
|
858
|
+
}
|
|
859
|
+
await import_promises3.default.writeFile(
|
|
860
|
+
outDir ? import_node_path5.default.join(outDir, outFile) : outFile,
|
|
861
|
+
entry(configPath, config, outDir ?? process.cwd(), addJsExtension)
|
|
862
|
+
);
|
|
863
|
+
console.log("[MDX] types generated");
|
|
864
|
+
}
|
|
865
|
+
|
|
792
866
|
// src/vite/index.ts
|
|
793
867
|
var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
|
|
794
868
|
function mdx(config, options = {}) {
|
|
795
869
|
const { generateIndexFile = true, configPath = "source.config.ts" } = options;
|
|
796
870
|
const loaded = buildConfig(config);
|
|
797
871
|
const mdxLoader = toVite(createMdxLoader(resolvedConfig(loaded)));
|
|
798
|
-
async function transformMeta(
|
|
799
|
-
const isJson =
|
|
872
|
+
async function transformMeta(path9, query, value) {
|
|
873
|
+
const isJson = path9.endsWith(".json");
|
|
800
874
|
const parsed = (0, import_node_querystring2.parse)(query);
|
|
801
875
|
const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
|
|
802
876
|
if (!collection) return null;
|
|
@@ -819,8 +893,8 @@ function mdx(config, options = {}) {
|
|
|
819
893
|
const out = await validate(
|
|
820
894
|
schema,
|
|
821
895
|
data,
|
|
822
|
-
{ path:
|
|
823
|
-
`invalid data in ${
|
|
896
|
+
{ path: path9, source: value },
|
|
897
|
+
`invalid data in ${path9}`
|
|
824
898
|
);
|
|
825
899
|
return {
|
|
826
900
|
code: isJson ? JSON.stringify(out) : `export default ${JSON.stringify(out)}`,
|
|
@@ -847,8 +921,8 @@ function mdx(config, options = {}) {
|
|
|
847
921
|
console.log("[Fumadocs MDX] Generating index files");
|
|
848
922
|
const outDir = process.cwd();
|
|
849
923
|
const outFile = "source.generated.ts";
|
|
850
|
-
await
|
|
851
|
-
|
|
924
|
+
await fs6.writeFile(
|
|
925
|
+
path8.join(outDir, outFile),
|
|
852
926
|
entry(
|
|
853
927
|
configPath,
|
|
854
928
|
loaded,
|
|
@@ -859,7 +933,7 @@ function mdx(config, options = {}) {
|
|
|
859
933
|
},
|
|
860
934
|
async transform(value, id) {
|
|
861
935
|
const [file, query = ""] = id.split("?");
|
|
862
|
-
const ext =
|
|
936
|
+
const ext = path8.extname(file);
|
|
863
937
|
try {
|
|
864
938
|
if ([".yaml", ".json"].includes(ext))
|
|
865
939
|
return await transformMeta(file, query, value);
|
|
@@ -874,3 +948,7 @@ function mdx(config, options = {}) {
|
|
|
874
948
|
}
|
|
875
949
|
};
|
|
876
950
|
}
|
|
951
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
952
|
+
0 && (module.exports = {
|
|
953
|
+
postInstall
|
|
954
|
+
});
|