fumadocs-mdx 15.1.1 → 15.2.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/{adapter-DPEpBHhE.js → adapter-DvWJNDHu.js} +10 -7
- package/dist/{build-BnKCFeb6.js → build-CMzB9h0Y.js} +2 -2
- package/dist/{build-default-DCQTM_P7.js → build-default-C77dbnhG.js} +9 -0
- package/dist/{build-satteri-Mk7OLtzu.js → build-satteri-oMFzrKGl.js} +4 -2
- package/dist/bun/index.d.ts +12 -3
- package/dist/bun/index.js +84 -13
- package/dist/config/index.d.ts +3 -2
- package/dist/config/index.js +2 -34
- package/dist/{core-Cq6V99iz.js → core-BPlsDtvN.js} +63 -37
- package/dist/{core-Br7DNGl3.d.ts → core-BmvJhZxm.d.ts} +112 -90
- package/dist/define-BW5lveuc.js +29 -0
- package/dist/eval-z3HV4VJp.js +173 -0
- package/dist/index-BN7EkING.d.ts +28 -0
- package/dist/{index-file-C9Bw7He1.js → index-file-pX-fCn8l.js} +19 -24
- package/dist/index-vs1fd5_x.d.ts +18 -0
- package/dist/index.d.ts +1 -1
- package/dist/last-modified-SdvMEHGm.js +45 -0
- package/dist/load-from-file-DNDIyOo3.js +48 -0
- package/dist/{loaders-CUuRGbiE.js → loaders-DWC_Uwqq.js} +2 -2
- package/dist/macro/index.d.ts +124 -0
- package/dist/macro/index.js +22 -0
- package/dist/{mdx-wSuDwc6c.js → mdx-Bcb4tkWn.js} +22 -12
- package/dist/{meta-BDiR5cQC.js → meta-DWvKGgBH.js} +23 -12
- package/dist/next/index.d.ts +7 -10
- package/dist/next/index.js +50 -34
- package/dist/node/_loader.js +57 -13
- package/dist/node/index.d.ts +9 -2
- package/dist/node/loader.js +6 -10
- package/dist/options-BNnYUjkM.js +37 -0
- package/dist/options-aB6xV-d7.d.ts +20 -0
- package/dist/plugins/index-file.d.ts +1 -1
- package/dist/plugins/index-file.js +1 -1
- package/dist/plugins/json-schema.d.ts +1 -1
- package/dist/plugins/json-schema.js +1 -1
- package/dist/plugins/last-modified.d.ts +6 -4
- package/dist/plugins/last-modified.js +10 -80
- package/dist/rolldown/index.d.ts +14 -4
- package/dist/rolldown/index.js +78 -34
- package/dist/runtime/browser.d.ts +1 -1
- package/dist/runtime/dynamic.d.ts +4 -2
- package/dist/runtime/dynamic.js +4 -4
- package/dist/runtime/macro.d.ts +89 -0
- package/dist/runtime/macro.js +71 -0
- package/dist/runtime/server.d.ts +48 -2
- package/dist/runtime/server.js +2 -3
- package/dist/transform-BFobDsdE.js +386 -0
- package/dist/vite/index.d.ts +10 -12
- package/dist/vite/index.js +90 -31
- package/dist/webpack/macro.d.ts +13 -0
- package/dist/webpack/macro.js +37 -0
- package/dist/webpack/mdx.d.ts +1 -1
- package/dist/webpack/mdx.js +4 -4
- package/dist/webpack/meta.d.ts +1 -1
- package/dist/webpack/meta.js +18 -13
- package/dist/webpack-BSog6pml.js +28 -0
- package/package.json +8 -3
- package/dist/index-Bb7u_Fzy.d.ts +0 -10
- package/dist/load-from-file-CVTAyohB.js +0 -37
- package/dist/webpack-BZVbRnxp.js +0 -12
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as loadConfig } from "./load-from-file-
|
|
1
|
+
import { i as buildConfig, n as ValidationError } from "./core-BPlsDtvN.js";
|
|
2
|
+
import { t as loadConfig } from "./load-from-file-DNDIyOo3.js";
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
4
|
import fs from "node:fs/promises";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { parse } from "node:querystring";
|
|
7
7
|
//#region src/loaders/config.ts
|
|
8
|
-
function createStandaloneConfigLoader({ core, buildConfig, mode }) {
|
|
8
|
+
function createStandaloneConfigLoader({ core, buildConfig: buildConfig$1, mode }) {
|
|
9
9
|
let prev;
|
|
10
10
|
async function getConfigHash() {
|
|
11
11
|
if (mode === "production") return "static";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const stats = await fs.stat(core.configPath).catch(() => void 0);
|
|
13
|
+
return stats ? stats.mtime.getTime() : "missing";
|
|
14
|
+
}
|
|
15
|
+
async function load(hash) {
|
|
16
|
+
if (hash === "missing") return buildConfig({}, process.cwd());
|
|
17
|
+
return await loadConfig(core, buildConfig$1);
|
|
15
18
|
}
|
|
16
19
|
return { async getCore() {
|
|
17
20
|
const hash = await getConfigHash();
|
|
18
21
|
if (!prev || hash !== prev.hash) prev = {
|
|
19
22
|
hash,
|
|
20
|
-
init: core.init({ config:
|
|
23
|
+
init: core.init({ config: load(hash) })
|
|
21
24
|
};
|
|
22
25
|
await prev.init;
|
|
23
26
|
return core;
|
|
@@ -3,10 +3,10 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
|
3
3
|
var build_exports = /* @__PURE__ */ __exportAll({ buildMDX: () => buildMDX });
|
|
4
4
|
async function buildMDX(core, collection, options) {
|
|
5
5
|
if ((collection ? collection.compiler : core.getConfig().global.compiler) === "satteri") {
|
|
6
|
-
const { buildSatteriMDX } = await import("./build-satteri-
|
|
6
|
+
const { buildSatteriMDX } = await import("./build-satteri-oMFzrKGl.js");
|
|
7
7
|
return buildSatteriMDX(core, collection, options);
|
|
8
8
|
}
|
|
9
|
-
const { buildJSMDX } = await import("./build-default-
|
|
9
|
+
const { buildJSMDX } = await import("./build-default-C77dbnhG.js");
|
|
10
10
|
return buildJSMDX(core, collection, options);
|
|
11
11
|
}
|
|
12
12
|
//#endregion
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { n as flattenNode, r as applyMdxPreset, t as remarkInclude } from "./remark-include-B6rmf4sh.js";
|
|
2
|
+
import { t as resolveLastModified } from "./last-modified-SdvMEHGm.js";
|
|
2
3
|
import { visit } from "unist-util-visit";
|
|
3
4
|
import { VFile } from "vfile";
|
|
4
5
|
import { createProcessor } from "@mdx-js/mdx";
|
|
@@ -127,6 +128,14 @@ async function buildJSMDX(core, collection, { filePath, frontmatter, source, _co
|
|
|
127
128
|
filePath,
|
|
128
129
|
source
|
|
129
130
|
}, vfile);
|
|
131
|
+
const lastModified = await resolveLastModified(collection, filePath);
|
|
132
|
+
if (lastModified) {
|
|
133
|
+
vfile.data["mdx-export"] ??= [];
|
|
134
|
+
vfile.data["mdx-export"].push({
|
|
135
|
+
name: "lastModified",
|
|
136
|
+
value: lastModified
|
|
137
|
+
});
|
|
138
|
+
}
|
|
130
139
|
const out = await getProcessor(filePath.endsWith(".mdx") ? "mdx" : "md").process(vfile);
|
|
131
140
|
return {
|
|
132
141
|
code: String(out.value),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as resolveLastModified } from "./last-modified-SdvMEHGm.js";
|
|
1
2
|
import { pathToFileURL } from "node:url";
|
|
2
3
|
//#region src/loaders/mdx/build-satteri.ts
|
|
3
4
|
async function buildSatteriMDX(core, collection, { filePath, frontmatter, source, _compiler, environment, isDevelopment }) {
|
|
@@ -29,7 +30,7 @@ async function buildSatteriMDX(core, collection, { filePath, frontmatter, source
|
|
|
29
30
|
const mdastPlugins = [remarkInclude({ cwd: collection?.cwd })];
|
|
30
31
|
if (satteriOptions.mdastPlugins) mdastPlugins.push(...satteriOptions.mdastPlugins);
|
|
31
32
|
if (postprocess.includeProcessedMarkdown) mdastPlugins.push(remarkLlms(typeof postprocess.includeProcessedMarkdown === "object" ? postprocess.includeProcessedMarkdown : void 0));
|
|
32
|
-
mdastPlugins.push(postprocessPlugin(postprocess));
|
|
33
|
+
mdastPlugins.push(postprocessPlugin(postprocess, await resolveLastModified(collection, filePath)));
|
|
33
34
|
return { code: (await compileMdx({
|
|
34
35
|
source,
|
|
35
36
|
filePath,
|
|
@@ -44,7 +45,7 @@ async function buildSatteriMDX(core, collection, { filePath, frontmatter, source
|
|
|
44
45
|
}
|
|
45
46
|
})).code };
|
|
46
47
|
}
|
|
47
|
-
function postprocessPlugin({ extractLinkReferences = false }) {
|
|
48
|
+
function postprocessPlugin({ extractLinkReferences = false }, lastModified) {
|
|
48
49
|
return {
|
|
49
50
|
name: "remark-postprocess",
|
|
50
51
|
heading(node, ctx) {
|
|
@@ -59,6 +60,7 @@ function postprocessPlugin({ extractLinkReferences = false }) {
|
|
|
59
60
|
result.data.extractedReferences ??= [];
|
|
60
61
|
result.code += `\nexport const extractedReferences = ${JSON.stringify(result.data.extractedReferences)};`;
|
|
61
62
|
}
|
|
63
|
+
if (lastModified) result.code += `\nexport const lastModified = new Date(${lastModified.getTime()});`;
|
|
62
64
|
}
|
|
63
65
|
};
|
|
64
66
|
}
|
package/dist/bun/index.d.ts
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import { r as CoreOptions } from "../core-
|
|
1
|
+
import { r as CoreOptions } from "../core-BmvJhZxm.js";
|
|
2
|
+
import { n as ResolvedMacroOptions, t as MacroPluginOption } from "../options-aB6xV-d7.js";
|
|
2
3
|
import { BunPlugin } from "bun";
|
|
3
4
|
//#region src/bun/index.d.ts
|
|
4
|
-
interface MdxPluginOptions extends
|
|
5
|
+
interface MdxPluginOptions extends Pick<CoreOptions, 'configPath' | 'outDir' | 'plugins'> {
|
|
6
|
+
/**
|
|
7
|
+
* Configure the macro API (`fumadocs-mdx/macro`), or `false` to disable it.
|
|
8
|
+
*/
|
|
9
|
+
macro?: MacroPluginOption;
|
|
5
10
|
/**
|
|
6
11
|
* Skip meta file transformation step
|
|
7
12
|
*/
|
|
8
13
|
disableMetaFile?: boolean;
|
|
9
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
declare function macroFilter(root: string, { include, exclude }: ResolvedMacroOptions): RegExp;
|
|
10
19
|
declare function createMdxPlugin(options?: MdxPluginOptions): BunPlugin;
|
|
11
20
|
//#endregion
|
|
12
|
-
export { MdxPluginOptions, createMdxPlugin };
|
|
21
|
+
export { MdxPluginOptions, createMdxPlugin, macroFilter };
|
package/dist/bun/index.js
CHANGED
|
@@ -1,27 +1,98 @@
|
|
|
1
|
-
import { t as createMdxLoader } from "../mdx-
|
|
2
|
-
import { i as buildConfig,
|
|
3
|
-
import {
|
|
4
|
-
import { t as
|
|
5
|
-
import {
|
|
1
|
+
import { t as createMdxLoader } from "../mdx-Bcb4tkWn.js";
|
|
2
|
+
import { i as buildConfig, t as createCore } from "../core-BPlsDtvN.js";
|
|
3
|
+
import { r as slash } from "../codegen-ESdi9CDJ.js";
|
|
4
|
+
import { a as createIntegratedConfigLoader, t as toBun } from "../adapter-DvWJNDHu.js";
|
|
5
|
+
import { t as createMetaLoader } from "../meta-DWvKGgBH.js";
|
|
6
|
+
import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-DWC_Uwqq.js";
|
|
7
|
+
import { r as resolveMacroOptions } from "../options-BNnYUjkM.js";
|
|
8
|
+
import fs from "node:fs/promises";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { randomUUID } from "node:crypto";
|
|
11
|
+
import picomatch from "picomatch";
|
|
6
12
|
import { pathToFileURL } from "node:url";
|
|
7
13
|
//#region src/bun/index.ts
|
|
14
|
+
const EvalQueryKey = "fd-macro-eval";
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
function macroFilter(root, { include, exclude }) {
|
|
19
|
+
const toSource = (pattern) => picomatch.makeRe(slash(path.resolve(root, pattern)), { dot: true }).source;
|
|
20
|
+
const included = include.map((pattern) => `(?:${toSource(pattern).replace(/\$$/, String.raw`(?:\?.*)?$`)})`).join("|");
|
|
21
|
+
const excluded = exclude.map((pattern) => `(?:${toSource(pattern)})`).join("|");
|
|
22
|
+
return new RegExp(`^(?!${excluded})(?:${included})`);
|
|
23
|
+
}
|
|
24
|
+
function bunLoader(file) {
|
|
25
|
+
if (file.endsWith(".tsx")) return "tsx";
|
|
26
|
+
if (file.endsWith(".jsx")) return "jsx";
|
|
27
|
+
if (/\.[cm]?ts$/.test(file)) return "ts";
|
|
28
|
+
return "js";
|
|
29
|
+
}
|
|
8
30
|
function createMdxPlugin(options = {}) {
|
|
9
|
-
const {
|
|
31
|
+
const { disableMetaFile = false } = options;
|
|
32
|
+
const macroOptions = resolveMacroOptions(options.macro);
|
|
10
33
|
return {
|
|
11
34
|
name: "bun-plugin-fumadocs-mdx",
|
|
12
35
|
async setup(build) {
|
|
13
|
-
const importPath = pathToFileURL(configPath).href;
|
|
14
36
|
const core = createCore({
|
|
15
|
-
environment,
|
|
16
|
-
outDir,
|
|
17
|
-
configPath
|
|
37
|
+
environment: "bun",
|
|
38
|
+
outDir: options.outDir,
|
|
39
|
+
configPath: options.configPath,
|
|
40
|
+
plugins: options.plugins
|
|
18
41
|
});
|
|
19
|
-
|
|
42
|
+
const importPath = pathToFileURL(core.configPath).href;
|
|
43
|
+
const configExports = await fs.access(core.configPath).then(() => true, () => false) ? await import(importPath) : {};
|
|
44
|
+
await core.init({ config: buildConfig(configExports, process.cwd()) });
|
|
45
|
+
if (macroOptions) {
|
|
46
|
+
const root = process.cwd();
|
|
47
|
+
const { MacroCollector } = await import("../eval-z3HV4VJp.js").then((n) => n.r);
|
|
48
|
+
const pendingEvals = /* @__PURE__ */ new Map();
|
|
49
|
+
core.macro = new MacroCollector({
|
|
50
|
+
root,
|
|
51
|
+
outDir: core.outDir,
|
|
52
|
+
isDev: false,
|
|
53
|
+
async evaluator({ entry, transform }) {
|
|
54
|
+
const token = randomUUID();
|
|
55
|
+
pendingEvals.set(token, transform);
|
|
56
|
+
try {
|
|
57
|
+
await import(`${entry}?${EvalQueryKey}=${token}`);
|
|
58
|
+
} finally {
|
|
59
|
+
pendingEvals.delete(token);
|
|
60
|
+
}
|
|
61
|
+
return { inputs: [entry] };
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const filter = macroFilter(root, macroOptions);
|
|
65
|
+
build.onLoad({ filter }, async (args) => {
|
|
66
|
+
const [file, query = ""] = args.path.split("?", 2);
|
|
67
|
+
const loader = bunLoader(file);
|
|
68
|
+
const source = await Bun.file(file).text();
|
|
69
|
+
if (!source.includes("fumadocs-mdx/macro")) return {
|
|
70
|
+
contents: source,
|
|
71
|
+
loader
|
|
72
|
+
};
|
|
73
|
+
const token = new URLSearchParams(query).get(EvalQueryKey);
|
|
74
|
+
const transform = token ? pendingEvals.get(token) : void 0;
|
|
75
|
+
if (transform) return {
|
|
76
|
+
contents: await transform(source, file) ?? source,
|
|
77
|
+
loader
|
|
78
|
+
};
|
|
79
|
+
const { transformMacroModule } = await import("../transform-BFobDsdE.js").then((n) => n.i);
|
|
80
|
+
return {
|
|
81
|
+
contents: (await transformMacroModule({
|
|
82
|
+
code: source,
|
|
83
|
+
file,
|
|
84
|
+
root,
|
|
85
|
+
target: "import"
|
|
86
|
+
}))?.code ?? source,
|
|
87
|
+
loader
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
}
|
|
20
91
|
const configLoader = createIntegratedConfigLoader(core);
|
|
21
92
|
toBun(mdxLoaderGlob, createMdxLoader(configLoader))(build);
|
|
22
|
-
if (!disableMetaFile) toBun(metaLoaderGlob, createMetaLoader(configLoader))(build);
|
|
93
|
+
if (!disableMetaFile) toBun(metaLoaderGlob, createMetaLoader(configLoader, {}))(build);
|
|
23
94
|
}
|
|
24
95
|
};
|
|
25
96
|
}
|
|
26
97
|
//#endregion
|
|
27
|
-
export { createMdxPlugin };
|
|
98
|
+
export { createMdxPlugin, macroFilter };
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { C as DocsCollection, D as defineCollections, E as SatteriPresetOptions, F as DefaultMDXOptions, I as MDXPresetOptions, L as applyMdxPreset, O as defineConfig, P as PostprocessOptions, S as DocCollectionSatteri, T as MetaCollection, _ as BaseCollection, b as DocCollectionBase, g as AnyCollection, k as defineDocs, v as CollectionSchema, w as GlobalConfig, x as DocCollectionMdx, y as DocCollection } from "../core-BmvJhZxm.js";
|
|
2
|
+
import { n as metaSchema, r as remarkInclude, t as frontmatterSchema } from "../index-BN7EkING.js";
|
|
3
|
+
export { AnyCollection, BaseCollection, CollectionSchema, DefaultMDXOptions, DocCollection, DocCollectionBase, DocCollectionMdx, DocCollectionSatteri, DocsCollection, GlobalConfig, MDXPresetOptions, MetaCollection, type PostprocessOptions, type SatteriPresetOptions, applyMdxPreset, defineCollections, defineConfig, defineDocs, frontmatterSchema, metaSchema, remarkInclude };
|
package/dist/config/index.js
CHANGED
|
@@ -1,42 +1,10 @@
|
|
|
1
|
+
import { n as defineConfig, r as defineDocs, t as defineCollections } from "../define-BW5lveuc.js";
|
|
1
2
|
import { r as applyMdxPreset, t as remarkInclude } from "../remark-include-B6rmf4sh.js";
|
|
2
3
|
import { metaSchema as metaSchema$1, pageSchema } from "fumadocs-core/source/schema";
|
|
3
|
-
//#region src/config/define.ts
|
|
4
|
-
function defineCollections(options) {
|
|
5
|
-
return options;
|
|
6
|
-
}
|
|
7
|
-
function defineDocs(options) {
|
|
8
|
-
const dir = options.dir ?? "content/docs";
|
|
9
|
-
return {
|
|
10
|
-
type: "docs",
|
|
11
|
-
dir,
|
|
12
|
-
docs: defineCollections({
|
|
13
|
-
type: "doc",
|
|
14
|
-
dir,
|
|
15
|
-
schema: pageSchema,
|
|
16
|
-
...options?.docs
|
|
17
|
-
}),
|
|
18
|
-
meta: defineCollections({
|
|
19
|
-
type: "meta",
|
|
20
|
-
dir,
|
|
21
|
-
schema: metaSchema$1,
|
|
22
|
-
...options?.meta
|
|
23
|
-
})
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function defineConfig(config = {}) {
|
|
27
|
-
return config;
|
|
28
|
-
}
|
|
29
|
-
function defineSatteriConfig(config = {}) {
|
|
30
|
-
return config;
|
|
31
|
-
}
|
|
32
|
-
function defineSatteriCollections(options) {
|
|
33
|
-
return options;
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
36
4
|
//#region src/config/index.ts
|
|
37
5
|
/** @deprecated import `pageSchema` from `fumadocs-core/source/schema` instead (since 16.2.3) */
|
|
38
6
|
const frontmatterSchema = pageSchema;
|
|
39
7
|
/** @deprecated import from `fumadocs-core/source/schema` instead (since 16.2.3) */
|
|
40
8
|
const metaSchema = metaSchema$1;
|
|
41
9
|
//#endregion
|
|
42
|
-
export { applyMdxPreset, defineCollections, defineConfig, defineDocs,
|
|
10
|
+
export { applyMdxPreset, defineCollections, defineConfig, defineDocs, frontmatterSchema, metaSchema, remarkInclude };
|
|
@@ -103,10 +103,6 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
103
103
|
}
|
|
104
104
|
//#endregion
|
|
105
105
|
//#region src/core.ts
|
|
106
|
-
const _Defaults = {
|
|
107
|
-
configPath: "source.config.ts",
|
|
108
|
-
outDir: ".source"
|
|
109
|
-
};
|
|
110
106
|
async function getPlugins(pluginOptions) {
|
|
111
107
|
const plugins = [];
|
|
112
108
|
for await (const option of pluginOptions) {
|
|
@@ -117,6 +113,9 @@ async function getPlugins(pluginOptions) {
|
|
|
117
113
|
return plugins;
|
|
118
114
|
}
|
|
119
115
|
function createCore(options) {
|
|
116
|
+
const root = options.root ? path.resolve(options.root) : process.cwd();
|
|
117
|
+
const outDir = path.resolve(root, options.outDir ?? ".source");
|
|
118
|
+
const configPath = path.resolve(root, options.configPath ?? "source.config.ts");
|
|
120
119
|
let config;
|
|
121
120
|
let plugins;
|
|
122
121
|
const workspaces = /* @__PURE__ */ new Map();
|
|
@@ -132,6 +131,31 @@ function createCore(options) {
|
|
|
132
131
|
* Convenient cache store, reset when config changes
|
|
133
132
|
*/
|
|
134
133
|
cache: /* @__PURE__ */ new Map(),
|
|
134
|
+
/**
|
|
135
|
+
* Collects the collections declared with `fumadocs-mdx/macro`.
|
|
136
|
+
*
|
|
137
|
+
* Assigned by the bundler adapter when the macro API is enabled, so that every loader of a
|
|
138
|
+
* build shares one collector (and hence one evaluation of each macro module).
|
|
139
|
+
*/
|
|
140
|
+
macro: void 0,
|
|
141
|
+
/** absolute path */
|
|
142
|
+
get outDir() {
|
|
143
|
+
return outDir;
|
|
144
|
+
},
|
|
145
|
+
/** absolute path */
|
|
146
|
+
get root() {
|
|
147
|
+
return root;
|
|
148
|
+
},
|
|
149
|
+
/** absolute path */
|
|
150
|
+
get configPath() {
|
|
151
|
+
return configPath;
|
|
152
|
+
},
|
|
153
|
+
get workspace() {
|
|
154
|
+
return options.workspace;
|
|
155
|
+
},
|
|
156
|
+
get environment() {
|
|
157
|
+
return options.environment;
|
|
158
|
+
},
|
|
135
159
|
async init({ config: newConfig }) {
|
|
136
160
|
config = await newConfig;
|
|
137
161
|
this.cache.clear();
|
|
@@ -148,7 +172,7 @@ function createCore(options) {
|
|
|
148
172
|
if (!options.workspace) await Promise.all(Object.entries(config.workspaces).map(async ([name, workspace]) => {
|
|
149
173
|
const core = createCore({
|
|
150
174
|
...options,
|
|
151
|
-
outDir: path.join(
|
|
175
|
+
outDir: path.join(outDir, name),
|
|
152
176
|
workspace: {
|
|
153
177
|
name,
|
|
154
178
|
parent: this,
|
|
@@ -162,9 +186,6 @@ function createCore(options) {
|
|
|
162
186
|
getWorkspaces() {
|
|
163
187
|
return workspaces;
|
|
164
188
|
},
|
|
165
|
-
getOptions() {
|
|
166
|
-
return options;
|
|
167
|
-
},
|
|
168
189
|
getConfig() {
|
|
169
190
|
return config;
|
|
170
191
|
},
|
|
@@ -172,7 +193,7 @@ function createCore(options) {
|
|
|
172
193
|
* The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
|
|
173
194
|
*/
|
|
174
195
|
getCompiledConfigPath() {
|
|
175
|
-
return path.join(
|
|
196
|
+
return path.join(outDir, "source.config.mjs");
|
|
176
197
|
},
|
|
177
198
|
getPlugins() {
|
|
178
199
|
return plugins;
|
|
@@ -213,7 +234,7 @@ function createCore(options) {
|
|
|
213
234
|
}
|
|
214
235
|
if (write) {
|
|
215
236
|
await Promise.all(out.entries.map(async (entry) => {
|
|
216
|
-
const file = path.join(
|
|
237
|
+
const file = path.join(outDir, entry.path);
|
|
217
238
|
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
218
239
|
await fs.writeFile(file, entry.content);
|
|
219
240
|
}));
|
|
@@ -253,6 +274,15 @@ function createCore(options) {
|
|
|
253
274
|
}
|
|
254
275
|
};
|
|
255
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* @returns the doc collection of a `doc`/`docs` collection, `undefined` for `meta`
|
|
279
|
+
*/
|
|
280
|
+
function docCollectionOf(collection) {
|
|
281
|
+
switch (collection.type) {
|
|
282
|
+
case "doc": return collection;
|
|
283
|
+
case "docs": return collection.docs;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
256
286
|
function postprocessPlugin() {
|
|
257
287
|
const LinkReferenceTypes = `{
|
|
258
288
|
/**
|
|
@@ -260,33 +290,29 @@ function postprocessPlugin() {
|
|
|
260
290
|
*/
|
|
261
291
|
extractedReferences: import("fumadocs-mdx").ExtractedReference[];
|
|
262
292
|
}`;
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
lines.push(
|
|
281
|
-
lines.push("}");
|
|
282
|
-
return lines.join("\n");
|
|
283
|
-
},
|
|
284
|
-
serverOptions(options) {
|
|
285
|
-
options.doc ??= {};
|
|
286
|
-
options.doc.passthroughs ??= [];
|
|
287
|
-
options.doc.passthroughs.push("extractedReferences");
|
|
293
|
+
const LastModifiedTypes = `{
|
|
294
|
+
/**
|
|
295
|
+
* Last modified date of document file, obtained from version control.
|
|
296
|
+
*/
|
|
297
|
+
lastModified?: Date;
|
|
298
|
+
}`;
|
|
299
|
+
return { "index-file": { generateTypeConfig() {
|
|
300
|
+
const lines = [];
|
|
301
|
+
lines.push("{");
|
|
302
|
+
lines.push(" DocData: {");
|
|
303
|
+
for (const collection of this.core.getCollections()) {
|
|
304
|
+
const docs = docCollectionOf(collection);
|
|
305
|
+
if (!docs) continue;
|
|
306
|
+
const extras = [];
|
|
307
|
+
if (docs.postprocess?.extractLinkReferences) extras.push(LinkReferenceTypes);
|
|
308
|
+
if (docs.lastModified) extras.push(LastModifiedTypes);
|
|
309
|
+
if (extras.length === 0) continue;
|
|
310
|
+
lines.push(ident(`${collection.name}: ${extras.join(" & ")},`, 2));
|
|
288
311
|
}
|
|
289
|
-
|
|
312
|
+
lines.push(" }");
|
|
313
|
+
lines.push("}");
|
|
314
|
+
return lines.join("\n");
|
|
315
|
+
} } };
|
|
290
316
|
}
|
|
291
317
|
//#endregion
|
|
292
|
-
export { buildConfig as i,
|
|
318
|
+
export { buildConfig as i, ValidationError as n, buildCollection as r, createCore as t };
|