fumadocs-mdx 11.7.1 → 11.7.4
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/{chunk-C5INPAZJ.js → chunk-2K55VKP6.js} +1 -1
- package/dist/{chunk-2KBRPMAM.js → chunk-4CGSOZUZ.js} +3 -29
- package/dist/chunk-JFNBRKRV.js +47 -0
- package/dist/{chunk-AVMO2SRO.js → chunk-PQCNPAD3.js} +45 -10
- package/dist/chunk-VUEZTR2H.js +26 -0
- package/dist/config/index.cjs +45 -10
- package/dist/config/index.d.cts +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +1 -1
- package/dist/{define-CCrinVBZ.d.cts → define-E6TRBwBQ.d.cts} +1 -1
- package/dist/{define-CCrinVBZ.d.ts → define-E6TRBwBQ.d.ts} +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/loader-mdx.cjs +64 -35
- package/dist/loader-mdx.js +7 -5
- package/dist/next/index.cjs +20 -27
- package/dist/next/index.js +6 -5
- package/dist/runtime/async.cjs +63 -32
- package/dist/runtime/async.d.cts +3 -3
- package/dist/runtime/async.d.ts +3 -3
- package/dist/runtime/async.js +4 -4
- package/dist/runtime/vite.cjs +3 -2
- package/dist/runtime/vite.d.cts +9 -7
- package/dist/runtime/vite.d.ts +9 -7
- package/dist/runtime/vite.js +3 -2
- package/dist/{types-C0bKwtAx.d.ts → types-DiL328cG.d.ts} +2 -2
- package/dist/{types-CnslxmoO.d.cts → types-Lh_-Uuix.d.cts} +2 -2
- package/dist/vite/index.cjs +231 -167
- package/dist/vite/index.js +153 -138
- package/package.json +12 -11
- package/dist/chunk-GWR7KMRU.js +0 -51
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildConfig
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-JFNBRKRV.js";
|
|
4
4
|
|
|
5
5
|
// src/utils/config.ts
|
|
6
6
|
import * as fs from "fs/promises";
|
|
@@ -37,12 +37,10 @@ async function loadConfig(configPath, outDir, hash, build = false) {
|
|
|
37
37
|
if (build) await compileConfig(configPath, outDir);
|
|
38
38
|
const url = pathToFileURL(path.resolve(outDir, "source.config.mjs"));
|
|
39
39
|
const config = import(`${url.href}?hash=${hash}`).then((loaded) => {
|
|
40
|
-
|
|
40
|
+
return buildConfig(
|
|
41
41
|
// every call to `loadConfig` will cause the previous cache to be ignored
|
|
42
42
|
loaded
|
|
43
43
|
);
|
|
44
|
-
if (err !== null) throw new Error(err);
|
|
45
|
-
return config2;
|
|
46
44
|
});
|
|
47
45
|
cache = { config, hash };
|
|
48
46
|
return await config;
|
|
@@ -55,32 +53,8 @@ async function getConfigHash(configPath) {
|
|
|
55
53
|
throw new Error("Cannot find config file");
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
// src/utils/git-timestamp.ts
|
|
59
|
-
import path2 from "path";
|
|
60
|
-
import { x } from "tinyexec";
|
|
61
|
-
var cache2 = /* @__PURE__ */ new Map();
|
|
62
|
-
async function getGitTimestamp(file) {
|
|
63
|
-
const cached = cache2.get(file);
|
|
64
|
-
if (cached) return cached;
|
|
65
|
-
try {
|
|
66
|
-
const out = await x(
|
|
67
|
-
"git",
|
|
68
|
-
["log", "-1", '--pretty="%ai"', path2.relative(process.cwd(), file)],
|
|
69
|
-
{
|
|
70
|
-
throwOnError: true
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
const time = new Date(out.stdout);
|
|
74
|
-
cache2.set(file, time);
|
|
75
|
-
return time;
|
|
76
|
-
} catch {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
56
|
export {
|
|
82
57
|
findConfigFile,
|
|
83
58
|
loadConfig,
|
|
84
|
-
getConfigHash
|
|
85
|
-
getGitTimestamp
|
|
59
|
+
getConfigHash
|
|
86
60
|
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/config/build.ts
|
|
2
|
+
function buildConfig(config) {
|
|
3
|
+
const collections = /* @__PURE__ */ new Map();
|
|
4
|
+
let globalConfig = {};
|
|
5
|
+
for (const [k, v] of Object.entries(config)) {
|
|
6
|
+
if (!v) {
|
|
7
|
+
continue;
|
|
8
|
+
}
|
|
9
|
+
if (typeof v === "object" && "type" in v) {
|
|
10
|
+
if (v.type === "docs") {
|
|
11
|
+
collections.set(k, v);
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (v.type === "doc" || v.type === "meta") {
|
|
15
|
+
collections.set(k, v);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (k === "default" && v) {
|
|
20
|
+
globalConfig = v;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
throw new Error(
|
|
24
|
+
`Unknown export "${k}", you can only export collections from source configuration file.`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
let cachedMdxOptions;
|
|
28
|
+
return {
|
|
29
|
+
global: globalConfig,
|
|
30
|
+
collections,
|
|
31
|
+
async getDefaultMDXOptions() {
|
|
32
|
+
if (cachedMdxOptions) return cachedMdxOptions;
|
|
33
|
+
const input = this.global.mdxOptions;
|
|
34
|
+
async function uncached() {
|
|
35
|
+
const options = typeof input === "function" ? await input() : input;
|
|
36
|
+
const { getDefaultMDXOptions } = await import("./mdx-options-UDV5WEFU.js");
|
|
37
|
+
if (options?.preset === "minimal") return options;
|
|
38
|
+
return getDefaultMDXOptions(options ?? {});
|
|
39
|
+
}
|
|
40
|
+
return cachedMdxOptions = uncached();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
buildConfig
|
|
47
|
+
};
|
|
@@ -12,9 +12,29 @@ function flattenNode(node) {
|
|
|
12
12
|
if ("value" in node) return node.value;
|
|
13
13
|
return "";
|
|
14
14
|
}
|
|
15
|
+
function parseSpecifier(specifier) {
|
|
16
|
+
const idx = specifier.lastIndexOf("#");
|
|
17
|
+
if (idx === -1) return { file: specifier };
|
|
18
|
+
return {
|
|
19
|
+
file: specifier.slice(0, idx),
|
|
20
|
+
section: specifier.slice(idx + 1)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function extractSection(root, section) {
|
|
24
|
+
for (const node of root.children) {
|
|
25
|
+
if (node.type === "mdxJsxFlowElement" && node.name === "section" && node.attributes.some(
|
|
26
|
+
(attr) => attr.type === "mdxJsxAttribute" && attr.name === "id" && attr.value === section
|
|
27
|
+
)) {
|
|
28
|
+
return {
|
|
29
|
+
type: "root",
|
|
30
|
+
children: node.children
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
15
35
|
function remarkInclude() {
|
|
16
36
|
const TagName = "include";
|
|
17
|
-
async function update(tree,
|
|
37
|
+
async function update(tree, directory, processor, compiler) {
|
|
18
38
|
const queue = [];
|
|
19
39
|
visit(
|
|
20
40
|
tree,
|
|
@@ -34,27 +54,41 @@ function remarkInclude() {
|
|
|
34
54
|
}
|
|
35
55
|
}
|
|
36
56
|
if (!specifier) return;
|
|
57
|
+
const { file, section } = parseSpecifier(specifier);
|
|
37
58
|
const targetPath = path.resolve(
|
|
38
|
-
"cwd" in params ? process.cwd() :
|
|
39
|
-
|
|
59
|
+
"cwd" in params ? process.cwd() : directory,
|
|
60
|
+
file
|
|
40
61
|
);
|
|
41
|
-
const asCode = params.lang || !
|
|
62
|
+
const asCode = params.lang || !file.endsWith(".md") && !file.endsWith(".mdx");
|
|
42
63
|
queue.push(
|
|
43
64
|
fs.readFile(targetPath).then((buffer) => buffer.toString()).then(async (content) => {
|
|
44
65
|
compiler?.addDependency(targetPath);
|
|
45
66
|
if (asCode) {
|
|
46
|
-
const lang = params.lang ?? path.extname(
|
|
67
|
+
const lang = params.lang ?? path.extname(file).slice(1);
|
|
47
68
|
Object.assign(node, {
|
|
48
69
|
type: "code",
|
|
49
70
|
lang,
|
|
50
71
|
meta: params.meta,
|
|
51
|
-
value: content
|
|
72
|
+
value: content,
|
|
52
73
|
data: {}
|
|
53
74
|
});
|
|
54
75
|
return;
|
|
55
76
|
}
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
let parsed = processor.parse(fumaMatter(content).content);
|
|
78
|
+
if (section) {
|
|
79
|
+
const extracted = extractSection(parsed, section);
|
|
80
|
+
if (!extracted)
|
|
81
|
+
throw new Error(
|
|
82
|
+
`Cannot find section ${section} in ${file}, make sure you have encapsulated the section in a <section id="${section}"> tag`
|
|
83
|
+
);
|
|
84
|
+
parsed = extracted;
|
|
85
|
+
}
|
|
86
|
+
await update(
|
|
87
|
+
parsed,
|
|
88
|
+
path.dirname(targetPath),
|
|
89
|
+
processor,
|
|
90
|
+
compiler
|
|
91
|
+
);
|
|
58
92
|
Object.assign(
|
|
59
93
|
parent && parent.type === "paragraph" ? parent : node,
|
|
60
94
|
parsed
|
|
@@ -62,7 +96,8 @@ function remarkInclude() {
|
|
|
62
96
|
}).catch((e) => {
|
|
63
97
|
throw new Error(
|
|
64
98
|
`failed to read file ${targetPath}
|
|
65
|
-
${e instanceof Error ? e.message : String(e)}
|
|
99
|
+
${e instanceof Error ? e.message : String(e)}`,
|
|
100
|
+
{ cause: e }
|
|
66
101
|
);
|
|
67
102
|
})
|
|
68
103
|
);
|
|
@@ -72,7 +107,7 @@ ${e instanceof Error ? e.message : String(e)}`
|
|
|
72
107
|
await Promise.all(queue);
|
|
73
108
|
}
|
|
74
109
|
return async (tree, file) => {
|
|
75
|
-
await update(tree, file.path, this, file.data._compiler);
|
|
110
|
+
await update(tree, path.dirname(file.path), this, file.data._compiler);
|
|
76
111
|
};
|
|
77
112
|
}
|
|
78
113
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/utils/git-timestamp.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { x } from "tinyexec";
|
|
4
|
+
var cache = /* @__PURE__ */ new Map();
|
|
5
|
+
async function getGitTimestamp(file) {
|
|
6
|
+
const cached = cache.get(file);
|
|
7
|
+
if (cached) return cached;
|
|
8
|
+
try {
|
|
9
|
+
const out = await x(
|
|
10
|
+
"git",
|
|
11
|
+
["log", "-1", '--pretty="%ai"', path.relative(process.cwd(), file)],
|
|
12
|
+
{
|
|
13
|
+
throwOnError: true
|
|
14
|
+
}
|
|
15
|
+
);
|
|
16
|
+
const time = new Date(out.stdout);
|
|
17
|
+
cache.set(file, time);
|
|
18
|
+
return time;
|
|
19
|
+
} catch {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
getGitTimestamp
|
|
26
|
+
};
|
package/dist/config/index.cjs
CHANGED
|
@@ -232,9 +232,29 @@ function flattenNode(node) {
|
|
|
232
232
|
if ("value" in node) return node.value;
|
|
233
233
|
return "";
|
|
234
234
|
}
|
|
235
|
+
function parseSpecifier(specifier) {
|
|
236
|
+
const idx = specifier.lastIndexOf("#");
|
|
237
|
+
if (idx === -1) return { file: specifier };
|
|
238
|
+
return {
|
|
239
|
+
file: specifier.slice(0, idx),
|
|
240
|
+
section: specifier.slice(idx + 1)
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function extractSection(root, section) {
|
|
244
|
+
for (const node of root.children) {
|
|
245
|
+
if (node.type === "mdxJsxFlowElement" && node.name === "section" && node.attributes.some(
|
|
246
|
+
(attr) => attr.type === "mdxJsxAttribute" && attr.name === "id" && attr.value === section
|
|
247
|
+
)) {
|
|
248
|
+
return {
|
|
249
|
+
type: "root",
|
|
250
|
+
children: node.children
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
235
255
|
function remarkInclude() {
|
|
236
256
|
const TagName = "include";
|
|
237
|
-
async function update(tree,
|
|
257
|
+
async function update(tree, directory, processor, compiler) {
|
|
238
258
|
const queue = [];
|
|
239
259
|
(0, import_unist_util_visit.visit)(
|
|
240
260
|
tree,
|
|
@@ -254,27 +274,41 @@ function remarkInclude() {
|
|
|
254
274
|
}
|
|
255
275
|
}
|
|
256
276
|
if (!specifier) return;
|
|
277
|
+
const { file, section } = parseSpecifier(specifier);
|
|
257
278
|
const targetPath = path.resolve(
|
|
258
|
-
"cwd" in params ? process.cwd() :
|
|
259
|
-
|
|
279
|
+
"cwd" in params ? process.cwd() : directory,
|
|
280
|
+
file
|
|
260
281
|
);
|
|
261
|
-
const asCode = params.lang || !
|
|
282
|
+
const asCode = params.lang || !file.endsWith(".md") && !file.endsWith(".mdx");
|
|
262
283
|
queue.push(
|
|
263
284
|
fs.readFile(targetPath).then((buffer) => buffer.toString()).then(async (content) => {
|
|
264
285
|
compiler?.addDependency(targetPath);
|
|
265
286
|
if (asCode) {
|
|
266
|
-
const lang = params.lang ?? path.extname(
|
|
287
|
+
const lang = params.lang ?? path.extname(file).slice(1);
|
|
267
288
|
Object.assign(node, {
|
|
268
289
|
type: "code",
|
|
269
290
|
lang,
|
|
270
291
|
meta: params.meta,
|
|
271
|
-
value: content
|
|
292
|
+
value: content,
|
|
272
293
|
data: {}
|
|
273
294
|
});
|
|
274
295
|
return;
|
|
275
296
|
}
|
|
276
|
-
|
|
277
|
-
|
|
297
|
+
let parsed = processor.parse(fumaMatter(content).content);
|
|
298
|
+
if (section) {
|
|
299
|
+
const extracted = extractSection(parsed, section);
|
|
300
|
+
if (!extracted)
|
|
301
|
+
throw new Error(
|
|
302
|
+
`Cannot find section ${section} in ${file}, make sure you have encapsulated the section in a <section id="${section}"> tag`
|
|
303
|
+
);
|
|
304
|
+
parsed = extracted;
|
|
305
|
+
}
|
|
306
|
+
await update(
|
|
307
|
+
parsed,
|
|
308
|
+
path.dirname(targetPath),
|
|
309
|
+
processor,
|
|
310
|
+
compiler
|
|
311
|
+
);
|
|
278
312
|
Object.assign(
|
|
279
313
|
parent && parent.type === "paragraph" ? parent : node,
|
|
280
314
|
parsed
|
|
@@ -282,7 +316,8 @@ function remarkInclude() {
|
|
|
282
316
|
}).catch((e) => {
|
|
283
317
|
throw new Error(
|
|
284
318
|
`failed to read file ${targetPath}
|
|
285
|
-
${e instanceof Error ? e.message : String(e)}
|
|
319
|
+
${e instanceof Error ? e.message : String(e)}`,
|
|
320
|
+
{ cause: e }
|
|
286
321
|
);
|
|
287
322
|
})
|
|
288
323
|
);
|
|
@@ -292,7 +327,7 @@ ${e instanceof Error ? e.message : String(e)}`
|
|
|
292
327
|
await Promise.all(queue);
|
|
293
328
|
}
|
|
294
329
|
return async (tree, file) => {
|
|
295
|
-
await update(tree, file.path, this, file.data._compiler);
|
|
330
|
+
await update(tree, path.dirname(file.path), this, file.data._compiler);
|
|
296
331
|
};
|
|
297
332
|
}
|
|
298
333
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/config/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AnyCollection, B as BaseCollection, C as CollectionSchema,
|
|
1
|
+
export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-E6TRBwBQ.cjs';
|
|
2
2
|
import { Processor, Transformer } from 'unified';
|
|
3
3
|
import { Root } from 'mdast';
|
|
4
4
|
import 'zod';
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AnyCollection, B as BaseCollection, C as CollectionSchema,
|
|
1
|
+
export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-E6TRBwBQ.js';
|
|
2
2
|
import { Processor, Transformer } from 'unified';
|
|
3
3
|
import { Root } from 'mdast';
|
|
4
4
|
import 'zod';
|
package/dist/config/index.js
CHANGED
|
@@ -106,4 +106,4 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
|
|
|
106
106
|
}): DocsCollection<DocSchema, MetaSchema, Async>;
|
|
107
107
|
declare function defineConfig(config?: GlobalConfig): GlobalConfig;
|
|
108
108
|
|
|
109
|
-
export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type
|
|
109
|
+
export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DefaultMDXOptions as D, type GlobalConfig as G, type MetaCollection as M, type DocCollection as a, type DocsCollection as b, defineDocs as c, defineCollections as d, defineConfig as e, frontmatterSchema as f, getDefaultMDXOptions as g, metaSchema as m };
|
|
@@ -106,4 +106,4 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
|
|
|
106
106
|
}): DocsCollection<DocSchema, MetaSchema, Async>;
|
|
107
107
|
declare function defineConfig(config?: GlobalConfig): GlobalConfig;
|
|
108
108
|
|
|
109
|
-
export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type
|
|
109
|
+
export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DefaultMDXOptions as D, type GlobalConfig as G, type MetaCollection as M, type DocCollection as a, type DocsCollection as b, defineDocs as c, defineCollections as d, defineConfig as e, frontmatterSchema as f, getDefaultMDXOptions as g, metaSchema as m };
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
|
|
2
|
-
import { R as Runtime, B as BaseCollectionEntry } from './types-
|
|
2
|
+
import { R as Runtime, B as BaseCollectionEntry } from './types-Lh_-Uuix.cjs';
|
|
3
3
|
import '@standard-schema/spec';
|
|
4
|
-
import './define-
|
|
4
|
+
import './define-E6TRBwBQ.cjs';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'fumadocs-core/mdx-plugins';
|
|
7
7
|
import '@mdx-js/mdx';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
|
|
2
|
-
import { R as Runtime, B as BaseCollectionEntry } from './types-
|
|
2
|
+
import { R as Runtime, B as BaseCollectionEntry } from './types-DiL328cG.js';
|
|
3
3
|
import '@standard-schema/spec';
|
|
4
|
-
import './define-
|
|
4
|
+
import './define-E6TRBwBQ.js';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'fumadocs-core/mdx-plugins';
|
|
7
7
|
import '@mdx-js/mdx';
|
package/dist/loader-mdx.cjs
CHANGED
|
@@ -175,7 +175,7 @@ var import_node_url = require("url");
|
|
|
175
175
|
// src/config/build.ts
|
|
176
176
|
function buildConfig(config) {
|
|
177
177
|
const collections = /* @__PURE__ */ new Map();
|
|
178
|
-
let globalConfig;
|
|
178
|
+
let globalConfig = {};
|
|
179
179
|
for (const [k, v] of Object.entries(config)) {
|
|
180
180
|
if (!v) {
|
|
181
181
|
continue;
|
|
@@ -190,34 +190,30 @@ function buildConfig(config) {
|
|
|
190
190
|
continue;
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
-
if (k === "default") {
|
|
193
|
+
if (k === "default" && v) {
|
|
194
194
|
globalConfig = v;
|
|
195
195
|
continue;
|
|
196
196
|
}
|
|
197
|
-
|
|
198
|
-
`Unknown export "${k}", you can only export collections from source configuration file
|
|
199
|
-
|
|
200
|
-
];
|
|
197
|
+
throw new Error(
|
|
198
|
+
`Unknown export "${k}", you can only export collections from source configuration file.`
|
|
199
|
+
);
|
|
201
200
|
}
|
|
202
201
|
let cachedMdxOptions;
|
|
203
|
-
return
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (options?.preset === "minimal") return options;
|
|
215
|
-
return getDefaultMDXOptions2(options ?? {});
|
|
216
|
-
}
|
|
217
|
-
return cachedMdxOptions = uncached();
|
|
202
|
+
return {
|
|
203
|
+
global: globalConfig,
|
|
204
|
+
collections,
|
|
205
|
+
async getDefaultMDXOptions() {
|
|
206
|
+
if (cachedMdxOptions) return cachedMdxOptions;
|
|
207
|
+
const input = this.global.mdxOptions;
|
|
208
|
+
async function uncached() {
|
|
209
|
+
const options = typeof input === "function" ? await input() : input;
|
|
210
|
+
const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
|
|
211
|
+
if (options?.preset === "minimal") return options;
|
|
212
|
+
return getDefaultMDXOptions2(options ?? {});
|
|
218
213
|
}
|
|
214
|
+
return cachedMdxOptions = uncached();
|
|
219
215
|
}
|
|
220
|
-
|
|
216
|
+
};
|
|
221
217
|
}
|
|
222
218
|
|
|
223
219
|
// src/utils/config.ts
|
|
@@ -249,12 +245,10 @@ async function loadConfig(configPath, outDir, hash, build = false) {
|
|
|
249
245
|
if (build) await compileConfig(configPath, outDir);
|
|
250
246
|
const url = (0, import_node_url.pathToFileURL)(path.resolve(outDir, "source.config.mjs"));
|
|
251
247
|
const config = import(`${url.href}?hash=${hash}`).then((loaded) => {
|
|
252
|
-
|
|
248
|
+
return buildConfig(
|
|
253
249
|
// every call to `loadConfig` will cause the previous cache to be ignored
|
|
254
250
|
loaded
|
|
255
251
|
);
|
|
256
|
-
if (err !== null) throw new Error(err);
|
|
257
|
-
return config2;
|
|
258
252
|
});
|
|
259
253
|
cache = { config, hash };
|
|
260
254
|
return await config;
|
|
@@ -298,9 +292,29 @@ function flattenNode(node) {
|
|
|
298
292
|
if ("value" in node) return node.value;
|
|
299
293
|
return "";
|
|
300
294
|
}
|
|
295
|
+
function parseSpecifier(specifier) {
|
|
296
|
+
const idx = specifier.lastIndexOf("#");
|
|
297
|
+
if (idx === -1) return { file: specifier };
|
|
298
|
+
return {
|
|
299
|
+
file: specifier.slice(0, idx),
|
|
300
|
+
section: specifier.slice(idx + 1)
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function extractSection(root, section) {
|
|
304
|
+
for (const node of root.children) {
|
|
305
|
+
if (node.type === "mdxJsxFlowElement" && node.name === "section" && node.attributes.some(
|
|
306
|
+
(attr) => attr.type === "mdxJsxAttribute" && attr.name === "id" && attr.value === section
|
|
307
|
+
)) {
|
|
308
|
+
return {
|
|
309
|
+
type: "root",
|
|
310
|
+
children: node.children
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
301
315
|
function remarkInclude() {
|
|
302
316
|
const TagName = "include";
|
|
303
|
-
async function update(tree,
|
|
317
|
+
async function update(tree, directory, processor, compiler) {
|
|
304
318
|
const queue = [];
|
|
305
319
|
(0, import_unist_util_visit.visit)(
|
|
306
320
|
tree,
|
|
@@ -320,27 +334,41 @@ function remarkInclude() {
|
|
|
320
334
|
}
|
|
321
335
|
}
|
|
322
336
|
if (!specifier) return;
|
|
337
|
+
const { file, section } = parseSpecifier(specifier);
|
|
323
338
|
const targetPath = path2.resolve(
|
|
324
|
-
"cwd" in params ? process.cwd() :
|
|
325
|
-
|
|
339
|
+
"cwd" in params ? process.cwd() : directory,
|
|
340
|
+
file
|
|
326
341
|
);
|
|
327
|
-
const asCode = params.lang || !
|
|
342
|
+
const asCode = params.lang || !file.endsWith(".md") && !file.endsWith(".mdx");
|
|
328
343
|
queue.push(
|
|
329
344
|
fs2.readFile(targetPath).then((buffer) => buffer.toString()).then(async (content) => {
|
|
330
345
|
compiler?.addDependency(targetPath);
|
|
331
346
|
if (asCode) {
|
|
332
|
-
const lang = params.lang ?? path2.extname(
|
|
347
|
+
const lang = params.lang ?? path2.extname(file).slice(1);
|
|
333
348
|
Object.assign(node, {
|
|
334
349
|
type: "code",
|
|
335
350
|
lang,
|
|
336
351
|
meta: params.meta,
|
|
337
|
-
value: content
|
|
352
|
+
value: content,
|
|
338
353
|
data: {}
|
|
339
354
|
});
|
|
340
355
|
return;
|
|
341
356
|
}
|
|
342
|
-
|
|
343
|
-
|
|
357
|
+
let parsed = processor.parse(fumaMatter(content).content);
|
|
358
|
+
if (section) {
|
|
359
|
+
const extracted = extractSection(parsed, section);
|
|
360
|
+
if (!extracted)
|
|
361
|
+
throw new Error(
|
|
362
|
+
`Cannot find section ${section} in ${file}, make sure you have encapsulated the section in a <section id="${section}"> tag`
|
|
363
|
+
);
|
|
364
|
+
parsed = extracted;
|
|
365
|
+
}
|
|
366
|
+
await update(
|
|
367
|
+
parsed,
|
|
368
|
+
path2.dirname(targetPath),
|
|
369
|
+
processor,
|
|
370
|
+
compiler
|
|
371
|
+
);
|
|
344
372
|
Object.assign(
|
|
345
373
|
parent && parent.type === "paragraph" ? parent : node,
|
|
346
374
|
parsed
|
|
@@ -348,7 +376,8 @@ function remarkInclude() {
|
|
|
348
376
|
}).catch((e) => {
|
|
349
377
|
throw new Error(
|
|
350
378
|
`failed to read file ${targetPath}
|
|
351
|
-
${e instanceof Error ? e.message : String(e)}
|
|
379
|
+
${e instanceof Error ? e.message : String(e)}`,
|
|
380
|
+
{ cause: e }
|
|
352
381
|
);
|
|
353
382
|
})
|
|
354
383
|
);
|
|
@@ -358,7 +387,7 @@ ${e instanceof Error ? e.message : String(e)}`
|
|
|
358
387
|
await Promise.all(queue);
|
|
359
388
|
}
|
|
360
389
|
return async (tree, file) => {
|
|
361
|
-
await update(tree, file.path, this, file.data._compiler);
|
|
390
|
+
await update(tree, path2.dirname(file.path), this, file.data._compiler);
|
|
362
391
|
};
|
|
363
392
|
}
|
|
364
393
|
|
package/dist/loader-mdx.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getConfigHash,
|
|
3
|
-
getGitTimestamp,
|
|
4
3
|
loadConfig
|
|
5
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-4CGSOZUZ.js";
|
|
6
5
|
import {
|
|
7
6
|
buildMDX,
|
|
8
7
|
countLines
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import
|
|
8
|
+
} from "./chunk-2K55VKP6.js";
|
|
9
|
+
import {
|
|
10
|
+
getGitTimestamp
|
|
11
|
+
} from "./chunk-VUEZTR2H.js";
|
|
11
12
|
import {
|
|
12
13
|
ValidationError,
|
|
13
14
|
validate
|
|
14
15
|
} from "./chunk-ZOWJF3OH.js";
|
|
15
|
-
import "./chunk-
|
|
16
|
+
import "./chunk-PQCNPAD3.js";
|
|
17
|
+
import "./chunk-JFNBRKRV.js";
|
|
16
18
|
import {
|
|
17
19
|
fumaMatter
|
|
18
20
|
} from "./chunk-KVWX6THC.js";
|