fumadocs-mdx 14.0.4 → 14.1.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-W3233QBZ.js → build-mdx-RXJZQXGA.js} +2 -2
- package/dist/bun/index.d.ts +2 -2
- package/dist/bun/index.js +6 -6
- package/dist/{chunk-KOPLIEVQ.js → chunk-7W73RILB.js} +2 -1
- package/dist/{chunk-LPX7ZO66.js → chunk-DTFUANSF.js} +1 -1
- package/dist/{chunk-CGGDM5F3.js → chunk-K7N6GD4M.js} +1 -1
- package/dist/{chunk-6RPNS75C.js → chunk-OLD35ARB.js} +43 -31
- package/dist/{chunk-WBIHDYMN.js → chunk-PW2AZGGD.js} +3 -4
- package/dist/{chunk-USWQVJWR.js → chunk-T6G5VOED.js} +21 -12
- package/dist/{chunk-ED3ON275.js → chunk-VITVHHR6.js} +85 -81
- package/dist/{chunk-K4KWUM3J.js → chunk-VKSHE52K.js} +83 -34
- package/dist/{chunk-NKIL543T.js → chunk-WAAWFNDX.js} +18 -20
- package/dist/{chunk-FBLMK4RS.js → chunk-Y7ISNZ7X.js} +22 -16
- package/dist/{chunk-TYJDYTKH.js → chunk-ZAYZWFWP.js} +10 -6
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +6 -5
- package/dist/{core-C3QZSdEx.d.ts → core-X5ggQtBM.d.ts} +50 -41
- package/dist/index-BqkSNsGO.d.ts +8 -0
- package/dist/index.d.ts +2 -2
- package/dist/{load-from-file-OZ5N7DXU.js → load-from-file-FHW724YY.js} +2 -2
- package/dist/next/index.cjs +251 -201
- package/dist/next/index.d.ts +2 -2
- package/dist/next/index.js +21 -36
- package/dist/node/loader.js +5 -5
- package/dist/plugins/index-file.d.ts +2 -2
- package/dist/plugins/index-file.js +2 -2
- package/dist/plugins/json-schema.d.ts +2 -2
- package/dist/plugins/json-schema.js +4 -7
- package/dist/plugins/last-modified.d.ts +2 -2
- package/dist/plugins/last-modified.js +20 -13
- package/dist/runtime/browser.d.ts +2 -2
- package/dist/runtime/dynamic.d.ts +2 -2
- package/dist/runtime/dynamic.js +6 -6
- package/dist/runtime/server.d.ts +2 -2
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +16 -18
- package/dist/webpack/mdx.d.ts +1 -15
- package/dist/webpack/mdx.js +5 -5
- package/dist/webpack/meta.d.ts +1 -15
- package/dist/webpack/meta.js +5 -5
- package/package.json +12 -13
- package/dist/index-DG1I0CwF.d.ts +0 -8
package/dist/bun/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BunPlugin } from 'bun';
|
|
2
|
-
import { C as CoreOptions } from '../core-
|
|
2
|
+
import { C as CoreOptions } from '../core-X5ggQtBM.js';
|
|
3
3
|
import '@mdx-js/mdx';
|
|
4
4
|
import '@standard-schema/spec';
|
|
5
5
|
import 'unified';
|
|
6
6
|
import 'fumadocs-core/mdx-plugins';
|
|
7
|
-
import '
|
|
7
|
+
import 'fumadocs-core/source/schema';
|
|
8
8
|
import 'chokidar';
|
|
9
9
|
import 'vfile';
|
|
10
10
|
import 'fumadocs-core/source';
|
package/dist/bun/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildConfig
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-OLD35ARB.js";
|
|
4
4
|
import "../chunk-S7KOJHHO.js";
|
|
5
5
|
import {
|
|
6
6
|
createMdxLoader
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-T6G5VOED.js";
|
|
8
8
|
import {
|
|
9
9
|
createMetaLoader
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-ZAYZWFWP.js";
|
|
11
11
|
import {
|
|
12
12
|
createIntegratedConfigLoader,
|
|
13
13
|
toBun
|
|
14
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-WAAWFNDX.js";
|
|
15
15
|
import "../chunk-4JSFLXXT.js";
|
|
16
16
|
import {
|
|
17
17
|
_Defaults,
|
|
18
18
|
createCore
|
|
19
|
-
} from "../chunk-
|
|
20
|
-
import "../chunk-
|
|
19
|
+
} from "../chunk-VKSHE52K.js";
|
|
20
|
+
import "../chunk-PW2AZGGD.js";
|
|
21
21
|
import "../chunk-VWJKRQZR.js";
|
|
22
22
|
|
|
23
23
|
// src/bun/index.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
flattenNode,
|
|
3
3
|
remarkInclude
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-Y7ISNZ7X.js";
|
|
5
5
|
|
|
6
6
|
// src/loaders/mdx/build-mdx.ts
|
|
7
7
|
import { createProcessor } from "@mdx-js/mdx";
|
|
@@ -159,6 +159,7 @@ async function buildMDX(core, collection, {
|
|
|
159
159
|
let vfile = new VFile({
|
|
160
160
|
value: source,
|
|
161
161
|
path: filePath,
|
|
162
|
+
cwd: collection?.cwd,
|
|
162
163
|
data: { frontmatter, _compiler, _getProcessor: getProcessor }
|
|
163
164
|
});
|
|
164
165
|
if (collection) {
|
|
@@ -4,46 +4,57 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/config/build.ts
|
|
6
6
|
import picomatch from "picomatch";
|
|
7
|
+
import path from "path";
|
|
7
8
|
var SupportedFormats = {
|
|
8
9
|
doc: ["mdx", "md"],
|
|
9
10
|
meta: ["json", "yaml"]
|
|
10
11
|
};
|
|
11
|
-
function buildCollection(name,
|
|
12
|
-
if (
|
|
12
|
+
function buildCollection(name, collection, cwd) {
|
|
13
|
+
if (collection.type === "docs") {
|
|
13
14
|
return {
|
|
14
|
-
...
|
|
15
|
+
...collection,
|
|
16
|
+
type: "docs",
|
|
17
|
+
get dir() {
|
|
18
|
+
return this.docs.dir;
|
|
19
|
+
},
|
|
15
20
|
name,
|
|
16
|
-
meta:
|
|
17
|
-
docs:
|
|
21
|
+
meta: buildCollection(name, collection.meta, cwd),
|
|
22
|
+
docs: buildCollection(name, collection.docs, cwd),
|
|
18
23
|
hasFile(filePath) {
|
|
19
24
|
return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);
|
|
20
|
-
}
|
|
25
|
+
},
|
|
26
|
+
isFileSupported(filePath) {
|
|
27
|
+
return this.docs.isFileSupported(filePath) || this.meta.isFileSupported(filePath);
|
|
28
|
+
},
|
|
29
|
+
cwd
|
|
21
30
|
};
|
|
22
31
|
}
|
|
23
|
-
return
|
|
32
|
+
return {
|
|
33
|
+
...collection,
|
|
34
|
+
...buildPrimitiveCollection(name, collection, cwd)
|
|
35
|
+
};
|
|
24
36
|
}
|
|
25
|
-
function buildPrimitiveCollection(name,
|
|
37
|
+
function buildPrimitiveCollection(name, config, cwd) {
|
|
26
38
|
const supportedFormats = SupportedFormats[config.type];
|
|
27
|
-
const patterns = files ?? [`**/*.{${supportedFormats.join(",")}}`];
|
|
28
|
-
let
|
|
39
|
+
const patterns = config.files ?? [`**/*.{${supportedFormats.join(",")}}`];
|
|
40
|
+
let matcher;
|
|
29
41
|
return {
|
|
30
|
-
|
|
42
|
+
dir: path.resolve(cwd, config.dir),
|
|
43
|
+
cwd,
|
|
31
44
|
name,
|
|
32
45
|
patterns,
|
|
33
46
|
isFileSupported(filePath) {
|
|
34
47
|
return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
|
|
35
48
|
},
|
|
36
49
|
hasFile(filePath) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
);
|
|
42
|
-
return this.isFileSupported(filePath) && matchers.some((matcher) => matcher(filePath));
|
|
50
|
+
if (!this.isFileSupported(filePath)) return false;
|
|
51
|
+
const relativePath = path.relative(this.dir, filePath);
|
|
52
|
+
if (relativePath.startsWith(`..${path.sep}`)) return false;
|
|
53
|
+
return (matcher ??= picomatch(patterns))(relativePath);
|
|
43
54
|
}
|
|
44
55
|
};
|
|
45
56
|
}
|
|
46
|
-
function buildConfig(config) {
|
|
57
|
+
function buildConfig(config, cwd = process.cwd()) {
|
|
47
58
|
const collections = /* @__PURE__ */ new Map();
|
|
48
59
|
const loaded = {};
|
|
49
60
|
for (const [k, v] of Object.entries(config)) {
|
|
@@ -51,15 +62,8 @@ function buildConfig(config) {
|
|
|
51
62
|
continue;
|
|
52
63
|
}
|
|
53
64
|
if (typeof v === "object" && "type" in v) {
|
|
54
|
-
if (v.type === "docs") {
|
|
55
|
-
collections.set(k, buildCollection(k, v));
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
if (v.type === "doc" || v.type === "meta") {
|
|
59
|
-
collections.set(
|
|
60
|
-
k,
|
|
61
|
-
buildCollection(k, v)
|
|
62
|
-
);
|
|
65
|
+
if (v.type === "docs" || v.type === "doc" || v.type === "meta") {
|
|
66
|
+
collections.set(k, buildCollection(k, v, cwd));
|
|
63
67
|
continue;
|
|
64
68
|
}
|
|
65
69
|
}
|
|
@@ -74,10 +78,18 @@ function buildConfig(config) {
|
|
|
74
78
|
const mdxOptionsCache = /* @__PURE__ */ new Map();
|
|
75
79
|
return {
|
|
76
80
|
global: loaded,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
collections,
|
|
82
|
+
workspaces: Object.fromEntries(
|
|
83
|
+
Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {
|
|
84
|
+
return [
|
|
85
|
+
key,
|
|
86
|
+
{
|
|
87
|
+
dir: value.dir,
|
|
88
|
+
config: buildConfig(value.config, path.resolve(cwd, value.dir))
|
|
89
|
+
}
|
|
90
|
+
];
|
|
91
|
+
})
|
|
92
|
+
),
|
|
81
93
|
getMDXOptions(collection, environment = "bundler") {
|
|
82
94
|
const key = collection ? `${environment}:${collection.name}` : environment;
|
|
83
95
|
const cached = mdxOptionsCache.get(key);
|
|
@@ -65,7 +65,7 @@ function createCodegen({
|
|
|
65
65
|
const fullPath = path.join(base, item);
|
|
66
66
|
const searchParams = new URLSearchParams();
|
|
67
67
|
for (const [k, v] of Object.entries(query)) {
|
|
68
|
-
searchParams.set(k, v);
|
|
68
|
+
if (v !== void 0) searchParams.set(k, v);
|
|
69
69
|
}
|
|
70
70
|
const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
|
|
71
71
|
if (eager) {
|
|
@@ -88,10 +88,9 @@ function createCodegen({
|
|
|
88
88
|
formatImportPath(file) {
|
|
89
89
|
const ext = path.extname(file);
|
|
90
90
|
let filename;
|
|
91
|
-
if (ext === ".ts"
|
|
92
|
-
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
93
|
-
} else if (ext === ".ts") {
|
|
91
|
+
if (ext === ".ts") {
|
|
94
92
|
filename = file.substring(0, file.length - ext.length);
|
|
93
|
+
if (jsExtension) filename += ".js";
|
|
95
94
|
} else {
|
|
96
95
|
filename = file;
|
|
97
96
|
}
|
|
@@ -12,14 +12,15 @@ import path from "path";
|
|
|
12
12
|
import { createHash } from "crypto";
|
|
13
13
|
var querySchema = z.object({
|
|
14
14
|
only: z.literal(["frontmatter", "all"]).default("all"),
|
|
15
|
-
collection: z.string().optional()
|
|
15
|
+
collection: z.string().optional(),
|
|
16
|
+
workspace: z.string().optional()
|
|
16
17
|
}).loose();
|
|
17
18
|
var cacheEntry = z.object({
|
|
18
19
|
code: z.string(),
|
|
19
20
|
map: z.any().optional(),
|
|
20
21
|
hash: z.string().optional()
|
|
21
22
|
});
|
|
22
|
-
function createMdxLoader(
|
|
23
|
+
function createMdxLoader({ getCore }) {
|
|
23
24
|
return {
|
|
24
25
|
test: mdxLoaderGlob,
|
|
25
26
|
async load({
|
|
@@ -29,14 +30,22 @@ function createMdxLoader(configLoader) {
|
|
|
29
30
|
compiler,
|
|
30
31
|
filePath
|
|
31
32
|
}) {
|
|
32
|
-
|
|
33
|
+
let core = await getCore();
|
|
33
34
|
const value = await getSource();
|
|
34
35
|
const matter = fumaMatter(value);
|
|
35
|
-
const
|
|
36
|
+
const {
|
|
37
|
+
collection: collectionName,
|
|
38
|
+
workspace,
|
|
39
|
+
only
|
|
40
|
+
} = querySchema.parse(query);
|
|
41
|
+
if (workspace) {
|
|
42
|
+
core = core.getWorkspaces().get(workspace) ?? core;
|
|
43
|
+
}
|
|
36
44
|
let after;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
45
|
+
const { experimentalBuildCache = false } = core.getConfig().global;
|
|
46
|
+
if (!isDevelopment && experimentalBuildCache) {
|
|
47
|
+
const cacheDir = experimentalBuildCache;
|
|
48
|
+
const cacheKey = `${collectionName ?? "global"}_${generateCacheHash(filePath)}`;
|
|
40
49
|
const cached = await fs.readFile(path.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
|
|
41
50
|
if (cached && cached.hash === generateCacheHash(value)) return cached;
|
|
42
51
|
after = async () => {
|
|
@@ -50,7 +59,7 @@ function createMdxLoader(configLoader) {
|
|
|
50
59
|
);
|
|
51
60
|
};
|
|
52
61
|
}
|
|
53
|
-
const collection =
|
|
62
|
+
const collection = collectionName ? core.getCollection(collectionName) : void 0;
|
|
54
63
|
let docCollection;
|
|
55
64
|
switch (collection?.type) {
|
|
56
65
|
case "doc":
|
|
@@ -61,20 +70,20 @@ function createMdxLoader(configLoader) {
|
|
|
61
70
|
break;
|
|
62
71
|
}
|
|
63
72
|
if (docCollection) {
|
|
64
|
-
matter.data = await
|
|
73
|
+
matter.data = await core.transformFrontmatter(
|
|
65
74
|
{ collection: docCollection, filePath, source: value },
|
|
66
75
|
matter.data
|
|
67
76
|
);
|
|
68
77
|
}
|
|
69
|
-
if (
|
|
78
|
+
if (only === "frontmatter") {
|
|
70
79
|
return {
|
|
71
80
|
code: `export const frontmatter = ${JSON.stringify(matter.data)}`,
|
|
72
81
|
map: null
|
|
73
82
|
};
|
|
74
83
|
}
|
|
75
84
|
const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
|
|
76
|
-
const { buildMDX } = await import("./build-mdx-
|
|
77
|
-
const compiled = await buildMDX(
|
|
85
|
+
const { buildMDX } = await import("./build-mdx-RXJZQXGA.js");
|
|
86
|
+
const compiled = await buildMDX(core, docCollection, {
|
|
78
87
|
isDevelopment,
|
|
79
88
|
source: "\n".repeat(lineOffset) + matter.content,
|
|
80
89
|
filePath,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createCodegen,
|
|
3
3
|
ident
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-PW2AZGGD.js";
|
|
5
5
|
import {
|
|
6
6
|
fumaMatter
|
|
7
7
|
} from "./chunk-VWJKRQZR.js";
|
|
@@ -11,32 +11,34 @@ import path2 from "path";
|
|
|
11
11
|
import { glob } from "tinyglobby";
|
|
12
12
|
|
|
13
13
|
// src/utils/fs-cache.ts
|
|
14
|
-
import { LRUCache } from "lru-cache";
|
|
15
14
|
import fs from "fs/promises";
|
|
16
15
|
import path from "path";
|
|
17
|
-
var map = new
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
var map = /* @__PURE__ */ new Map();
|
|
17
|
+
function createFSCache() {
|
|
18
|
+
return {
|
|
19
|
+
read(file) {
|
|
20
|
+
const fullPath = toFullPath(file);
|
|
21
|
+
const cached = map.get(fullPath);
|
|
22
|
+
if (cached) return cached;
|
|
23
|
+
const read = fs.readFile(fullPath).then((s) => s.toString());
|
|
24
|
+
map.set(fullPath, read);
|
|
25
|
+
return read;
|
|
26
|
+
},
|
|
27
|
+
delete(file) {
|
|
28
|
+
map.delete(toFullPath(file));
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
20
32
|
function toFullPath(file) {
|
|
21
33
|
if (path.isAbsolute(file)) {
|
|
22
34
|
return path.relative(process.cwd(), file);
|
|
23
35
|
}
|
|
24
36
|
return file;
|
|
25
37
|
}
|
|
26
|
-
function readFileWithCache(file) {
|
|
27
|
-
const fullPath = toFullPath(file);
|
|
28
|
-
const cached = map.get(fullPath);
|
|
29
|
-
if (cached) return cached;
|
|
30
|
-
const read = fs.readFile(fullPath).then((s) => s.toString());
|
|
31
|
-
map.set(fullPath, read);
|
|
32
|
-
return read;
|
|
33
|
-
}
|
|
34
|
-
function removeFileCache(file) {
|
|
35
|
-
map.delete(toFullPath(file));
|
|
36
|
-
}
|
|
37
38
|
|
|
38
39
|
// src/plugins/index-file.ts
|
|
39
40
|
import { createHash } from "crypto";
|
|
41
|
+
var indexFileCache = createFSCache();
|
|
40
42
|
function indexFile(options = {}) {
|
|
41
43
|
const {
|
|
42
44
|
target = "default",
|
|
@@ -44,7 +46,6 @@ function indexFile(options = {}) {
|
|
|
44
46
|
browser = true,
|
|
45
47
|
dynamic = true
|
|
46
48
|
} = options;
|
|
47
|
-
let config;
|
|
48
49
|
let dynamicCollections;
|
|
49
50
|
function isDynamic(collection) {
|
|
50
51
|
return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
|
|
@@ -59,8 +60,8 @@ function indexFile(options = {}) {
|
|
|
59
60
|
const indexFilePlugin = plugin["index-file"];
|
|
60
61
|
if (!indexFilePlugin) continue;
|
|
61
62
|
indexFilePlugin.serverOptions?.call(ctx, serverOptions);
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
63
|
+
const config = indexFilePlugin.generateTypeConfig?.call(ctx);
|
|
64
|
+
if (config) typeConfigs.push(config);
|
|
64
65
|
}
|
|
65
66
|
return {
|
|
66
67
|
serverOptions,
|
|
@@ -69,38 +70,38 @@ function indexFile(options = {}) {
|
|
|
69
70
|
}
|
|
70
71
|
return {
|
|
71
72
|
name: "index-file",
|
|
72
|
-
config(
|
|
73
|
-
|
|
74
|
-
dynamicCollections = config.collectionList.filter(isDynamic);
|
|
73
|
+
config() {
|
|
74
|
+
dynamicCollections = this.core.getCollections().filter(isDynamic);
|
|
75
75
|
},
|
|
76
76
|
configureServer(server) {
|
|
77
77
|
if (!server.watcher) return;
|
|
78
78
|
server.watcher.on("all", async (event, file) => {
|
|
79
|
-
|
|
79
|
+
indexFileCache.delete(file);
|
|
80
80
|
if (dynamicCollections.length === 0) {
|
|
81
81
|
if (target === "vite") return;
|
|
82
82
|
if (target === "default" && event === "change") return;
|
|
83
83
|
}
|
|
84
|
-
const updatedCollection =
|
|
85
|
-
(collection) => collection.hasFile(file)
|
|
86
|
-
);
|
|
84
|
+
const updatedCollection = this.core.getCollections().find((collection) => collection.hasFile(file));
|
|
87
85
|
if (!updatedCollection) return;
|
|
88
86
|
if (!isDynamic(updatedCollection)) {
|
|
89
87
|
if (target === "vite") return;
|
|
90
88
|
if (target === "default" && event === "change") return;
|
|
91
89
|
}
|
|
92
|
-
await this.core.
|
|
93
|
-
filterPlugin: (plugin) => plugin.name === "index-file"
|
|
90
|
+
await this.core.emit({
|
|
91
|
+
filterPlugin: (plugin) => plugin.name === "index-file",
|
|
92
|
+
filterWorkspace: () => false,
|
|
93
|
+
write: true
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
96
|
},
|
|
97
97
|
async emit() {
|
|
98
98
|
const globCache = /* @__PURE__ */ new Map();
|
|
99
|
+
const { workspace, outDir } = this.core.getOptions();
|
|
99
100
|
const { serverOptions, tc } = generateConfigs(this.core);
|
|
100
101
|
const toEmitEntry = async (path3, content) => {
|
|
101
102
|
const codegen = createCodegen({
|
|
102
103
|
target,
|
|
103
|
-
outDir
|
|
104
|
+
outDir,
|
|
104
105
|
jsExtension: addJsExtension,
|
|
105
106
|
globCache
|
|
106
107
|
});
|
|
@@ -108,7 +109,8 @@ function indexFile(options = {}) {
|
|
|
108
109
|
core: this.core,
|
|
109
110
|
codegen,
|
|
110
111
|
serverOptions,
|
|
111
|
-
tc
|
|
112
|
+
tc,
|
|
113
|
+
workspace: workspace?.name
|
|
112
114
|
});
|
|
113
115
|
return {
|
|
114
116
|
path: path3,
|
|
@@ -126,12 +128,8 @@ function indexFile(options = {}) {
|
|
|
126
128
|
}
|
|
127
129
|
};
|
|
128
130
|
}
|
|
129
|
-
async function generateServerIndexFile({
|
|
130
|
-
core,
|
|
131
|
-
codegen,
|
|
132
|
-
serverOptions,
|
|
133
|
-
tc
|
|
134
|
-
}) {
|
|
131
|
+
async function generateServerIndexFile(ctx) {
|
|
132
|
+
const { core, codegen, serverOptions, tc } = ctx;
|
|
135
133
|
codegen.lines.push(
|
|
136
134
|
`import { server } from 'fumadocs-mdx/runtime/server';`,
|
|
137
135
|
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
@@ -139,51 +137,48 @@ async function generateServerIndexFile({
|
|
|
139
137
|
`const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`
|
|
140
138
|
);
|
|
141
139
|
async function generateCollectionObject(collection) {
|
|
140
|
+
const base = getBase(collection);
|
|
142
141
|
switch (collection.type) {
|
|
143
142
|
case "docs": {
|
|
144
143
|
if (collection.docs.dynamic) return;
|
|
145
144
|
if (collection.docs.async) {
|
|
146
145
|
const [metaGlob2, headGlob, bodyGlob] = await Promise.all([
|
|
147
|
-
generateMetaCollectionGlob(
|
|
148
|
-
generateDocCollectionFrontmatterGlob(
|
|
149
|
-
|
|
150
|
-
collection.docs,
|
|
151
|
-
true
|
|
152
|
-
),
|
|
153
|
-
generateDocCollectionGlob(codegen, collection.docs)
|
|
146
|
+
generateMetaCollectionGlob(ctx, collection.meta, true),
|
|
147
|
+
generateDocCollectionFrontmatterGlob(ctx, collection.docs, true),
|
|
148
|
+
generateDocCollectionGlob(ctx, collection.docs)
|
|
154
149
|
]);
|
|
155
|
-
return `await create.docsLazy("${collection.name}", "${
|
|
150
|
+
return `await create.docsLazy("${collection.name}", "${base}", ${metaGlob2}, ${headGlob}, ${bodyGlob})`;
|
|
156
151
|
}
|
|
157
152
|
const [metaGlob, docGlob] = await Promise.all([
|
|
158
|
-
generateMetaCollectionGlob(
|
|
159
|
-
generateDocCollectionGlob(
|
|
153
|
+
generateMetaCollectionGlob(ctx, collection.meta, true),
|
|
154
|
+
generateDocCollectionGlob(ctx, collection.docs, true)
|
|
160
155
|
]);
|
|
161
|
-
return `await create.docs("${collection.name}", "${
|
|
156
|
+
return `await create.docs("${collection.name}", "${base}", ${metaGlob}, ${docGlob})`;
|
|
162
157
|
}
|
|
163
158
|
case "doc":
|
|
164
159
|
if (collection.dynamic) return;
|
|
165
160
|
if (collection.async) {
|
|
166
161
|
const [headGlob, bodyGlob] = await Promise.all([
|
|
167
|
-
generateDocCollectionFrontmatterGlob(
|
|
168
|
-
generateDocCollectionGlob(
|
|
162
|
+
generateDocCollectionFrontmatterGlob(ctx, collection, true),
|
|
163
|
+
generateDocCollectionGlob(ctx, collection)
|
|
169
164
|
]);
|
|
170
|
-
return `await create.docLazy("${collection.name}", "${
|
|
165
|
+
return `await create.docLazy("${collection.name}", "${base}", ${headGlob}, ${bodyGlob})`;
|
|
171
166
|
}
|
|
172
|
-
return `await create.doc("${collection.name}", "${
|
|
173
|
-
|
|
167
|
+
return `await create.doc("${collection.name}", "${base}", ${await generateDocCollectionGlob(
|
|
168
|
+
ctx,
|
|
174
169
|
collection,
|
|
175
170
|
true
|
|
176
171
|
)})`;
|
|
177
172
|
case "meta":
|
|
178
|
-
return `await create.meta("${collection.name}", "${
|
|
179
|
-
|
|
173
|
+
return `await create.meta("${collection.name}", "${base}", ${await generateMetaCollectionGlob(
|
|
174
|
+
ctx,
|
|
180
175
|
collection,
|
|
181
176
|
true
|
|
182
177
|
)})`;
|
|
183
178
|
}
|
|
184
179
|
}
|
|
185
180
|
await codegen.pushAsync(
|
|
186
|
-
core.
|
|
181
|
+
core.getCollections().map(async (collection) => {
|
|
187
182
|
const obj = await generateCollectionObject(collection);
|
|
188
183
|
if (!obj) return;
|
|
189
184
|
return `
|
|
@@ -191,22 +186,23 @@ export const ${collection.name} = ${obj};`;
|
|
|
191
186
|
})
|
|
192
187
|
);
|
|
193
188
|
}
|
|
194
|
-
async function generateDynamicIndexFile({
|
|
195
|
-
core,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
189
|
+
async function generateDynamicIndexFile(ctx) {
|
|
190
|
+
const { core, codegen, serverOptions, tc } = ctx;
|
|
191
|
+
const { configPath, environment, outDir } = core.getOptions();
|
|
192
|
+
const partialOptions = {
|
|
193
|
+
configPath,
|
|
194
|
+
environment,
|
|
195
|
+
outDir
|
|
196
|
+
};
|
|
201
197
|
codegen.lines.push(
|
|
202
198
|
`import { dynamic } from 'fumadocs-mdx/runtime/dynamic';`,
|
|
203
199
|
`import * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
204
200
|
"",
|
|
205
|
-
`const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(
|
|
201
|
+
`const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(partialOptions)}, ${JSON.stringify(serverOptions)});`
|
|
206
202
|
);
|
|
207
|
-
async function generateCollectionObjectEntry(collection,
|
|
208
|
-
const fullPath = path2.
|
|
209
|
-
const content = await
|
|
203
|
+
async function generateCollectionObjectEntry(collection, absolutePath) {
|
|
204
|
+
const fullPath = path2.relative(process.cwd(), absolutePath);
|
|
205
|
+
const content = await indexFileCache.read(fullPath).catch(() => "");
|
|
210
206
|
const parsed = fumaMatter(content);
|
|
211
207
|
const data = await core.transformFrontmatter(
|
|
212
208
|
{
|
|
@@ -224,7 +220,7 @@ async function generateDynamicIndexFile({
|
|
|
224
220
|
for (const [k, v] of Object.entries({
|
|
225
221
|
info: {
|
|
226
222
|
fullPath,
|
|
227
|
-
path:
|
|
223
|
+
path: path2.relative(collection.dir, absolutePath)
|
|
228
224
|
},
|
|
229
225
|
data,
|
|
230
226
|
hash
|
|
@@ -239,7 +235,8 @@ async function generateDynamicIndexFile({
|
|
|
239
235
|
else if (parent.type === "docs") collection = parent.docs;
|
|
240
236
|
if (!collection || !collection.dynamic) return;
|
|
241
237
|
const files = await glob(collection.patterns, {
|
|
242
|
-
cwd: collection.dir
|
|
238
|
+
cwd: collection.dir,
|
|
239
|
+
absolute: true
|
|
243
240
|
});
|
|
244
241
|
const entries = await Promise.all(
|
|
245
242
|
files.map((file) => generateCollectionObjectEntry(collection, file))
|
|
@@ -247,18 +244,18 @@ async function generateDynamicIndexFile({
|
|
|
247
244
|
switch (parent.type) {
|
|
248
245
|
case "docs": {
|
|
249
246
|
const metaGlob = await generateMetaCollectionGlob(
|
|
250
|
-
|
|
247
|
+
ctx,
|
|
251
248
|
parent.meta,
|
|
252
249
|
true
|
|
253
250
|
);
|
|
254
|
-
return `await create.docs("${parent.name}", "${parent
|
|
251
|
+
return `await create.docs("${parent.name}", "${getBase(parent)}", ${metaGlob}, ${entries.join(", ")})`;
|
|
255
252
|
}
|
|
256
253
|
case "doc":
|
|
257
|
-
return `await create.doc("${collection.name}", "${collection
|
|
254
|
+
return `await create.doc("${collection.name}", "${getBase(collection)}", ${entries.join(", ")})`;
|
|
258
255
|
}
|
|
259
256
|
}
|
|
260
257
|
await codegen.pushAsync(
|
|
261
|
-
core.
|
|
258
|
+
core.getCollections().map(async (collection) => {
|
|
262
259
|
const obj = await generateCollectionObject(collection);
|
|
263
260
|
if (!obj) return;
|
|
264
261
|
return `
|
|
@@ -266,7 +263,8 @@ export const ${collection.name} = ${obj};`;
|
|
|
266
263
|
})
|
|
267
264
|
);
|
|
268
265
|
}
|
|
269
|
-
async function generateBrowserIndexFile(
|
|
266
|
+
async function generateBrowserIndexFile(ctx) {
|
|
267
|
+
const { core, codegen, tc } = ctx;
|
|
270
268
|
codegen.lines.push(
|
|
271
269
|
`import { browser } from 'fumadocs-mdx/runtime/browser';`,
|
|
272
270
|
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
@@ -281,12 +279,12 @@ async function generateBrowserIndexFile({ core, codegen, tc }) {
|
|
|
281
279
|
}
|
|
282
280
|
case "doc":
|
|
283
281
|
if (collection.dynamic) return;
|
|
284
|
-
return `create.doc("${collection.name}", ${await generateDocCollectionGlob(
|
|
282
|
+
return `create.doc("${collection.name}", ${await generateDocCollectionGlob(ctx, collection)})`;
|
|
285
283
|
}
|
|
286
284
|
}
|
|
287
285
|
codegen.lines.push("const browserCollections = {");
|
|
288
286
|
await codegen.pushAsync(
|
|
289
|
-
core.
|
|
287
|
+
core.getCollections().map(async (collection) => {
|
|
290
288
|
const obj = await generateCollectionObject(collection);
|
|
291
289
|
if (!obj) return;
|
|
292
290
|
return ident(`${collection.name}: ${obj},`);
|
|
@@ -294,30 +292,36 @@ async function generateBrowserIndexFile({ core, codegen, tc }) {
|
|
|
294
292
|
);
|
|
295
293
|
codegen.lines.push("};", "export default browserCollections;");
|
|
296
294
|
}
|
|
297
|
-
function
|
|
295
|
+
function getBase(collection) {
|
|
296
|
+
return path2.relative(process.cwd(), collection.dir);
|
|
297
|
+
}
|
|
298
|
+
function generateDocCollectionFrontmatterGlob({ codegen, workspace }, collection, eager = false) {
|
|
298
299
|
return codegen.generateGlobImport(collection.patterns, {
|
|
299
300
|
query: {
|
|
300
301
|
collection: collection.name,
|
|
301
|
-
only: "frontmatter"
|
|
302
|
+
only: "frontmatter",
|
|
303
|
+
workspace
|
|
302
304
|
},
|
|
303
305
|
import: "frontmatter",
|
|
304
306
|
base: collection.dir,
|
|
305
307
|
eager
|
|
306
308
|
});
|
|
307
309
|
}
|
|
308
|
-
function generateDocCollectionGlob(codegen, collection, eager = false) {
|
|
310
|
+
function generateDocCollectionGlob({ codegen, workspace }, collection, eager = false) {
|
|
309
311
|
return codegen.generateGlobImport(collection.patterns, {
|
|
310
312
|
query: {
|
|
311
|
-
collection: collection.name
|
|
313
|
+
collection: collection.name,
|
|
314
|
+
workspace
|
|
312
315
|
},
|
|
313
316
|
base: collection.dir,
|
|
314
317
|
eager
|
|
315
318
|
});
|
|
316
319
|
}
|
|
317
|
-
function generateMetaCollectionGlob(codegen, collection, eager = false) {
|
|
320
|
+
function generateMetaCollectionGlob({ codegen, workspace }, collection, eager = false) {
|
|
318
321
|
return codegen.generateGlobImport(collection.patterns, {
|
|
319
322
|
query: {
|
|
320
|
-
collection: collection.name
|
|
323
|
+
collection: collection.name,
|
|
324
|
+
workspace
|
|
321
325
|
},
|
|
322
326
|
import: "default",
|
|
323
327
|
base: collection.dir,
|