fumadocs-mdx 9.0.4 → 10.0.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/bin.mjs +5 -0
- package/dist/chunk-LRV535YP.mjs +161 -0
- package/dist/chunk-P6WKCOD5.mjs +139 -0
- package/dist/config/index.d.mts +171 -0
- package/dist/config/index.mjs +16 -0
- package/dist/index.d.mts +20 -93
- package/dist/index.mjs +49 -87
- package/dist/loader-mdx.d.mts +13 -13
- package/dist/loader-mdx.mjs +167 -44
- package/dist/next/index.d.mts +13 -0
- package/dist/next/index.mjs +239 -0
- package/package.json +20 -9
- package/dist/config.d.mts +0 -45
- package/dist/config.mjs +0 -264
- package/dist/loader.d.mts +0 -18
- package/dist/loader.mjs +0 -36
- package/dist/search-index-plugin-DG9nZ1CX.d.mts +0 -40
- package/loader.js +0 -8
package/bin.mjs
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// src/utils/schema.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var metaSchema = z.object({
|
|
4
|
+
title: z.string().optional(),
|
|
5
|
+
pages: z.array(z.string()).optional(),
|
|
6
|
+
root: z.boolean().optional(),
|
|
7
|
+
defaultOpen: z.boolean().optional(),
|
|
8
|
+
icon: z.string().optional()
|
|
9
|
+
});
|
|
10
|
+
var frontmatterSchema = z.object({
|
|
11
|
+
title: z.string(),
|
|
12
|
+
description: z.string().optional(),
|
|
13
|
+
icon: z.string().optional(),
|
|
14
|
+
full: z.boolean().optional(),
|
|
15
|
+
// Fumadocs OpenAPI generated
|
|
16
|
+
_openapi: z.object({}).passthrough().optional()
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// src/config/define.ts
|
|
20
|
+
function defineCollections(options) {
|
|
21
|
+
return {
|
|
22
|
+
_doc: "collections",
|
|
23
|
+
...options
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function defineDocs(options) {
|
|
27
|
+
return {
|
|
28
|
+
docs: defineCollections({
|
|
29
|
+
type: "doc",
|
|
30
|
+
dir: "content/docs",
|
|
31
|
+
schema: frontmatterSchema,
|
|
32
|
+
...options?.docs
|
|
33
|
+
}),
|
|
34
|
+
meta: defineCollections({
|
|
35
|
+
type: "meta",
|
|
36
|
+
dir: "content/docs",
|
|
37
|
+
schema: metaSchema,
|
|
38
|
+
...options?.meta
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function defineConfig(config = {}) {
|
|
43
|
+
return config;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/utils/mdx-options.ts
|
|
47
|
+
import {
|
|
48
|
+
rehypeCode,
|
|
49
|
+
remarkGfm,
|
|
50
|
+
remarkHeading,
|
|
51
|
+
remarkImage,
|
|
52
|
+
remarkStructure
|
|
53
|
+
} from "fumadocs-core/mdx-plugins";
|
|
54
|
+
|
|
55
|
+
// src/mdx-plugins/utils.ts
|
|
56
|
+
import { valueToEstree } from "estree-util-value-to-estree";
|
|
57
|
+
function getMdastExport(name, value) {
|
|
58
|
+
return {
|
|
59
|
+
type: "mdxjsEsm",
|
|
60
|
+
value: "",
|
|
61
|
+
data: {
|
|
62
|
+
estree: {
|
|
63
|
+
type: "Program",
|
|
64
|
+
sourceType: "module",
|
|
65
|
+
body: [
|
|
66
|
+
{
|
|
67
|
+
type: "ExportNamedDeclaration",
|
|
68
|
+
specifiers: [],
|
|
69
|
+
source: null,
|
|
70
|
+
declaration: {
|
|
71
|
+
type: "VariableDeclaration",
|
|
72
|
+
kind: "let",
|
|
73
|
+
declarations: [
|
|
74
|
+
{
|
|
75
|
+
type: "VariableDeclarator",
|
|
76
|
+
id: {
|
|
77
|
+
type: "Identifier",
|
|
78
|
+
name
|
|
79
|
+
},
|
|
80
|
+
init: valueToEstree(value)
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/mdx-plugins/remark-exports.ts
|
|
92
|
+
function remarkMdxExport({ values }) {
|
|
93
|
+
return (tree, vfile) => {
|
|
94
|
+
for (const name of values) {
|
|
95
|
+
if (!(name in vfile.data)) return;
|
|
96
|
+
tree.children.unshift(getMdastExport(name, vfile.data[name]));
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/utils/mdx-options.ts
|
|
102
|
+
function pluginOption(def, options = []) {
|
|
103
|
+
const list = def(Array.isArray(options) ? options : []).filter(
|
|
104
|
+
Boolean
|
|
105
|
+
);
|
|
106
|
+
if (typeof options === "function") {
|
|
107
|
+
return options(list);
|
|
108
|
+
}
|
|
109
|
+
return list;
|
|
110
|
+
}
|
|
111
|
+
function getDefaultMDXOptions({
|
|
112
|
+
valueToExport = [],
|
|
113
|
+
rehypeCodeOptions,
|
|
114
|
+
remarkImageOptions,
|
|
115
|
+
remarkHeadingOptions,
|
|
116
|
+
remarkStructureOptions,
|
|
117
|
+
...mdxOptions
|
|
118
|
+
}) {
|
|
119
|
+
const mdxExports = [
|
|
120
|
+
"structuredData",
|
|
121
|
+
"toc",
|
|
122
|
+
"frontmatter",
|
|
123
|
+
"lastModified",
|
|
124
|
+
...valueToExport
|
|
125
|
+
];
|
|
126
|
+
const remarkPlugins = pluginOption(
|
|
127
|
+
(v) => [
|
|
128
|
+
remarkGfm,
|
|
129
|
+
[remarkHeading, remarkHeadingOptions],
|
|
130
|
+
remarkImageOptions !== false && [remarkImage, remarkImageOptions],
|
|
131
|
+
...v,
|
|
132
|
+
remarkStructureOptions !== false && [
|
|
133
|
+
remarkStructure,
|
|
134
|
+
remarkStructureOptions
|
|
135
|
+
],
|
|
136
|
+
[remarkMdxExport, { values: mdxExports }]
|
|
137
|
+
],
|
|
138
|
+
mdxOptions.remarkPlugins
|
|
139
|
+
);
|
|
140
|
+
const rehypePlugins = pluginOption(
|
|
141
|
+
(v) => [
|
|
142
|
+
rehypeCodeOptions !== false && [rehypeCode, rehypeCodeOptions],
|
|
143
|
+
...v
|
|
144
|
+
],
|
|
145
|
+
mdxOptions.rehypePlugins
|
|
146
|
+
);
|
|
147
|
+
return {
|
|
148
|
+
...mdxOptions,
|
|
149
|
+
remarkPlugins,
|
|
150
|
+
rehypePlugins
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export {
|
|
155
|
+
metaSchema,
|
|
156
|
+
frontmatterSchema,
|
|
157
|
+
defineCollections,
|
|
158
|
+
defineDocs,
|
|
159
|
+
defineConfig,
|
|
160
|
+
getDefaultMDXOptions
|
|
161
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// src/config/cached.ts
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
|
|
5
|
+
// src/config/load.ts
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
8
|
+
import { build } from "esbuild";
|
|
9
|
+
|
|
10
|
+
// src/config/validate.ts
|
|
11
|
+
function validateConfig(config) {
|
|
12
|
+
const out = {
|
|
13
|
+
collections: /* @__PURE__ */ new Map(),
|
|
14
|
+
_runtime: {
|
|
15
|
+
files: /* @__PURE__ */ new Map()
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
for (const [k, v] of Object.entries(config)) {
|
|
19
|
+
if (!v) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (typeof v === "object" && "_doc" in v && v._doc === "collections") {
|
|
23
|
+
out.collections.set(k, v);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (k === "default") {
|
|
27
|
+
out.global = v;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
return [
|
|
31
|
+
`Unknown export "${k}", you can only export collections from source configuration file.`,
|
|
32
|
+
null
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
return [null, out];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/config/load.ts
|
|
39
|
+
function findConfigFile() {
|
|
40
|
+
return path.resolve("source.config.ts");
|
|
41
|
+
}
|
|
42
|
+
async function loadConfig(configPath) {
|
|
43
|
+
const outputPath = path.resolve(".source/source.config.mjs");
|
|
44
|
+
const transformed = await build({
|
|
45
|
+
entryPoints: [{ in: configPath, out: "source.config" }],
|
|
46
|
+
bundle: true,
|
|
47
|
+
outdir: ".source",
|
|
48
|
+
target: "node18",
|
|
49
|
+
write: true,
|
|
50
|
+
platform: "node",
|
|
51
|
+
format: "esm",
|
|
52
|
+
packages: "external",
|
|
53
|
+
outExtension: {
|
|
54
|
+
".js": ".mjs"
|
|
55
|
+
},
|
|
56
|
+
allowOverwrite: true,
|
|
57
|
+
splitting: true
|
|
58
|
+
});
|
|
59
|
+
if (transformed.errors.length > 0) {
|
|
60
|
+
throw new Error("failed to compile configuration file");
|
|
61
|
+
}
|
|
62
|
+
const url = pathToFileURL(outputPath);
|
|
63
|
+
const [err, config] = validateConfig(
|
|
64
|
+
// every call to `loadConfig` will cause the previous cache to be ignored
|
|
65
|
+
await import(`${url.toString()}?hash=${Date.now().toString()}`)
|
|
66
|
+
);
|
|
67
|
+
if (err !== null) throw new Error(err);
|
|
68
|
+
return config;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/config/cached.ts
|
|
72
|
+
var cache = /* @__PURE__ */ new Map();
|
|
73
|
+
async function loadConfigCached(configPath, hash) {
|
|
74
|
+
const cached = cache.get(configPath);
|
|
75
|
+
if (cached && cached.hash === hash) {
|
|
76
|
+
return await cached.config;
|
|
77
|
+
}
|
|
78
|
+
const config = loadConfig(configPath);
|
|
79
|
+
cache.set(configPath, { config, hash });
|
|
80
|
+
return await config;
|
|
81
|
+
}
|
|
82
|
+
async function getConfigHash(configPath) {
|
|
83
|
+
const hash = createHash("sha256");
|
|
84
|
+
const rs = fs.createReadStream(configPath);
|
|
85
|
+
for await (const chunk of rs) {
|
|
86
|
+
hash.update(chunk);
|
|
87
|
+
}
|
|
88
|
+
return hash.digest("hex");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/map/manifest.ts
|
|
92
|
+
import fs2 from "node:fs";
|
|
93
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
94
|
+
import path2 from "node:path";
|
|
95
|
+
|
|
96
|
+
// src/utils/get-type-from-path.ts
|
|
97
|
+
import { extname } from "node:path";
|
|
98
|
+
var docTypes = [".mdx", ".md"];
|
|
99
|
+
var metaTypes = [".json", ".yaml"];
|
|
100
|
+
function getTypeFromPath(path3) {
|
|
101
|
+
const ext = extname(path3);
|
|
102
|
+
if (docTypes.includes(ext)) return "doc";
|
|
103
|
+
if (metaTypes.includes(ext)) return "meta";
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/map/manifest.ts
|
|
107
|
+
function getKey(key) {
|
|
108
|
+
return createHash2("sha256").update(key).digest("hex");
|
|
109
|
+
}
|
|
110
|
+
function writeManifest(to, config) {
|
|
111
|
+
const output = { files: [] };
|
|
112
|
+
for (const [file, collection] of config._runtime.files.entries()) {
|
|
113
|
+
const type = config.collections.get(collection)?.type ?? getTypeFromPath(file);
|
|
114
|
+
if (type === "meta") continue;
|
|
115
|
+
try {
|
|
116
|
+
const content = fs2.readFileSync(
|
|
117
|
+
path2.resolve(".next/cache/fumadocs", `${getKey(file)}.json`)
|
|
118
|
+
);
|
|
119
|
+
const meta = JSON.parse(content.toString());
|
|
120
|
+
output.files.push({
|
|
121
|
+
...meta,
|
|
122
|
+
collection
|
|
123
|
+
});
|
|
124
|
+
} catch (e) {
|
|
125
|
+
console.error(`cannot find the search index of ${file}`, e);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
fs2.writeFileSync(to, JSON.stringify(output));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export {
|
|
132
|
+
findConfigFile,
|
|
133
|
+
loadConfig,
|
|
134
|
+
loadConfigCached,
|
|
135
|
+
getConfigHash,
|
|
136
|
+
getTypeFromPath,
|
|
137
|
+
getKey,
|
|
138
|
+
writeManifest
|
|
139
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { z, ZodTypeAny } from 'zod';
|
|
2
|
+
import { MDXProps } from 'mdx/types';
|
|
3
|
+
import { StructureOptions, RemarkHeadingOptions, RemarkImageOptions, RehypeCodeOptions, StructuredData } from 'fumadocs-core/mdx-plugins';
|
|
4
|
+
import { TableOfContents } from 'fumadocs-core/server';
|
|
5
|
+
import { ProcessorOptions } from '@mdx-js/mdx';
|
|
6
|
+
import { Pluggable } from 'unified';
|
|
7
|
+
|
|
8
|
+
interface MDXOptions extends ProcessorOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Name of collection
|
|
11
|
+
*/
|
|
12
|
+
collection?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Specify a file path for source
|
|
15
|
+
*/
|
|
16
|
+
filePath?: string;
|
|
17
|
+
frontmatter?: Record<string, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Custom Vfile data
|
|
20
|
+
*/
|
|
21
|
+
data?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare const metaSchema: z.ZodObject<{
|
|
25
|
+
title: z.ZodOptional<z.ZodString>;
|
|
26
|
+
pages: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
27
|
+
root: z.ZodOptional<z.ZodBoolean>;
|
|
28
|
+
defaultOpen: z.ZodOptional<z.ZodBoolean>;
|
|
29
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
30
|
+
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
title?: string | undefined;
|
|
32
|
+
pages?: string[] | undefined;
|
|
33
|
+
root?: boolean | undefined;
|
|
34
|
+
defaultOpen?: boolean | undefined;
|
|
35
|
+
icon?: string | undefined;
|
|
36
|
+
}, {
|
|
37
|
+
title?: string | undefined;
|
|
38
|
+
pages?: string[] | undefined;
|
|
39
|
+
root?: boolean | undefined;
|
|
40
|
+
defaultOpen?: boolean | undefined;
|
|
41
|
+
icon?: string | undefined;
|
|
42
|
+
}>;
|
|
43
|
+
declare const frontmatterSchema: z.ZodObject<{
|
|
44
|
+
title: z.ZodString;
|
|
45
|
+
description: z.ZodOptional<z.ZodString>;
|
|
46
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
47
|
+
full: z.ZodOptional<z.ZodBoolean>;
|
|
48
|
+
_openapi: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
|
49
|
+
}, "strip", z.ZodTypeAny, {
|
|
50
|
+
title: string;
|
|
51
|
+
icon?: string | undefined;
|
|
52
|
+
description?: string | undefined;
|
|
53
|
+
full?: boolean | undefined;
|
|
54
|
+
_openapi?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
55
|
+
}, {
|
|
56
|
+
title: string;
|
|
57
|
+
icon?: string | undefined;
|
|
58
|
+
description?: string | undefined;
|
|
59
|
+
full?: boolean | undefined;
|
|
60
|
+
_openapi?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
61
|
+
}>;
|
|
62
|
+
|
|
63
|
+
interface TransformContext {
|
|
64
|
+
path: string;
|
|
65
|
+
source: string;
|
|
66
|
+
/**
|
|
67
|
+
* Compile MDX to JavaScript
|
|
68
|
+
*/
|
|
69
|
+
buildMDX: (source: string, options?: ProcessorOptions) => Promise<string>;
|
|
70
|
+
}
|
|
71
|
+
interface Collections<Schema extends ZodTypeAny = ZodTypeAny, Type extends SupportedType = SupportedType, Output extends BaseCollectionEntry = CollectionEntry<Type, z.output<Schema>>> {
|
|
72
|
+
/**
|
|
73
|
+
* Directories to scan
|
|
74
|
+
*/
|
|
75
|
+
dir: string | string[];
|
|
76
|
+
/**
|
|
77
|
+
* what files to include/exclude (glob patterns)
|
|
78
|
+
*
|
|
79
|
+
* Include all files if not specified
|
|
80
|
+
*/
|
|
81
|
+
files?: string[];
|
|
82
|
+
schema?: Schema | ((ctx: TransformContext) => Schema);
|
|
83
|
+
/**
|
|
84
|
+
* content type
|
|
85
|
+
*/
|
|
86
|
+
type: Type;
|
|
87
|
+
/**
|
|
88
|
+
* Do transformation in runtime.
|
|
89
|
+
*
|
|
90
|
+
* This cannot be optimized by bundlers/loaders, avoid expensive calculations here.
|
|
91
|
+
*/
|
|
92
|
+
transform?: (entry: CollectionEntry<Type, z.output<Schema>>, globalConfig?: GlobalConfig) => Output | Promise<Output>;
|
|
93
|
+
mdxOptions?: Type extends 'doc' ? MDXOptions : never;
|
|
94
|
+
}
|
|
95
|
+
declare function defineCollections<Schema extends ZodTypeAny, Type extends SupportedType, Output extends BaseCollectionEntry = CollectionEntry<Type, z.output<Schema>>>(options: Collections<Schema, Type, Output>): {
|
|
96
|
+
_doc: 'collections';
|
|
97
|
+
} & Collections<Schema, Type, Output>;
|
|
98
|
+
declare function defineDocs<F extends ZodTypeAny = typeof frontmatterSchema, M extends ZodTypeAny = typeof metaSchema, DocsOut extends BaseCollectionEntry = CollectionEntry<'doc', z.output<F>>, MetaOut extends BaseCollectionEntry = CollectionEntry<'meta', z.output<M>>>(options?: {
|
|
99
|
+
docs?: Partial<Collections<F, 'doc', DocsOut>>;
|
|
100
|
+
meta?: Partial<Collections<M, 'meta', MetaOut>>;
|
|
101
|
+
}): {
|
|
102
|
+
docs: Collections<F, 'doc', DocsOut>;
|
|
103
|
+
meta: Collections<M, 'meta', MetaOut>;
|
|
104
|
+
};
|
|
105
|
+
declare function defineConfig(config?: GlobalConfig): GlobalConfig;
|
|
106
|
+
|
|
107
|
+
type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
|
|
108
|
+
type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | 'remarkPlugins' | '_ctx'> & {
|
|
109
|
+
rehypePlugins?: ResolvePlugins;
|
|
110
|
+
remarkPlugins?: ResolvePlugins;
|
|
111
|
+
/**
|
|
112
|
+
* Properties to export from `vfile.data`
|
|
113
|
+
*/
|
|
114
|
+
valueToExport?: string[];
|
|
115
|
+
remarkStructureOptions?: StructureOptions | false;
|
|
116
|
+
remarkHeadingOptions?: RemarkHeadingOptions;
|
|
117
|
+
remarkImageOptions?: RemarkImageOptions | false;
|
|
118
|
+
rehypeCodeOptions?: RehypeCodeOptions | false;
|
|
119
|
+
};
|
|
120
|
+
declare function getDefaultMDXOptions({ valueToExport, rehypeCodeOptions, remarkImageOptions, remarkHeadingOptions, remarkStructureOptions, ...mdxOptions }: DefaultMDXOptions): ProcessorOptions;
|
|
121
|
+
|
|
122
|
+
interface GlobalConfig {
|
|
123
|
+
/**
|
|
124
|
+
* Configure global MDX options
|
|
125
|
+
*/
|
|
126
|
+
mdxOptions?: DefaultMDXOptions;
|
|
127
|
+
/**
|
|
128
|
+
* Fetch last modified time with specified version control
|
|
129
|
+
* @defaultValue 'none'
|
|
130
|
+
*/
|
|
131
|
+
lastModifiedTime?: 'git' | 'none';
|
|
132
|
+
/**
|
|
133
|
+
* Generate manifest file on build mode
|
|
134
|
+
*
|
|
135
|
+
* @defaultValue false
|
|
136
|
+
*/
|
|
137
|
+
generateManifest?: boolean;
|
|
138
|
+
}
|
|
139
|
+
type InferSchema<C> = C extends Collections<infer Schema, any, any> ? Schema : never;
|
|
140
|
+
type InferSchemaType<C> = z.output<InferSchema<C>>;
|
|
141
|
+
type InferCollectionsProps<C> = SupportedTypes[C extends Collections<any, infer Type, any> ? Type : never];
|
|
142
|
+
interface FileInfo {
|
|
143
|
+
path: string;
|
|
144
|
+
absolutePath: string;
|
|
145
|
+
}
|
|
146
|
+
interface MarkdownProps {
|
|
147
|
+
body: (props: MDXProps) => React.ReactElement;
|
|
148
|
+
structuredData: StructuredData;
|
|
149
|
+
toc: TableOfContents;
|
|
150
|
+
_exports: Record<string, unknown>;
|
|
151
|
+
/**
|
|
152
|
+
* Only available when `lastModifiedTime` is enabled on MDX loader
|
|
153
|
+
*/
|
|
154
|
+
lastModified?: Date;
|
|
155
|
+
}
|
|
156
|
+
interface SupportedTypes {
|
|
157
|
+
meta: {};
|
|
158
|
+
doc: MarkdownProps;
|
|
159
|
+
}
|
|
160
|
+
type SupportedType = keyof SupportedTypes;
|
|
161
|
+
type CollectionEntry<Type extends SupportedType, Output> = Omit<SupportedTypes[Type], keyof Output> & Output & BaseCollectionEntry;
|
|
162
|
+
interface BaseCollectionEntry {
|
|
163
|
+
_file: FileInfo;
|
|
164
|
+
}
|
|
165
|
+
type EntryFromCollection<C> = C extends Collections<any, any, infer Output> ? Output : never;
|
|
166
|
+
/**
|
|
167
|
+
* Get output type of collections
|
|
168
|
+
*/
|
|
169
|
+
type GetOutput<C> = EntryFromCollection<C>[];
|
|
170
|
+
|
|
171
|
+
export { type BaseCollectionEntry, type CollectionEntry, type Collections, type DefaultMDXOptions, type EntryFromCollection, type FileInfo, type GetOutput, type GlobalConfig, type InferCollectionsProps, type InferSchema, type InferSchemaType, type SupportedType, type SupportedTypes, type TransformContext, defineCollections, defineConfig, defineDocs, frontmatterSchema, getDefaultMDXOptions, metaSchema };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineCollections,
|
|
3
|
+
defineConfig,
|
|
4
|
+
defineDocs,
|
|
5
|
+
frontmatterSchema,
|
|
6
|
+
getDefaultMDXOptions,
|
|
7
|
+
metaSchema
|
|
8
|
+
} from "../chunk-LRV535YP.mjs";
|
|
9
|
+
export {
|
|
10
|
+
defineCollections,
|
|
11
|
+
defineConfig,
|
|
12
|
+
defineDocs,
|
|
13
|
+
frontmatterSchema,
|
|
14
|
+
getDefaultMDXOptions,
|
|
15
|
+
metaSchema
|
|
16
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,97 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
1
|
+
import { PageData, MetaData, Source } from 'fumadocs-core/source';
|
|
2
|
+
import { SupportedType, FileInfo, EntryFromCollection, Collections, CollectionEntry } from './config/index.mjs';
|
|
3
|
+
import { MetaFile } from './loader-mdx.mjs';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import 'mdx/types';
|
|
6
|
+
import 'fumadocs-core/mdx-plugins';
|
|
7
|
+
import 'fumadocs-core/server';
|
|
8
|
+
import '@mdx-js/mdx';
|
|
9
|
+
import 'unified';
|
|
10
|
+
import 'webpack';
|
|
7
11
|
|
|
8
|
-
declare
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
full: z.ZodOptional<z.ZodBoolean>;
|
|
14
|
-
_openapi: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
|
15
|
-
}, "strip", z.ZodTypeAny, {
|
|
16
|
-
title: string;
|
|
17
|
-
description?: string | undefined;
|
|
18
|
-
icon?: string | undefined;
|
|
19
|
-
full?: boolean | undefined;
|
|
20
|
-
_openapi?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
21
|
-
}, {
|
|
22
|
-
title: string;
|
|
23
|
-
description?: string | undefined;
|
|
24
|
-
icon?: string | undefined;
|
|
25
|
-
full?: boolean | undefined;
|
|
26
|
-
_openapi?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
27
|
-
}>;
|
|
28
|
-
meta: z.ZodObject<{
|
|
29
|
-
title: z.ZodOptional<z.ZodString>;
|
|
30
|
-
pages: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
31
|
-
root: z.ZodOptional<z.ZodBoolean>;
|
|
32
|
-
defaultOpen: z.ZodOptional<z.ZodBoolean>;
|
|
33
|
-
icon: z.ZodOptional<z.ZodString>;
|
|
34
|
-
}, "strip", z.ZodTypeAny, {
|
|
35
|
-
title?: string | undefined;
|
|
36
|
-
pages?: string[] | undefined;
|
|
37
|
-
root?: boolean | undefined;
|
|
38
|
-
defaultOpen?: boolean | undefined;
|
|
39
|
-
icon?: string | undefined;
|
|
40
|
-
}, {
|
|
41
|
-
title?: string | undefined;
|
|
42
|
-
pages?: string[] | undefined;
|
|
43
|
-
root?: boolean | undefined;
|
|
44
|
-
defaultOpen?: boolean | undefined;
|
|
45
|
-
icon?: string | undefined;
|
|
46
|
-
}>;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
type SourceFile<Meta extends MetaData, Fronmatter extends PageData> = {
|
|
50
|
-
type: 'meta';
|
|
51
|
-
path: string;
|
|
52
|
-
data: Meta;
|
|
53
|
-
} | {
|
|
54
|
-
type: 'page';
|
|
55
|
-
path: string;
|
|
56
|
-
data: MDXPageData<Fronmatter>;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Defalt MDX properties
|
|
60
|
-
*/
|
|
61
|
-
interface MDXExport<Frontmatter = PageData> {
|
|
62
|
-
default: (props: MDXProps) => React.ReactElement;
|
|
63
|
-
frontmatter: Frontmatter;
|
|
64
|
-
lastModified: number | undefined;
|
|
65
|
-
toc: TableOfContents;
|
|
66
|
-
structuredData: StructuredData;
|
|
67
|
-
}
|
|
68
|
-
type MDXPageData<Frontmatter extends PageData = PageData> = Omit<Frontmatter, 'exports'> & {
|
|
69
|
-
exports: Omit<MDXExport<Frontmatter>, 'frontmatter'>;
|
|
70
|
-
};
|
|
71
|
-
interface InternalFrontmatter {
|
|
72
|
-
_mdx?: {
|
|
73
|
-
/**
|
|
74
|
-
* Mirror another MDX file
|
|
75
|
-
*/
|
|
76
|
-
mirror?: string;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
12
|
+
declare function toRuntime(type: SupportedType, file: Record<string, unknown>, info: FileInfo): EntryFromCollection<Collections>;
|
|
13
|
+
declare function createMDXSource<Doc extends CollectionEntry<'doc', PageData>, Meta extends CollectionEntry<'meta', MetaData>>(docs: Doc[], meta: Meta[]): Source<{
|
|
14
|
+
pageData: Doc;
|
|
15
|
+
metaData: Meta;
|
|
16
|
+
}>;
|
|
79
17
|
|
|
80
|
-
interface
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
interface LoadOptions<Frontmatter, Meta> extends SourceOptions<Frontmatter, Meta> {
|
|
87
|
-
rootDir?: string;
|
|
18
|
+
interface Manifest {
|
|
19
|
+
files: (MetaFile & {
|
|
20
|
+
collection: string;
|
|
21
|
+
})[];
|
|
88
22
|
}
|
|
89
|
-
type DefaultFrontmatter = (typeof defaultSchemas)['frontmatter'];
|
|
90
|
-
type DefaultMeta = (typeof defaultSchemas)['meta'];
|
|
91
|
-
declare function createMDXSource<Frontmatter extends DefaultFrontmatter = DefaultFrontmatter, Meta extends DefaultMeta = DefaultMeta>(map: Record<string, unknown>, options?: SourceOptions<Frontmatter, Meta>): Source<{
|
|
92
|
-
metaData: z.infer<Meta>;
|
|
93
|
-
pageData: MDXPageData<z.infer<Frontmatter>>;
|
|
94
|
-
}>;
|
|
95
|
-
declare function loadMDXSource<Frontmatter extends DefaultFrontmatter = DefaultFrontmatter, Meta extends DefaultMeta = DefaultMeta>(map: Record<string, unknown>, options?: LoadOptions<Frontmatter, Meta>): SourceFile<z.infer<Meta>, z.infer<Frontmatter>>[];
|
|
96
23
|
|
|
97
|
-
export { type
|
|
24
|
+
export { type Manifest, createMDXSource, toRuntime };
|