fumadocs-mdx 11.5.7 → 11.6.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/{chunk-KGLACICA.js → chunk-2ZOW45YZ.js} +25 -5
- package/dist/{chunk-SLCPEEMF.js → chunk-DRVUBK5B.js} +1 -4
- package/dist/{chunk-R6U7CJLB.js → chunk-HFLDWPJA.js} +1 -1
- package/dist/chunk-MK7EXW7O.js +75 -0
- package/dist/{chunk-IZURUUPO.js → chunk-VFALQK6O.js} +3 -9
- package/dist/config/index.cjs +47 -39
- package/dist/config/index.d.cts +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +2 -2
- package/dist/{define-P0QTVn7W.d.cts → define-BaW0PQDJ.d.cts} +2 -2
- package/dist/{define-P0QTVn7W.d.ts → define-BaW0PQDJ.d.ts} +2 -2
- package/dist/index.cjs +3 -9
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +1 -1
- package/dist/loader-mdx.cjs +72 -49
- package/dist/loader-mdx.js +5 -5
- package/dist/next/index.cjs +110 -108
- package/dist/next/index.js +89 -102
- package/dist/runtime/async.cjs +54 -56
- package/dist/runtime/async.d.cts +2 -2
- package/dist/runtime/async.d.ts +2 -2
- package/dist/runtime/async.js +9 -9
- package/dist/{types-CJRGJLAg.d.ts → types-BNrQHCj5.d.cts} +10 -10
- package/dist/{types-bWXuqsw9.d.cts → types-DEduCvIT.d.ts} +10 -10
- package/package.json +11 -9
- package/dist/chunk-ITGWT23S.js +0 -68
package/dist/runtime/async.cjs
CHANGED
|
@@ -35,7 +35,6 @@ __export(async_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(async_exports);
|
|
37
37
|
var import_mdx_remote = require("@fumadocs/mdx-remote");
|
|
38
|
-
var fs2 = __toESM(require("fs/promises"), 1);
|
|
39
38
|
|
|
40
39
|
// src/mdx-plugins/remark-include.ts
|
|
41
40
|
var import_unist_util_visit = require("unist-util-visit");
|
|
@@ -52,49 +51,56 @@ function remarkInclude() {
|
|
|
52
51
|
const TagName = "include";
|
|
53
52
|
async function update(tree, file, processor, compiler) {
|
|
54
53
|
const queue = [];
|
|
55
|
-
(0, import_unist_util_visit.visit)(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
(0, import_unist_util_visit.visit)(
|
|
55
|
+
tree,
|
|
56
|
+
["mdxJsxFlowElement", "mdxJsxTextElement"],
|
|
57
|
+
(node, _, parent) => {
|
|
58
|
+
let specifier;
|
|
59
|
+
const params = {};
|
|
60
|
+
if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
|
|
61
|
+
const value = flattenNode(node);
|
|
62
|
+
if (value.length > 0) {
|
|
63
|
+
for (const attr of node.attributes) {
|
|
64
|
+
if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
|
|
65
|
+
params[attr.name] = attr.value;
|
|
66
|
+
}
|
|
64
67
|
}
|
|
68
|
+
specifier = value;
|
|
65
69
|
}
|
|
66
|
-
specifier = value;
|
|
67
70
|
}
|
|
71
|
+
if (!specifier) return;
|
|
72
|
+
const targetPath = path.resolve(
|
|
73
|
+
"cwd" in params ? process.cwd() : path.dirname(file),
|
|
74
|
+
specifier
|
|
75
|
+
);
|
|
76
|
+
const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
|
|
77
|
+
queue.push(
|
|
78
|
+
fs.readFile(targetPath).then(async (content) => {
|
|
79
|
+
compiler?.addDependency(targetPath);
|
|
80
|
+
if (asCode) {
|
|
81
|
+
const lang = params.lang ?? path.extname(specifier).slice(1);
|
|
82
|
+
Object.assign(node, {
|
|
83
|
+
type: "code",
|
|
84
|
+
lang,
|
|
85
|
+
meta: params.meta,
|
|
86
|
+
value: content.toString(),
|
|
87
|
+
data: {}
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const parsed = processor.parse((0, import_gray_matter.default)(content).content);
|
|
92
|
+
await update(parsed, targetPath, processor, compiler);
|
|
93
|
+
Object.assign(
|
|
94
|
+
parent && parent.type === "paragraph" ? parent : node,
|
|
95
|
+
parsed
|
|
96
|
+
);
|
|
97
|
+
}).catch((e) => {
|
|
98
|
+
console.warn(`failed to read file: ${targetPath}`, e);
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
return "skip";
|
|
68
102
|
}
|
|
69
|
-
|
|
70
|
-
const targetPath = path.resolve(
|
|
71
|
-
"cwd" in params ? process.cwd() : path.dirname(file),
|
|
72
|
-
specifier
|
|
73
|
-
);
|
|
74
|
-
const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
|
|
75
|
-
queue.push(
|
|
76
|
-
fs.readFile(targetPath).then(async (content) => {
|
|
77
|
-
compiler?.addDependency(targetPath);
|
|
78
|
-
if (asCode) {
|
|
79
|
-
const lang = params.lang ?? path.extname(specifier).slice(1);
|
|
80
|
-
Object.assign(node, {
|
|
81
|
-
type: "code",
|
|
82
|
-
lang,
|
|
83
|
-
meta: params.meta,
|
|
84
|
-
value: content.toString(),
|
|
85
|
-
data: {}
|
|
86
|
-
});
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
const parsed = processor.parse((0, import_gray_matter.default)(content).content);
|
|
90
|
-
await update(parsed, targetPath, processor, compiler);
|
|
91
|
-
Object.assign(node, parsed);
|
|
92
|
-
}).catch((e) => {
|
|
93
|
-
console.warn(`failed to read file: ${targetPath}`, e);
|
|
94
|
-
})
|
|
95
|
-
);
|
|
96
|
-
return "skip";
|
|
97
|
-
});
|
|
103
|
+
);
|
|
98
104
|
await Promise.all(queue);
|
|
99
105
|
}
|
|
100
106
|
return async (tree, file) => {
|
|
@@ -141,21 +147,15 @@ var _runtime = {
|
|
|
141
147
|
};
|
|
142
148
|
function createMDXSource(docs, meta = []) {
|
|
143
149
|
return {
|
|
144
|
-
files: (
|
|
150
|
+
files: () => resolveFiles({
|
|
145
151
|
docs,
|
|
146
|
-
meta
|
|
147
|
-
rootDir
|
|
152
|
+
meta
|
|
148
153
|
})
|
|
149
154
|
};
|
|
150
155
|
}
|
|
151
|
-
function resolveFiles({
|
|
152
|
-
docs,
|
|
153
|
-
meta,
|
|
154
|
-
rootDir = ""
|
|
155
|
-
}) {
|
|
156
|
+
function resolveFiles({ docs, meta }) {
|
|
156
157
|
const outputs = [];
|
|
157
158
|
for (const entry of docs) {
|
|
158
|
-
if (!entry._file.path.startsWith(rootDir)) continue;
|
|
159
159
|
outputs.push({
|
|
160
160
|
type: "page",
|
|
161
161
|
path: entry._file.path,
|
|
@@ -203,10 +203,7 @@ function buildConfig(config) {
|
|
|
203
203
|
null,
|
|
204
204
|
{
|
|
205
205
|
global: globalConfig,
|
|
206
|
-
collections
|
|
207
|
-
_runtime: {
|
|
208
|
-
files: /* @__PURE__ */ new Map()
|
|
209
|
-
}
|
|
206
|
+
collections
|
|
210
207
|
}
|
|
211
208
|
];
|
|
212
209
|
}
|
|
@@ -232,14 +229,15 @@ async function initCompiler(config, collection) {
|
|
|
232
229
|
var _runtimeAsync = {
|
|
233
230
|
doc(files, collection, config) {
|
|
234
231
|
const init = initCompiler(config, collection);
|
|
235
|
-
return files.map(({ info: file, data
|
|
232
|
+
return files.map(({ info: file, data, content }) => {
|
|
236
233
|
return {
|
|
237
|
-
...
|
|
234
|
+
...data,
|
|
238
235
|
_file: file,
|
|
236
|
+
content,
|
|
239
237
|
async load() {
|
|
240
238
|
const compiler = await init;
|
|
241
239
|
const out = await compiler.compile({
|
|
242
|
-
source:
|
|
240
|
+
source: content,
|
|
243
241
|
filePath: file.absolutePath
|
|
244
242
|
});
|
|
245
243
|
return {
|
package/dist/runtime/async.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LoadedConfig,
|
|
2
|
-
import '../define-
|
|
1
|
+
import { L as LoadedConfig, a as RuntimeAsync } from '../types-BNrQHCj5.cjs';
|
|
2
|
+
import '../define-BaW0PQDJ.cjs';
|
|
3
3
|
import '@mdx-js/mdx';
|
|
4
4
|
import 'mdx/types';
|
|
5
5
|
import 'fumadocs-core/mdx-plugins';
|
package/dist/runtime/async.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LoadedConfig,
|
|
2
|
-
import '../define-
|
|
1
|
+
import { L as LoadedConfig, a as RuntimeAsync } from '../types-DEduCvIT.js';
|
|
2
|
+
import '../define-BaW0PQDJ.js';
|
|
3
3
|
import '@mdx-js/mdx';
|
|
4
4
|
import 'mdx/types';
|
|
5
5
|
import 'fumadocs-core/mdx-plugins';
|
package/dist/runtime/async.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
_runtime,
|
|
3
3
|
createMDXSource
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import {
|
|
6
|
-
remarkInclude
|
|
7
|
-
} from "../chunk-ITGWT23S.js";
|
|
4
|
+
} from "../chunk-VFALQK6O.js";
|
|
8
5
|
import {
|
|
9
6
|
buildConfig
|
|
10
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-DRVUBK5B.js";
|
|
8
|
+
import {
|
|
9
|
+
remarkInclude
|
|
10
|
+
} from "../chunk-MK7EXW7O.js";
|
|
11
11
|
|
|
12
12
|
// src/runtime/async.ts
|
|
13
13
|
import { createCompiler } from "@fumadocs/mdx-remote";
|
|
14
|
-
import * as fs from "node:fs/promises";
|
|
15
14
|
import {
|
|
16
15
|
remarkStructure
|
|
17
16
|
} from "fumadocs-core/mdx-plugins";
|
|
@@ -35,14 +34,15 @@ async function initCompiler(config, collection) {
|
|
|
35
34
|
var _runtimeAsync = {
|
|
36
35
|
doc(files, collection, config) {
|
|
37
36
|
const init = initCompiler(config, collection);
|
|
38
|
-
return files.map(({ info: file, data
|
|
37
|
+
return files.map(({ info: file, data, content }) => {
|
|
39
38
|
return {
|
|
40
|
-
...
|
|
39
|
+
...data,
|
|
41
40
|
_file: file,
|
|
41
|
+
content,
|
|
42
42
|
async load() {
|
|
43
43
|
const compiler = await init;
|
|
44
44
|
const out = await compiler.compile({
|
|
45
|
-
source:
|
|
45
|
+
source: content,
|
|
46
46
|
filePath: file.absolutePath
|
|
47
47
|
});
|
|
48
48
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as DocCollection,
|
|
1
|
+
import { D as DocCollection, M as MetaCollection, a as DocsCollection, G as GlobalConfig, F as FileInfo, b as MarkdownProps, B as BaseCollectionEntry } from './define-BaW0PQDJ.cjs';
|
|
2
2
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
3
|
import { Source, PageData, MetaData } from 'fumadocs-core/source';
|
|
4
4
|
import { ProcessorOptions } from '@mdx-js/mdx';
|
|
@@ -7,12 +7,6 @@ import { MDXOptions } from '@fumadocs/mdx-remote';
|
|
|
7
7
|
interface LoadedConfig {
|
|
8
8
|
collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
|
|
9
9
|
global?: GlobalConfig;
|
|
10
|
-
_runtime: {
|
|
11
|
-
/**
|
|
12
|
-
* Absolute file path and their associated collections
|
|
13
|
-
*/
|
|
14
|
-
files: Map<string, string>;
|
|
15
|
-
};
|
|
16
10
|
_mdx_loader?: {
|
|
17
11
|
cachedProcessorOptions?: ProcessorOptions;
|
|
18
12
|
};
|
|
@@ -25,6 +19,11 @@ interface RuntimeFile {
|
|
|
25
19
|
info: FileInfo;
|
|
26
20
|
data: Record<string, unknown>;
|
|
27
21
|
}
|
|
22
|
+
interface AsyncRuntimeFile {
|
|
23
|
+
info: FileInfo;
|
|
24
|
+
data: Record<string, unknown>;
|
|
25
|
+
content: string;
|
|
26
|
+
}
|
|
28
27
|
type DocOut<Schema extends StandardSchemaV1> = Omit<MarkdownProps, keyof StandardSchemaV1.InferOutput<Schema>> & StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry;
|
|
29
28
|
type MetaOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry;
|
|
30
29
|
interface Runtime {
|
|
@@ -64,16 +63,17 @@ interface Runtime {
|
|
|
64
63
|
} : never;
|
|
65
64
|
}
|
|
66
65
|
type AsyncDocOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry & {
|
|
66
|
+
content: string;
|
|
67
67
|
load: () => Promise<MarkdownProps>;
|
|
68
68
|
};
|
|
69
69
|
interface RuntimeAsync {
|
|
70
|
-
doc: <C>(files:
|
|
70
|
+
doc: <C>(files: AsyncRuntimeFile[], collection: string, config: LoadedConfig) => C extends {
|
|
71
71
|
type: 'doc';
|
|
72
72
|
_type: {
|
|
73
73
|
schema: infer Schema extends StandardSchemaV1;
|
|
74
74
|
};
|
|
75
75
|
} ? AsyncDocOut<Schema>[] : never;
|
|
76
|
-
docs: <C>(docs:
|
|
76
|
+
docs: <C>(docs: AsyncRuntimeFile[], metas: RuntimeFile[], collection: string, config: LoadedConfig) => C extends {
|
|
77
77
|
type: 'docs';
|
|
78
78
|
docs: {
|
|
79
79
|
type: 'doc';
|
|
@@ -97,4 +97,4 @@ interface RuntimeAsync {
|
|
|
97
97
|
} : never;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
export type { LoadedConfig as L, Runtime as R,
|
|
100
|
+
export type { LoadedConfig as L, Runtime as R, RuntimeAsync as a };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as DocCollection,
|
|
1
|
+
import { D as DocCollection, M as MetaCollection, a as DocsCollection, G as GlobalConfig, F as FileInfo, b as MarkdownProps, B as BaseCollectionEntry } from './define-BaW0PQDJ.js';
|
|
2
2
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
3
|
import { Source, PageData, MetaData } from 'fumadocs-core/source';
|
|
4
4
|
import { ProcessorOptions } from '@mdx-js/mdx';
|
|
@@ -7,12 +7,6 @@ import { MDXOptions } from '@fumadocs/mdx-remote';
|
|
|
7
7
|
interface LoadedConfig {
|
|
8
8
|
collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
|
|
9
9
|
global?: GlobalConfig;
|
|
10
|
-
_runtime: {
|
|
11
|
-
/**
|
|
12
|
-
* Absolute file path and their associated collections
|
|
13
|
-
*/
|
|
14
|
-
files: Map<string, string>;
|
|
15
|
-
};
|
|
16
10
|
_mdx_loader?: {
|
|
17
11
|
cachedProcessorOptions?: ProcessorOptions;
|
|
18
12
|
};
|
|
@@ -25,6 +19,11 @@ interface RuntimeFile {
|
|
|
25
19
|
info: FileInfo;
|
|
26
20
|
data: Record<string, unknown>;
|
|
27
21
|
}
|
|
22
|
+
interface AsyncRuntimeFile {
|
|
23
|
+
info: FileInfo;
|
|
24
|
+
data: Record<string, unknown>;
|
|
25
|
+
content: string;
|
|
26
|
+
}
|
|
28
27
|
type DocOut<Schema extends StandardSchemaV1> = Omit<MarkdownProps, keyof StandardSchemaV1.InferOutput<Schema>> & StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry;
|
|
29
28
|
type MetaOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry;
|
|
30
29
|
interface Runtime {
|
|
@@ -64,16 +63,17 @@ interface Runtime {
|
|
|
64
63
|
} : never;
|
|
65
64
|
}
|
|
66
65
|
type AsyncDocOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry & {
|
|
66
|
+
content: string;
|
|
67
67
|
load: () => Promise<MarkdownProps>;
|
|
68
68
|
};
|
|
69
69
|
interface RuntimeAsync {
|
|
70
|
-
doc: <C>(files:
|
|
70
|
+
doc: <C>(files: AsyncRuntimeFile[], collection: string, config: LoadedConfig) => C extends {
|
|
71
71
|
type: 'doc';
|
|
72
72
|
_type: {
|
|
73
73
|
schema: infer Schema extends StandardSchemaV1;
|
|
74
74
|
};
|
|
75
75
|
} ? AsyncDocOut<Schema>[] : never;
|
|
76
|
-
docs: <C>(docs:
|
|
76
|
+
docs: <C>(docs: AsyncRuntimeFile[], metas: RuntimeFile[], collection: string, config: LoadedConfig) => C extends {
|
|
77
77
|
type: 'docs';
|
|
78
78
|
docs: {
|
|
79
79
|
type: 'doc';
|
|
@@ -97,4 +97,4 @@ interface RuntimeAsync {
|
|
|
97
97
|
} : never;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
export type { LoadedConfig as L, Runtime as R,
|
|
100
|
+
export type { LoadedConfig as L, Runtime as R, RuntimeAsync as a };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-mdx",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.6.0",
|
|
4
4
|
"description": "The built-in source for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -46,10 +46,12 @@
|
|
|
46
46
|
"@standard-schema/spec": "^1.0.0",
|
|
47
47
|
"chokidar": "^4.0.3",
|
|
48
48
|
"cross-spawn": "^7.0.6",
|
|
49
|
-
"esbuild": "^0.25.
|
|
50
|
-
"estree-util-value-to-estree": "^3.3.
|
|
49
|
+
"esbuild": "^0.25.2",
|
|
50
|
+
"estree-util-value-to-estree": "^3.3.3",
|
|
51
51
|
"fast-glob": "^3.3.3",
|
|
52
52
|
"gray-matter": "^4.0.3",
|
|
53
|
+
"lru-cache": "^11.1.0",
|
|
54
|
+
"picocolors": "^1.1.1",
|
|
53
55
|
"unist-util-visit": "^5.0.0",
|
|
54
56
|
"zod": "^3.24.2"
|
|
55
57
|
},
|
|
@@ -57,21 +59,21 @@
|
|
|
57
59
|
"@types/cross-spawn": "^6.0.6",
|
|
58
60
|
"@types/mdast": "^4.0.3",
|
|
59
61
|
"@types/mdx": "^2.0.13",
|
|
60
|
-
"@types/react": "^19.0
|
|
62
|
+
"@types/react": "^19.1.0",
|
|
61
63
|
"mdast-util-mdx-jsx": "^3.2.0",
|
|
62
|
-
"next": "^15.
|
|
64
|
+
"next": "^15.3.0",
|
|
63
65
|
"unified": "^11.0.5",
|
|
64
66
|
"vfile": "^6.0.3",
|
|
65
|
-
"webpack": "^5.
|
|
66
|
-
"@fumadocs/mdx-remote": "1.
|
|
67
|
+
"webpack": "^5.99.5",
|
|
68
|
+
"@fumadocs/mdx-remote": "1.3.0",
|
|
67
69
|
"eslint-config-custom": "0.0.0",
|
|
68
|
-
"fumadocs-core": "15.
|
|
70
|
+
"fumadocs-core": "15.2.7",
|
|
69
71
|
"tsconfig": "0.0.0"
|
|
70
72
|
},
|
|
71
73
|
"peerDependencies": {
|
|
72
74
|
"@fumadocs/mdx-remote": "^1.2.0",
|
|
73
75
|
"fumadocs-core": "^14.0.0 || ^15.0.0",
|
|
74
|
-
"next": "
|
|
76
|
+
"next": "^15.3.0"
|
|
75
77
|
},
|
|
76
78
|
"peerDependenciesMeta": {
|
|
77
79
|
"@fumadocs/mdx-remote": {
|
package/dist/chunk-ITGWT23S.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// src/mdx-plugins/remark-include.ts
|
|
2
|
-
import { visit } from "unist-util-visit";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
import * as fs from "node:fs/promises";
|
|
5
|
-
import matter from "gray-matter";
|
|
6
|
-
function flattenNode(node) {
|
|
7
|
-
if ("children" in node)
|
|
8
|
-
return node.children.map((child) => flattenNode(child)).join("");
|
|
9
|
-
if ("value" in node) return node.value;
|
|
10
|
-
return "";
|
|
11
|
-
}
|
|
12
|
-
function remarkInclude() {
|
|
13
|
-
const TagName = "include";
|
|
14
|
-
async function update(tree, file, processor, compiler) {
|
|
15
|
-
const queue = [];
|
|
16
|
-
visit(tree, ["mdxJsxFlowElement", "mdxJsxTextElement"], (node) => {
|
|
17
|
-
let specifier;
|
|
18
|
-
const params = {};
|
|
19
|
-
if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
|
|
20
|
-
const value = flattenNode(node);
|
|
21
|
-
if (value.length > 0) {
|
|
22
|
-
for (const attr of node.attributes) {
|
|
23
|
-
if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
|
|
24
|
-
params[attr.name] = attr.value;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
specifier = value;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (!specifier) return;
|
|
31
|
-
const targetPath = path.resolve(
|
|
32
|
-
"cwd" in params ? process.cwd() : path.dirname(file),
|
|
33
|
-
specifier
|
|
34
|
-
);
|
|
35
|
-
const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
|
|
36
|
-
queue.push(
|
|
37
|
-
fs.readFile(targetPath).then(async (content) => {
|
|
38
|
-
compiler?.addDependency(targetPath);
|
|
39
|
-
if (asCode) {
|
|
40
|
-
const lang = params.lang ?? path.extname(specifier).slice(1);
|
|
41
|
-
Object.assign(node, {
|
|
42
|
-
type: "code",
|
|
43
|
-
lang,
|
|
44
|
-
meta: params.meta,
|
|
45
|
-
value: content.toString(),
|
|
46
|
-
data: {}
|
|
47
|
-
});
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const parsed = processor.parse(matter(content).content);
|
|
51
|
-
await update(parsed, targetPath, processor, compiler);
|
|
52
|
-
Object.assign(node, parsed);
|
|
53
|
-
}).catch((e) => {
|
|
54
|
-
console.warn(`failed to read file: ${targetPath}`, e);
|
|
55
|
-
})
|
|
56
|
-
);
|
|
57
|
-
return "skip";
|
|
58
|
-
});
|
|
59
|
-
await Promise.all(queue);
|
|
60
|
-
}
|
|
61
|
-
return async (tree, file) => {
|
|
62
|
-
await update(tree, file.path, this, file.data._compiler);
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export {
|
|
67
|
-
remarkInclude
|
|
68
|
-
};
|