fumadocs-mdx 11.2.2 → 11.3.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/{build-mdx-SZwWfZMp.d.ts → build-mdx-C2hor32E.d.cts} +2 -1
- package/dist/build-mdx-C2hor32E.d.ts +106 -0
- package/dist/{chunk-2KEQHW7J.js → chunk-2ZPSMAUV.js} +33 -54
- package/dist/config/index.cjs +244 -0
- package/dist/config/index.d.cts +134 -0
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +1 -1
- package/dist/index.cjs +98 -0
- package/dist/index.d.cts +17 -0
- package/dist/index.d.ts +2 -10
- package/dist/loader-mdx.cjs +472 -0
- package/dist/loader-mdx.d.cts +18 -0
- package/dist/loader-mdx.d.ts +1 -10
- package/dist/loader-mdx.js +9 -18
- package/dist/mdx-options-L5C3NQRY.js +6 -0
- package/dist/next/index.cjs +556 -0
- package/dist/next/index.d.cts +21 -0
- package/dist/next/index.js +28 -24
- package/package.json +13 -10
- /package/dist/{chunk-MKWJLEE7.js → chunk-6LEQ23AC.js} +0 -0
|
@@ -24,7 +24,7 @@ interface GlobalConfig {
|
|
|
24
24
|
/**
|
|
25
25
|
* Configure global MDX options
|
|
26
26
|
*/
|
|
27
|
-
mdxOptions?: DefaultMDXOptions;
|
|
27
|
+
mdxOptions?: DefaultMDXOptions | (() => DefaultMDXOptions | Promise<DefaultMDXOptions>);
|
|
28
28
|
/**
|
|
29
29
|
* Fetch last modified time with specified version control
|
|
30
30
|
* @defaultValue 'none'
|
|
@@ -34,6 +34,7 @@ interface GlobalConfig {
|
|
|
34
34
|
* Generate manifest file on build mode
|
|
35
35
|
*
|
|
36
36
|
* @defaultValue false
|
|
37
|
+
* @deprecated No longer needed, use a route handler to export build time info
|
|
37
38
|
*/
|
|
38
39
|
generateManifest?: boolean;
|
|
39
40
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { AnyZodObject, z } 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
|
+
type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
|
|
9
|
+
type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | 'remarkPlugins' | '_ctx'> & {
|
|
10
|
+
rehypePlugins?: ResolvePlugins;
|
|
11
|
+
remarkPlugins?: ResolvePlugins;
|
|
12
|
+
/**
|
|
13
|
+
* Properties to export from `vfile.data`
|
|
14
|
+
*/
|
|
15
|
+
valueToExport?: string[];
|
|
16
|
+
remarkStructureOptions?: StructureOptions | false;
|
|
17
|
+
remarkHeadingOptions?: RemarkHeadingOptions;
|
|
18
|
+
remarkImageOptions?: RemarkImageOptions | false;
|
|
19
|
+
rehypeCodeOptions?: Partial<RehypeCodeOptions> | false;
|
|
20
|
+
};
|
|
21
|
+
declare function getDefaultMDXOptions({ valueToExport, rehypeCodeOptions, remarkImageOptions, remarkHeadingOptions, remarkStructureOptions, ...mdxOptions }: DefaultMDXOptions): ProcessorOptions;
|
|
22
|
+
|
|
23
|
+
interface GlobalConfig {
|
|
24
|
+
/**
|
|
25
|
+
* Configure global MDX options
|
|
26
|
+
*/
|
|
27
|
+
mdxOptions?: DefaultMDXOptions | (() => DefaultMDXOptions | Promise<DefaultMDXOptions>);
|
|
28
|
+
/**
|
|
29
|
+
* Fetch last modified time with specified version control
|
|
30
|
+
* @defaultValue 'none'
|
|
31
|
+
*/
|
|
32
|
+
lastModifiedTime?: 'git' | 'none';
|
|
33
|
+
/**
|
|
34
|
+
* Generate manifest file on build mode
|
|
35
|
+
*
|
|
36
|
+
* @defaultValue false
|
|
37
|
+
* @deprecated No longer needed, use a route handler to export build time info
|
|
38
|
+
*/
|
|
39
|
+
generateManifest?: boolean;
|
|
40
|
+
}
|
|
41
|
+
type InferSchema<CollectionOut> = CollectionOut extends {
|
|
42
|
+
_type: {
|
|
43
|
+
schema: infer T;
|
|
44
|
+
};
|
|
45
|
+
} ? T : never;
|
|
46
|
+
type InferSchemaType<C> = InferSchema<C> extends AnyZodObject ? z.output<InferSchema<C>> : never;
|
|
47
|
+
interface FileInfo {
|
|
48
|
+
path: string;
|
|
49
|
+
absolutePath: string;
|
|
50
|
+
}
|
|
51
|
+
interface MarkdownProps {
|
|
52
|
+
body: (props: MDXProps) => React.ReactElement;
|
|
53
|
+
structuredData: StructuredData;
|
|
54
|
+
toc: TableOfContents;
|
|
55
|
+
_exports: Record<string, unknown>;
|
|
56
|
+
/**
|
|
57
|
+
* Only available when `lastModifiedTime` is enabled on MDX loader
|
|
58
|
+
*/
|
|
59
|
+
lastModified?: Date;
|
|
60
|
+
}
|
|
61
|
+
type CollectionEntry<CollectionOut extends {
|
|
62
|
+
_type: {
|
|
63
|
+
runtime: unknown;
|
|
64
|
+
};
|
|
65
|
+
}> = CollectionOut['_type']['runtime'];
|
|
66
|
+
interface BaseCollectionEntry {
|
|
67
|
+
_file: FileInfo;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get output type of collections
|
|
71
|
+
*/
|
|
72
|
+
type GetOutput<C extends {
|
|
73
|
+
_type: {
|
|
74
|
+
runtime: unknown;
|
|
75
|
+
};
|
|
76
|
+
}> = CollectionEntry<C>[];
|
|
77
|
+
|
|
78
|
+
interface MDXOptions extends ProcessorOptions {
|
|
79
|
+
/**
|
|
80
|
+
* Name of collection
|
|
81
|
+
*/
|
|
82
|
+
collection?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Specify a file path for source
|
|
85
|
+
*/
|
|
86
|
+
filePath?: string;
|
|
87
|
+
frontmatter?: Record<string, unknown>;
|
|
88
|
+
/**
|
|
89
|
+
* Custom Vfile data
|
|
90
|
+
*/
|
|
91
|
+
data?: Record<string, unknown>;
|
|
92
|
+
_compiler?: CompilerOptions;
|
|
93
|
+
}
|
|
94
|
+
interface CompilerOptions {
|
|
95
|
+
addDependency: (file: string) => void;
|
|
96
|
+
}
|
|
97
|
+
declare module 'vfile' {
|
|
98
|
+
interface DataMap {
|
|
99
|
+
/**
|
|
100
|
+
* The compiler object from loader
|
|
101
|
+
*/
|
|
102
|
+
_compiler?: CompilerOptions;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { type BaseCollectionEntry as B, type CollectionEntry as C, type DefaultMDXOptions as D, type FileInfo as F, type GlobalConfig as G, type InferSchema as I, type MarkdownProps as M, type MDXOptions as a, type InferSchemaType as b, type GetOutput as c, getDefaultMDXOptions as g };
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getDefaultMDXOptions
|
|
3
|
-
} from "./chunk-MKWJLEE7.js";
|
|
4
|
-
|
|
5
1
|
// src/config/cached.ts
|
|
6
2
|
import { createHash } from "node:crypto";
|
|
7
3
|
import * as fs from "node:fs";
|
|
@@ -9,20 +5,33 @@ import * as fs from "node:fs";
|
|
|
9
5
|
// src/config/load.ts
|
|
10
6
|
import * as path from "node:path";
|
|
11
7
|
import { pathToFileURL } from "node:url";
|
|
12
|
-
import { createJiti } from "jiti";
|
|
13
8
|
function findConfigFile() {
|
|
14
9
|
return path.resolve("source.config.ts");
|
|
15
10
|
}
|
|
16
|
-
var jiti = createJiti(import.meta.url, {
|
|
17
|
-
moduleCache: false
|
|
18
|
-
});
|
|
19
11
|
async function loadConfig(configPath) {
|
|
20
|
-
const
|
|
21
|
-
|
|
12
|
+
const { build } = await import("esbuild");
|
|
13
|
+
const url = pathToFileURL(path.resolve(".source/source.config.mjs"));
|
|
14
|
+
const transformed = await build({
|
|
15
|
+
entryPoints: [{ in: configPath, out: "source.config" }],
|
|
16
|
+
bundle: true,
|
|
17
|
+
outdir: ".source",
|
|
18
|
+
target: "node18",
|
|
19
|
+
write: true,
|
|
20
|
+
platform: "node",
|
|
21
|
+
format: "esm",
|
|
22
|
+
packages: "external",
|
|
23
|
+
outExtension: {
|
|
24
|
+
".js": ".mjs"
|
|
25
|
+
},
|
|
26
|
+
allowOverwrite: true
|
|
22
27
|
});
|
|
28
|
+
if (transformed.errors.length > 0) {
|
|
29
|
+
throw new Error("failed to compile configuration file");
|
|
30
|
+
}
|
|
31
|
+
const loaded = await import(`${url.href}?hash=${Date.now().toString()}`);
|
|
23
32
|
const [err, config] = buildConfig(
|
|
24
33
|
// every call to `loadConfig` will cause the previous cache to be ignored
|
|
25
|
-
|
|
34
|
+
loaded
|
|
26
35
|
);
|
|
27
36
|
if (err !== null) throw new Error(err);
|
|
28
37
|
return config;
|
|
@@ -50,12 +59,23 @@ function buildConfig(config) {
|
|
|
50
59
|
null
|
|
51
60
|
];
|
|
52
61
|
}
|
|
62
|
+
let cachedMdxOptions;
|
|
53
63
|
return [
|
|
54
64
|
null,
|
|
55
65
|
{
|
|
56
66
|
global: globalConfig,
|
|
57
67
|
collections,
|
|
58
|
-
|
|
68
|
+
async getDefaultMDXOptions() {
|
|
69
|
+
if (cachedMdxOptions) return cachedMdxOptions;
|
|
70
|
+
const { getDefaultMDXOptions } = await import("./mdx-options-L5C3NQRY.js");
|
|
71
|
+
const mdxOptions = globalConfig?.mdxOptions ?? {};
|
|
72
|
+
if (typeof mdxOptions === "function") {
|
|
73
|
+
cachedMdxOptions = getDefaultMDXOptions(await mdxOptions());
|
|
74
|
+
} else {
|
|
75
|
+
cachedMdxOptions = getDefaultMDXOptions(mdxOptions);
|
|
76
|
+
}
|
|
77
|
+
return cachedMdxOptions;
|
|
78
|
+
},
|
|
59
79
|
_runtime: {
|
|
60
80
|
files: /* @__PURE__ */ new Map()
|
|
61
81
|
}
|
|
@@ -83,50 +103,9 @@ async function getConfigHash(configPath) {
|
|
|
83
103
|
return hash.digest("hex");
|
|
84
104
|
}
|
|
85
105
|
|
|
86
|
-
// src/map/manifest.ts
|
|
87
|
-
import * as fs2 from "node:fs";
|
|
88
|
-
import * as path2 from "node:path";
|
|
89
|
-
|
|
90
|
-
// src/utils/get-type-from-path.ts
|
|
91
|
-
import { extname } from "node:path";
|
|
92
|
-
var docTypes = [".mdx", ".md"];
|
|
93
|
-
var metaTypes = [".json", ".yaml"];
|
|
94
|
-
function getTypeFromPath(path3) {
|
|
95
|
-
const ext = extname(path3);
|
|
96
|
-
if (docTypes.includes(ext)) return "doc";
|
|
97
|
-
if (metaTypes.includes(ext)) return "meta";
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// src/map/manifest.ts
|
|
101
|
-
function getManifestEntryPath(originalPath) {
|
|
102
|
-
const toName = path2.relative(process.cwd(), originalPath).replaceAll(`..${path2.sep}`, "-").replaceAll(path2.sep, "_");
|
|
103
|
-
return path2.resolve(".next/cache/fumadocs", `${toName}.json`);
|
|
104
|
-
}
|
|
105
|
-
function writeManifest(to, config) {
|
|
106
|
-
const output = { files: [] };
|
|
107
|
-
for (const [file, collection] of config._runtime.files.entries()) {
|
|
108
|
-
const type = config.collections.get(collection)?.type ?? getTypeFromPath(file);
|
|
109
|
-
if (type === "meta") continue;
|
|
110
|
-
try {
|
|
111
|
-
const content = fs2.readFileSync(getManifestEntryPath(file));
|
|
112
|
-
const meta = JSON.parse(content.toString());
|
|
113
|
-
output.files.push({
|
|
114
|
-
...meta,
|
|
115
|
-
collection
|
|
116
|
-
});
|
|
117
|
-
} catch (e) {
|
|
118
|
-
console.error(`cannot find the search index of ${file}`, e);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
fs2.writeFileSync(to, JSON.stringify(output));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
106
|
export {
|
|
125
107
|
findConfigFile,
|
|
126
108
|
loadConfig,
|
|
127
109
|
loadConfigCached,
|
|
128
|
-
getConfigHash
|
|
129
|
-
getTypeFromPath,
|
|
130
|
-
getManifestEntryPath,
|
|
131
|
-
writeManifest
|
|
110
|
+
getConfigHash
|
|
132
111
|
};
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/config/index.ts
|
|
31
|
+
var config_exports = {};
|
|
32
|
+
__export(config_exports, {
|
|
33
|
+
defineCollections: () => defineCollections,
|
|
34
|
+
defineConfig: () => defineConfig,
|
|
35
|
+
defineDocs: () => defineDocs,
|
|
36
|
+
frontmatterSchema: () => frontmatterSchema,
|
|
37
|
+
getDefaultMDXOptions: () => getDefaultMDXOptions,
|
|
38
|
+
metaSchema: () => metaSchema,
|
|
39
|
+
remarkInclude: () => remarkInclude
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(config_exports);
|
|
42
|
+
|
|
43
|
+
// src/utils/schema.ts
|
|
44
|
+
var import_zod = require("zod");
|
|
45
|
+
var metaSchema = import_zod.z.object({
|
|
46
|
+
title: import_zod.z.string().optional(),
|
|
47
|
+
pages: import_zod.z.array(import_zod.z.string()).optional(),
|
|
48
|
+
description: import_zod.z.string().optional(),
|
|
49
|
+
root: import_zod.z.boolean().optional(),
|
|
50
|
+
defaultOpen: import_zod.z.boolean().optional(),
|
|
51
|
+
icon: import_zod.z.string().optional()
|
|
52
|
+
});
|
|
53
|
+
var frontmatterSchema = import_zod.z.object({
|
|
54
|
+
title: import_zod.z.string(),
|
|
55
|
+
description: import_zod.z.string().optional(),
|
|
56
|
+
icon: import_zod.z.string().optional(),
|
|
57
|
+
full: import_zod.z.boolean().optional(),
|
|
58
|
+
// Fumadocs OpenAPI generated
|
|
59
|
+
_openapi: import_zod.z.object({}).passthrough().optional()
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// src/config/define.ts
|
|
63
|
+
function defineCollections(options) {
|
|
64
|
+
return {
|
|
65
|
+
_doc: "collections",
|
|
66
|
+
// @ts-expect-error -- internal type inferring
|
|
67
|
+
_type: void 0,
|
|
68
|
+
...options
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function defineDocs(options) {
|
|
72
|
+
const dir = options?.dir ?? "content/docs";
|
|
73
|
+
return {
|
|
74
|
+
docs: defineCollections({
|
|
75
|
+
type: "doc",
|
|
76
|
+
dir,
|
|
77
|
+
schema: frontmatterSchema,
|
|
78
|
+
...options?.docs
|
|
79
|
+
}),
|
|
80
|
+
meta: defineCollections({
|
|
81
|
+
type: "meta",
|
|
82
|
+
dir,
|
|
83
|
+
schema: metaSchema,
|
|
84
|
+
...options?.meta
|
|
85
|
+
})
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function defineConfig(config = {}) {
|
|
89
|
+
return config;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/utils/mdx-options.ts
|
|
93
|
+
var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
94
|
+
|
|
95
|
+
// src/mdx-plugins/remark-exports.ts
|
|
96
|
+
var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
97
|
+
function remarkMdxExport({ values }) {
|
|
98
|
+
return (tree, vfile) => {
|
|
99
|
+
for (const name of values) {
|
|
100
|
+
if (!(name in vfile.data)) return;
|
|
101
|
+
tree.children.unshift(getMdastExport(name, vfile.data[name]));
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function getMdastExport(name, value) {
|
|
106
|
+
return {
|
|
107
|
+
type: "mdxjsEsm",
|
|
108
|
+
value: "",
|
|
109
|
+
data: {
|
|
110
|
+
estree: {
|
|
111
|
+
type: "Program",
|
|
112
|
+
sourceType: "module",
|
|
113
|
+
body: [
|
|
114
|
+
{
|
|
115
|
+
type: "ExportNamedDeclaration",
|
|
116
|
+
specifiers: [],
|
|
117
|
+
source: null,
|
|
118
|
+
declaration: {
|
|
119
|
+
type: "VariableDeclaration",
|
|
120
|
+
kind: "let",
|
|
121
|
+
declarations: [
|
|
122
|
+
{
|
|
123
|
+
type: "VariableDeclarator",
|
|
124
|
+
id: {
|
|
125
|
+
type: "Identifier",
|
|
126
|
+
name
|
|
127
|
+
},
|
|
128
|
+
init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/utils/mdx-options.ts
|
|
140
|
+
function pluginOption(def, options = []) {
|
|
141
|
+
const list = def(Array.isArray(options) ? options : []).filter(
|
|
142
|
+
Boolean
|
|
143
|
+
);
|
|
144
|
+
if (typeof options === "function") {
|
|
145
|
+
return options(list);
|
|
146
|
+
}
|
|
147
|
+
return list;
|
|
148
|
+
}
|
|
149
|
+
function getDefaultMDXOptions({
|
|
150
|
+
valueToExport = [],
|
|
151
|
+
rehypeCodeOptions,
|
|
152
|
+
remarkImageOptions,
|
|
153
|
+
remarkHeadingOptions,
|
|
154
|
+
remarkStructureOptions,
|
|
155
|
+
...mdxOptions
|
|
156
|
+
}) {
|
|
157
|
+
const mdxExports = [
|
|
158
|
+
"structuredData",
|
|
159
|
+
"frontmatter",
|
|
160
|
+
"lastModified",
|
|
161
|
+
...valueToExport
|
|
162
|
+
];
|
|
163
|
+
const remarkPlugins = pluginOption(
|
|
164
|
+
(v) => [
|
|
165
|
+
import_mdx_plugins.remarkGfm,
|
|
166
|
+
[
|
|
167
|
+
import_mdx_plugins.remarkHeading,
|
|
168
|
+
{
|
|
169
|
+
generateToc: false,
|
|
170
|
+
...remarkHeadingOptions
|
|
171
|
+
}
|
|
172
|
+
],
|
|
173
|
+
remarkImageOptions !== false && [import_mdx_plugins.remarkImage, remarkImageOptions],
|
|
174
|
+
...v,
|
|
175
|
+
remarkStructureOptions !== false && [
|
|
176
|
+
import_mdx_plugins.remarkStructure,
|
|
177
|
+
remarkStructureOptions
|
|
178
|
+
],
|
|
179
|
+
[remarkMdxExport, { values: mdxExports }]
|
|
180
|
+
],
|
|
181
|
+
mdxOptions.remarkPlugins
|
|
182
|
+
);
|
|
183
|
+
const rehypePlugins = pluginOption(
|
|
184
|
+
(v) => [
|
|
185
|
+
rehypeCodeOptions !== false && [import_mdx_plugins.rehypeCode, rehypeCodeOptions],
|
|
186
|
+
...v,
|
|
187
|
+
[import_mdx_plugins.rehypeToc]
|
|
188
|
+
],
|
|
189
|
+
mdxOptions.rehypePlugins
|
|
190
|
+
);
|
|
191
|
+
return {
|
|
192
|
+
...mdxOptions,
|
|
193
|
+
remarkPlugins,
|
|
194
|
+
rehypePlugins
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/mdx-plugins/remark-include.ts
|
|
199
|
+
var import_unist_util_visit = require("unist-util-visit");
|
|
200
|
+
var path = __toESM(require("path"), 1);
|
|
201
|
+
var fs = __toESM(require("fs/promises"), 1);
|
|
202
|
+
var import_gray_matter = __toESM(require("gray-matter"), 1);
|
|
203
|
+
function remarkInclude() {
|
|
204
|
+
return async (tree, file) => {
|
|
205
|
+
const queue = [];
|
|
206
|
+
(0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "paragraph"], (node) => {
|
|
207
|
+
let specifier;
|
|
208
|
+
if (node.type === "paragraph" && node.children.length === 3) {
|
|
209
|
+
const [open, content, closure] = node.children;
|
|
210
|
+
if (open.type === "html" && open.value === "<include>" && content.type === "text" && closure.type === "html" && closure.value === "</include>") {
|
|
211
|
+
specifier = content.value.trim();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (node.type === "mdxJsxFlowElement" && node.name === "include") {
|
|
215
|
+
const child = node.children.at(0);
|
|
216
|
+
if (!child || child.type !== "text") return;
|
|
217
|
+
specifier = child.value;
|
|
218
|
+
}
|
|
219
|
+
if (!specifier) return "skip";
|
|
220
|
+
const targetPath = path.resolve(path.dirname(file.path), specifier);
|
|
221
|
+
queue.push(
|
|
222
|
+
fs.readFile(targetPath).then((content) => {
|
|
223
|
+
const parsed = this.parse((0, import_gray_matter.default)(content).content);
|
|
224
|
+
if (file.data._compiler) {
|
|
225
|
+
file.data._compiler.addDependency(targetPath);
|
|
226
|
+
}
|
|
227
|
+
Object.assign(node, parsed);
|
|
228
|
+
})
|
|
229
|
+
);
|
|
230
|
+
return "skip";
|
|
231
|
+
});
|
|
232
|
+
await Promise.all(queue);
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
236
|
+
0 && (module.exports = {
|
|
237
|
+
defineCollections,
|
|
238
|
+
defineConfig,
|
|
239
|
+
defineDocs,
|
|
240
|
+
frontmatterSchema,
|
|
241
|
+
getDefaultMDXOptions,
|
|
242
|
+
metaSchema,
|
|
243
|
+
remarkInclude
|
|
244
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { F as FileInfo, G as GlobalConfig, M as MarkdownProps, a as MDXOptions, B as BaseCollectionEntry } from '../build-mdx-C2hor32E.cjs';
|
|
2
|
+
export { C as CollectionEntry, D as DefaultMDXOptions, c as GetOutput, I as InferSchema, b as InferSchemaType, g as getDefaultMDXOptions } from '../build-mdx-C2hor32E.cjs';
|
|
3
|
+
import { z, ZodTypeAny } from 'zod';
|
|
4
|
+
import { ProcessorOptions } from '@mdx-js/mdx';
|
|
5
|
+
import { Processor, Transformer } from 'unified';
|
|
6
|
+
import { Root } from 'mdast';
|
|
7
|
+
import 'mdx/types';
|
|
8
|
+
import 'fumadocs-core/mdx-plugins';
|
|
9
|
+
import 'fumadocs-core/server';
|
|
10
|
+
|
|
11
|
+
declare const metaSchema: z.ZodObject<{
|
|
12
|
+
title: z.ZodOptional<z.ZodString>;
|
|
13
|
+
pages: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
14
|
+
description: z.ZodOptional<z.ZodString>;
|
|
15
|
+
root: z.ZodOptional<z.ZodBoolean>;
|
|
16
|
+
defaultOpen: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
root?: boolean | undefined;
|
|
20
|
+
title?: string | undefined;
|
|
21
|
+
icon?: string | undefined;
|
|
22
|
+
pages?: string[] | undefined;
|
|
23
|
+
description?: string | undefined;
|
|
24
|
+
defaultOpen?: boolean | undefined;
|
|
25
|
+
}, {
|
|
26
|
+
root?: boolean | undefined;
|
|
27
|
+
title?: string | undefined;
|
|
28
|
+
icon?: string | undefined;
|
|
29
|
+
pages?: string[] | undefined;
|
|
30
|
+
description?: string | undefined;
|
|
31
|
+
defaultOpen?: boolean | undefined;
|
|
32
|
+
}>;
|
|
33
|
+
declare const frontmatterSchema: z.ZodObject<{
|
|
34
|
+
title: z.ZodString;
|
|
35
|
+
description: z.ZodOptional<z.ZodString>;
|
|
36
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
37
|
+
full: z.ZodOptional<z.ZodBoolean>;
|
|
38
|
+
_openapi: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
title: string;
|
|
41
|
+
icon?: string | undefined;
|
|
42
|
+
description?: string | undefined;
|
|
43
|
+
full?: boolean | undefined;
|
|
44
|
+
_openapi?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
45
|
+
}, {
|
|
46
|
+
title: string;
|
|
47
|
+
icon?: string | undefined;
|
|
48
|
+
description?: string | undefined;
|
|
49
|
+
full?: boolean | undefined;
|
|
50
|
+
_openapi?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
51
|
+
}>;
|
|
52
|
+
|
|
53
|
+
interface TransformContext {
|
|
54
|
+
path: string;
|
|
55
|
+
source: string;
|
|
56
|
+
/**
|
|
57
|
+
* Compile MDX to JavaScript
|
|
58
|
+
*/
|
|
59
|
+
buildMDX: (source: string, options?: ProcessorOptions) => Promise<string>;
|
|
60
|
+
}
|
|
61
|
+
interface BaseCollection<Schema> {
|
|
62
|
+
/**
|
|
63
|
+
* Directories to scan
|
|
64
|
+
*/
|
|
65
|
+
dir: string | string[];
|
|
66
|
+
/**
|
|
67
|
+
* what files to include/exclude (glob patterns)
|
|
68
|
+
*
|
|
69
|
+
* Include all files if not specified
|
|
70
|
+
*/
|
|
71
|
+
files?: string[];
|
|
72
|
+
schema?: Schema | ((ctx: TransformContext) => Schema);
|
|
73
|
+
}
|
|
74
|
+
interface MetaCollection<Schema extends ZodTypeAny = ZodTypeAny, TransformOutput = unknown> extends BaseCollection<Schema> {
|
|
75
|
+
type: 'meta';
|
|
76
|
+
/**
|
|
77
|
+
* Do transformation in runtime.
|
|
78
|
+
*
|
|
79
|
+
* This cannot be optimized by bundlers/loaders, avoid expensive calculations here.
|
|
80
|
+
*/
|
|
81
|
+
transform?: (entry: {
|
|
82
|
+
data: z.output<Schema>;
|
|
83
|
+
file: FileInfo;
|
|
84
|
+
}, globalConfig?: GlobalConfig) => TransformOutput | Promise<TransformOutput>;
|
|
85
|
+
}
|
|
86
|
+
interface DocCollection<Schema extends ZodTypeAny = ZodTypeAny, Async extends boolean = boolean, TransformOutput = unknown> extends BaseCollection<Schema> {
|
|
87
|
+
type: 'doc';
|
|
88
|
+
/**
|
|
89
|
+
* Do transformation in runtime.
|
|
90
|
+
*
|
|
91
|
+
* This cannot be optimized by bundlers/loaders, avoid expensive calculations here.
|
|
92
|
+
*/
|
|
93
|
+
transform?: (entry: {
|
|
94
|
+
data: z.output<Schema>;
|
|
95
|
+
file: FileInfo;
|
|
96
|
+
mdx: Async extends true ? MarkdownProps : never;
|
|
97
|
+
}, globalConfig?: GlobalConfig) => TransformOutput | Promise<TransformOutput>;
|
|
98
|
+
mdxOptions?: MDXOptions;
|
|
99
|
+
/**
|
|
100
|
+
* Load files with async
|
|
101
|
+
*/
|
|
102
|
+
async?: Async;
|
|
103
|
+
}
|
|
104
|
+
declare function defineCollections<T extends 'doc' | 'meta', Schema extends ZodTypeAny = ZodTypeAny, Async extends boolean = false, TransformOutput = unknown>(options: {
|
|
105
|
+
type: T;
|
|
106
|
+
} & (T extends 'doc' ? DocCollection<Schema, Async, TransformOutput> : MetaCollection<Schema, TransformOutput>)): {
|
|
107
|
+
_doc: 'collections';
|
|
108
|
+
type: T;
|
|
109
|
+
_type: {
|
|
110
|
+
async: Async;
|
|
111
|
+
transform: TransformOutput;
|
|
112
|
+
runtime: T extends 'doc' ? Async extends true ? z.infer<Schema> & BaseCollectionEntry & {
|
|
113
|
+
load: () => Promise<MarkdownProps>;
|
|
114
|
+
} : Omit<MarkdownProps, keyof z.infer<Schema>> & z.infer<Schema> & BaseCollectionEntry : typeof options extends MetaCollection ? z.infer<Schema> & BaseCollectionEntry : never;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
declare function defineDocs<DocData extends ZodTypeAny = typeof frontmatterSchema, MetaData extends ZodTypeAny = typeof metaSchema, DocAsync extends boolean = false, DocOut = unknown, MetaOut = unknown>(options?: {
|
|
118
|
+
/**
|
|
119
|
+
* The directory to scan files
|
|
120
|
+
*
|
|
121
|
+
* @defaultValue 'content/docs'
|
|
122
|
+
*/
|
|
123
|
+
dir?: string | string[];
|
|
124
|
+
docs?: Partial<DocCollection<DocData, DocAsync, DocOut>>;
|
|
125
|
+
meta?: Partial<MetaCollection<MetaData, MetaOut>>;
|
|
126
|
+
}): {
|
|
127
|
+
docs: ReturnType<typeof defineCollections<'doc', DocData, DocAsync, DocOut>>;
|
|
128
|
+
meta: ReturnType<typeof defineCollections<'meta', MetaData, false, MetaOut>>;
|
|
129
|
+
};
|
|
130
|
+
declare function defineConfig(config?: GlobalConfig): GlobalConfig;
|
|
131
|
+
|
|
132
|
+
declare function remarkInclude(this: Processor): Transformer<Root, Root>;
|
|
133
|
+
|
|
134
|
+
export { type BaseCollection, BaseCollectionEntry, type DocCollection, FileInfo, GlobalConfig, MarkdownProps, type MetaCollection, type TransformContext, defineCollections, defineConfig, defineDocs, frontmatterSchema, metaSchema, remarkInclude };
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as FileInfo, G as GlobalConfig, M as MarkdownProps, a as MDXOptions, B as BaseCollectionEntry } from '../build-mdx-
|
|
2
|
-
export { C as CollectionEntry, D as DefaultMDXOptions, c as GetOutput, I as InferSchema, b as InferSchemaType, g as getDefaultMDXOptions } from '../build-mdx-
|
|
1
|
+
import { F as FileInfo, G as GlobalConfig, M as MarkdownProps, a as MDXOptions, B as BaseCollectionEntry } from '../build-mdx-C2hor32E.js';
|
|
2
|
+
export { C as CollectionEntry, D as DefaultMDXOptions, c as GetOutput, I as InferSchema, b as InferSchemaType, g as getDefaultMDXOptions } from '../build-mdx-C2hor32E.js';
|
|
3
3
|
import { z, ZodTypeAny } from 'zod';
|
|
4
4
|
import { ProcessorOptions } from '@mdx-js/mdx';
|
|
5
5
|
import { Processor, Transformer } from 'unified';
|