@hanzo/docs-mdx 14.1.1 → 14.2.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/adapter-Jwap8N8Y.js +144 -0
- package/dist/adapter-Jwap8N8Y.js.map +1 -0
- package/dist/bin.d.ts +1 -1
- package/dist/bin.js +21 -12
- package/dist/bin.js.map +1 -0
- package/dist/build-DP5xMGSd.js +100 -0
- package/dist/build-DP5xMGSd.js.map +1 -0
- package/dist/build-mdx-B0MQbgVM.js +5 -0
- package/dist/build-mdx-CNzC71ea.js +153 -0
- package/dist/build-mdx-CNzC71ea.js.map +1 -0
- package/dist/build-mdx-DyJk_jWV.d.ts +53 -0
- package/dist/build-mdx-DyJk_jWV.d.ts.map +1 -0
- package/dist/bun/index.d.ts +10 -21
- package/dist/bun/index.d.ts.map +1 -0
- package/dist/bun/index.js +30 -49
- package/dist/bun/index.js.map +1 -0
- package/dist/codegen-DleOVLNr.js +101 -0
- package/dist/codegen-DleOVLNr.js.map +1 -0
- package/dist/config/index.d.ts +2 -18
- package/dist/config/index.js +50 -53
- package/dist/config/index.js.map +1 -0
- package/dist/core-BJualF84.js +212 -0
- package/dist/core-BJualF84.js.map +1 -0
- package/dist/core-D2BJuXMW.d.ts +364 -0
- package/dist/core-D2BJuXMW.d.ts.map +1 -0
- package/dist/fuma-matter-CHgJa_-B.js +27 -0
- package/dist/fuma-matter-CHgJa_-B.js.map +1 -0
- package/dist/index-Bc_4I1HE.d.ts +12 -0
- package/dist/index-Bc_4I1HE.d.ts.map +1 -0
- package/dist/index-file-Bil6OoJJ.js +264 -0
- package/dist/index-file-Bil6OoJJ.js.map +1 -0
- package/dist/index.d.ts +3 -61
- package/dist/index.js +1 -0
- package/dist/load-from-file-BD2SdoUT.js +5 -0
- package/dist/load-from-file-CSjo1gN1.js +38 -0
- package/dist/load-from-file-CSjo1gN1.js.map +1 -0
- package/dist/loaders-BVwYfelL.js +7 -0
- package/dist/loaders-BVwYfelL.js.map +1 -0
- package/dist/mdx-QPp-1kXt.js +91 -0
- package/dist/mdx-QPp-1kXt.js.map +1 -0
- package/dist/meta-DyieTM4Z.js +81 -0
- package/dist/meta-DyieTM4Z.js.map +1 -0
- package/dist/next/index.cjs +863 -1076
- package/dist/next/index.d.ts +17 -28
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/index.js +141 -170
- package/dist/next/index.js.map +1 -0
- package/dist/node/loader.d.ts +4 -2
- package/dist/node/loader.d.ts.map +1 -0
- package/dist/node/loader.js +26 -38
- package/dist/node/loader.js.map +1 -0
- package/dist/plugins/index-file.d.ts +2 -14
- package/dist/plugins/index-file.js +5 -8
- package/dist/plugins/json-schema.d.ts +14 -23
- package/dist/plugins/json-schema.d.ts.map +1 -0
- package/dist/plugins/json-schema.js +70 -78
- package/dist/plugins/json-schema.js.map +1 -0
- package/dist/plugins/last-modified.d.ts +21 -32
- package/dist/plugins/last-modified.d.ts.map +1 -0
- package/dist/plugins/last-modified.js +70 -78
- package/dist/plugins/last-modified.js.map +1 -0
- package/dist/preset-DtKimtBh.js +61 -0
- package/dist/preset-DtKimtBh.js.map +1 -0
- package/dist/remark-include-DirFkbLw.js +247 -0
- package/dist/remark-include-DirFkbLw.js.map +1 -0
- package/dist/runtime/browser.d.ts +32 -41
- package/dist/runtime/browser.d.ts.map +1 -0
- package/dist/runtime/browser.js +56 -63
- package/dist/runtime/browser.js.map +1 -0
- package/dist/runtime/dynamic.d.ts +13 -21
- package/dist/runtime/dynamic.d.ts.map +1 -0
- package/dist/runtime/dynamic.js +64 -76
- package/dist/runtime/dynamic.js.map +1 -0
- package/dist/runtime/server.d.ts +2 -14
- package/dist/runtime/server.js +111 -8
- package/dist/runtime/server.js.map +1 -0
- package/dist/runtime/types.d.ts +2 -61
- package/dist/runtime/types.js +1 -0
- package/dist/types-CBMeukTI.d.ts +63 -0
- package/dist/types-CBMeukTI.d.ts.map +1 -0
- package/dist/vite/index.d.ts +28 -39
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +79 -114
- package/dist/vite/index.js.map +1 -0
- package/dist/webpack/mdx.d.ts +6 -3
- package/dist/webpack/mdx.d.ts.map +1 -0
- package/dist/webpack/mdx.js +21 -34
- package/dist/webpack/mdx.js.map +1 -0
- package/dist/webpack/meta.d.ts +6 -3
- package/dist/webpack/meta.d.ts.map +1 -0
- package/dist/webpack/meta.js +23 -37
- package/dist/webpack/meta.js.map +1 -0
- package/dist/webpack-DKHWtYK4.js +15 -0
- package/dist/webpack-DKHWtYK4.js.map +1 -0
- package/loader-mdx.cjs +1 -3
- package/loader-meta.cjs +1 -3
- package/package.json +50 -50
- package/dist/build-mdx-LN7FEKIP.js +0 -8
- package/dist/build-mdx-RXJZQXGA.js +0 -8
- package/dist/chunk-4JSFLXXT.js +0 -8
- package/dist/chunk-5OBUOALK.js +0 -141
- package/dist/chunk-72JS4QVZ.js +0 -17
- package/dist/chunk-7I4W7XGI.js +0 -179
- package/dist/chunk-7W73RILB.js +0 -173
- package/dist/chunk-A3YIGE7S.js +0 -334
- package/dist/chunk-AOTZP2TV.js +0 -152
- package/dist/chunk-AXJB5MGS.js +0 -173
- package/dist/chunk-DMIIE3XZ.js +0 -179
- package/dist/chunk-DTFUANSF.js +0 -40
- package/dist/chunk-JWZR25CW.js +0 -116
- package/dist/chunk-K7N6GD4M.js +0 -17
- package/dist/chunk-LXB7WYAF.js +0 -334
- package/dist/chunk-MYAVS2LD.js +0 -116
- package/dist/chunk-OLD35ARB.js +0 -116
- package/dist/chunk-PW2AZGGD.js +0 -125
- package/dist/chunk-RGBNABKS.js +0 -334
- package/dist/chunk-RPUM7REY.js +0 -40
- package/dist/chunk-RR2X6AE6.js +0 -274
- package/dist/chunk-S7KOJHHO.js +0 -89
- package/dist/chunk-STUCUTJQ.js +0 -334
- package/dist/chunk-T6G5VOED.js +0 -116
- package/dist/chunk-U5YPLCO5.js +0 -89
- package/dist/chunk-UB55AMXC.js +0 -274
- package/dist/chunk-VITVHHR6.js +0 -334
- package/dist/chunk-VKSHE52K.js +0 -274
- package/dist/chunk-VWJKRQZR.js +0 -19
- package/dist/chunk-WAAWFNDX.js +0 -179
- package/dist/chunk-WGXYJGSZ.js +0 -141
- package/dist/chunk-WLJ6EKOZ.js +0 -17
- package/dist/chunk-WMYYALAS.js +0 -334
- package/dist/chunk-Y7ISNZ7X.js +0 -216
- package/dist/chunk-YKRCQ42E.js +0 -216
- package/dist/chunk-ZAYZWFWP.js +0 -89
- package/dist/core-BQcKaqmC.d.ts +0 -350
- package/dist/core-BhWOtait.d.ts +0 -350
- package/dist/core-CV8uFMUa.d.ts +0 -350
- package/dist/core-DAQ64Hkq.d.ts +0 -350
- package/dist/core-DZtRjhds.d.ts +0 -350
- package/dist/core-De5K4ixv.d.ts +0 -350
- package/dist/core-X5ggQtBM.d.ts +0 -350
- package/dist/index-BqkSNsGO.d.ts +0 -8
- package/dist/load-from-file-FHW724YY.js +0 -8
- package/dist/load-from-file-S5CQ4H6T.js +0 -8
package/dist/chunk-5OBUOALK.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
// src/runtime/server.ts
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
function server(options = {}) {
|
|
4
|
-
const { doc: { passthroughs: docPassthroughs = [] } = {} } = options;
|
|
5
|
-
function fileInfo(file, base) {
|
|
6
|
-
if (file.startsWith("./")) {
|
|
7
|
-
file = file.slice(2);
|
|
8
|
-
}
|
|
9
|
-
return {
|
|
10
|
-
path: file,
|
|
11
|
-
fullPath: path.join(base, file)
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
function mapDocData(entry) {
|
|
15
|
-
const data = {
|
|
16
|
-
body: entry.default,
|
|
17
|
-
toc: entry.toc,
|
|
18
|
-
structuredData: entry.structuredData,
|
|
19
|
-
_exports: entry
|
|
20
|
-
};
|
|
21
|
-
for (const key of docPassthroughs) {
|
|
22
|
-
data[key] = entry[key];
|
|
23
|
-
}
|
|
24
|
-
return data;
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
async doc(_name, base, glob) {
|
|
28
|
-
const out = await Promise.all(
|
|
29
|
-
Object.entries(glob).map(async ([k, v]) => {
|
|
30
|
-
const data = typeof v === "function" ? await v() : v;
|
|
31
|
-
return {
|
|
32
|
-
...mapDocData(data),
|
|
33
|
-
...data.frontmatter,
|
|
34
|
-
...createDocMethods(fileInfo(k, base), () => data)
|
|
35
|
-
};
|
|
36
|
-
})
|
|
37
|
-
);
|
|
38
|
-
return out;
|
|
39
|
-
},
|
|
40
|
-
async docLazy(_name, base, head, body) {
|
|
41
|
-
const out = await Promise.all(
|
|
42
|
-
Object.entries(head).map(async ([k, v]) => {
|
|
43
|
-
const data = typeof v === "function" ? await v() : v;
|
|
44
|
-
const content = body[k];
|
|
45
|
-
return {
|
|
46
|
-
...data,
|
|
47
|
-
...createDocMethods(fileInfo(k, base), content),
|
|
48
|
-
async load() {
|
|
49
|
-
return mapDocData(await content());
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
})
|
|
53
|
-
);
|
|
54
|
-
return out;
|
|
55
|
-
},
|
|
56
|
-
async meta(_name, base, glob) {
|
|
57
|
-
const out = await Promise.all(
|
|
58
|
-
Object.entries(glob).map(async ([k, v]) => {
|
|
59
|
-
const data = typeof v === "function" ? await v() : v;
|
|
60
|
-
return {
|
|
61
|
-
info: fileInfo(k, base),
|
|
62
|
-
...data
|
|
63
|
-
};
|
|
64
|
-
})
|
|
65
|
-
);
|
|
66
|
-
return out;
|
|
67
|
-
},
|
|
68
|
-
async docs(name, base, metaGlob, docGlob) {
|
|
69
|
-
const entry = {
|
|
70
|
-
docs: await this.doc(name, base, docGlob),
|
|
71
|
-
meta: await this.meta(name, base, metaGlob),
|
|
72
|
-
toFumadocsSource() {
|
|
73
|
-
return toFumadocsSource(this.docs, this.meta);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
return entry;
|
|
77
|
-
},
|
|
78
|
-
async docsLazy(name, base, metaGlob, docHeadGlob, docBodyGlob) {
|
|
79
|
-
const entry = {
|
|
80
|
-
docs: await this.docLazy(name, base, docHeadGlob, docBodyGlob),
|
|
81
|
-
meta: await this.meta(name, base, metaGlob),
|
|
82
|
-
toFumadocsSource() {
|
|
83
|
-
return toFumadocsSource(this.docs, this.meta);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
return entry;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function toFumadocsSource(pages, metas) {
|
|
91
|
-
const files = [];
|
|
92
|
-
for (const entry of pages) {
|
|
93
|
-
files.push({
|
|
94
|
-
type: "page",
|
|
95
|
-
path: entry.info.path,
|
|
96
|
-
absolutePath: entry.info.fullPath,
|
|
97
|
-
data: entry
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
for (const entry of metas) {
|
|
101
|
-
files.push({
|
|
102
|
-
type: "meta",
|
|
103
|
-
path: entry.info.path,
|
|
104
|
-
absolutePath: entry.info.fullPath,
|
|
105
|
-
data: entry
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
files
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function createDocMethods(info, load) {
|
|
113
|
-
return {
|
|
114
|
-
info,
|
|
115
|
-
async getText(type) {
|
|
116
|
-
if (type === "raw") {
|
|
117
|
-
const fs = await import("fs/promises");
|
|
118
|
-
return (await fs.readFile(info.fullPath)).toString();
|
|
119
|
-
}
|
|
120
|
-
const data = await load();
|
|
121
|
-
if (typeof data._markdown !== "string")
|
|
122
|
-
throw new Error(
|
|
123
|
-
"getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
|
|
124
|
-
);
|
|
125
|
-
return data._markdown;
|
|
126
|
-
},
|
|
127
|
-
async getMDAST() {
|
|
128
|
-
const data = await load();
|
|
129
|
-
if (!data._mdast)
|
|
130
|
-
throw new Error(
|
|
131
|
-
"getMDAST() requires `includeMDAST` to be enabled in your collection config."
|
|
132
|
-
);
|
|
133
|
-
return JSON.parse(data._mdast);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export {
|
|
139
|
-
server,
|
|
140
|
-
toFumadocsSource
|
|
141
|
-
};
|
package/dist/chunk-72JS4QVZ.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createCore
|
|
3
|
-
} from "./chunk-UB55AMXC.js";
|
|
4
|
-
|
|
5
|
-
// src/webpack/index.ts
|
|
6
|
-
var core;
|
|
7
|
-
function getCore(options) {
|
|
8
|
-
return core ??= createCore({
|
|
9
|
-
environment: "webpack",
|
|
10
|
-
outDir: options.outDir,
|
|
11
|
-
configPath: options.configPath
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
getCore
|
|
17
|
-
};
|
package/dist/chunk-7I4W7XGI.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ValidationError
|
|
3
|
-
} from "./chunk-UB55AMXC.js";
|
|
4
|
-
|
|
5
|
-
// src/loaders/adapter.ts
|
|
6
|
-
import { fileURLToPath } from "url";
|
|
7
|
-
import fs from "fs/promises";
|
|
8
|
-
import { parse } from "querystring";
|
|
9
|
-
import path from "path";
|
|
10
|
-
import { readFileSync } from "fs";
|
|
11
|
-
function toNode(loader) {
|
|
12
|
-
return async (url, _context, nextLoad) => {
|
|
13
|
-
if (url.startsWith("file:///") && (!loader.test || loader.test.test(url))) {
|
|
14
|
-
const parsedUrl = new URL(url);
|
|
15
|
-
const filePath = fileURLToPath(parsedUrl);
|
|
16
|
-
const result = await loader.load({
|
|
17
|
-
filePath,
|
|
18
|
-
query: Object.fromEntries(parsedUrl.searchParams.entries()),
|
|
19
|
-
async getSource() {
|
|
20
|
-
return (await fs.readFile(filePath)).toString();
|
|
21
|
-
},
|
|
22
|
-
development: false,
|
|
23
|
-
compiler: {
|
|
24
|
-
addDependency() {
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
if (result) {
|
|
29
|
-
return {
|
|
30
|
-
source: result.code,
|
|
31
|
-
format: "module",
|
|
32
|
-
shortCircuit: true
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return nextLoad(url);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function toVite(loader) {
|
|
40
|
-
return {
|
|
41
|
-
filter(id) {
|
|
42
|
-
return !loader.test || loader.test.test(id);
|
|
43
|
-
},
|
|
44
|
-
async transform(value, id) {
|
|
45
|
-
const [file, query = ""] = id.split("?", 2);
|
|
46
|
-
const result = await loader.load({
|
|
47
|
-
filePath: file,
|
|
48
|
-
query: parse(query),
|
|
49
|
-
getSource() {
|
|
50
|
-
return value;
|
|
51
|
-
},
|
|
52
|
-
development: this.environment.mode === "dev",
|
|
53
|
-
compiler: {
|
|
54
|
-
addDependency: (file2) => {
|
|
55
|
-
this.addWatchFile(file2);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
if (result === null) return null;
|
|
60
|
-
return {
|
|
61
|
-
code: result.code,
|
|
62
|
-
map: result.map
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
function toWebpack(loader) {
|
|
68
|
-
return async function(source, callback) {
|
|
69
|
-
try {
|
|
70
|
-
const result = await loader.load({
|
|
71
|
-
filePath: this.resourcePath,
|
|
72
|
-
query: parse(this.resourceQuery.slice(1)),
|
|
73
|
-
getSource() {
|
|
74
|
-
return source;
|
|
75
|
-
},
|
|
76
|
-
development: this.mode === "development",
|
|
77
|
-
compiler: this
|
|
78
|
-
});
|
|
79
|
-
if (result === null) {
|
|
80
|
-
callback(void 0, source);
|
|
81
|
-
} else {
|
|
82
|
-
callback(void 0, result.code, result.map);
|
|
83
|
-
}
|
|
84
|
-
} catch (error) {
|
|
85
|
-
if (error instanceof ValidationError) {
|
|
86
|
-
return callback(new Error(await error.toStringFormatted()));
|
|
87
|
-
}
|
|
88
|
-
if (!(error instanceof Error)) throw error;
|
|
89
|
-
const fpath = path.relative(this.context, this.resourcePath);
|
|
90
|
-
error.message = `${fpath}:${error.name}: ${error.message}`;
|
|
91
|
-
callback(error);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function toBun(loader) {
|
|
96
|
-
function toResult(output) {
|
|
97
|
-
if (!output) return;
|
|
98
|
-
return {
|
|
99
|
-
contents: output.code,
|
|
100
|
-
loader: "js"
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
return (build) => {
|
|
104
|
-
build.onLoad({ filter: loader.test ?? /.+/ }, (args) => {
|
|
105
|
-
const [filePath, query = ""] = args.path.split("?", 2);
|
|
106
|
-
const input = {
|
|
107
|
-
async getSource() {
|
|
108
|
-
return Bun.file(filePath).text();
|
|
109
|
-
},
|
|
110
|
-
query: parse(query),
|
|
111
|
-
filePath,
|
|
112
|
-
development: false,
|
|
113
|
-
compiler: {
|
|
114
|
-
addDependency() {
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
if (loader.bun?.load) {
|
|
119
|
-
return loader.bun.load(readFileSync(filePath).toString(), input);
|
|
120
|
-
}
|
|
121
|
-
const result = loader.load(input);
|
|
122
|
-
if (result instanceof Promise) {
|
|
123
|
-
return result.then(toResult);
|
|
124
|
-
}
|
|
125
|
-
return toResult(result);
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// src/loaders/config.ts
|
|
131
|
-
import fs2 from "fs/promises";
|
|
132
|
-
function createStandaloneConfigLoader({
|
|
133
|
-
core,
|
|
134
|
-
buildConfig,
|
|
135
|
-
mode
|
|
136
|
-
}) {
|
|
137
|
-
let prev;
|
|
138
|
-
async function getConfigHash() {
|
|
139
|
-
if (mode === "production") return "static";
|
|
140
|
-
const stats = await fs2.stat(core.getOptions().configPath).catch(() => {
|
|
141
|
-
throw new Error("Cannot find config file");
|
|
142
|
-
});
|
|
143
|
-
return stats.mtime.getTime().toString();
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
async getCore() {
|
|
147
|
-
const hash = await getConfigHash();
|
|
148
|
-
if (!prev || hash !== prev.hash) {
|
|
149
|
-
prev = {
|
|
150
|
-
hash,
|
|
151
|
-
init: (async () => {
|
|
152
|
-
const { loadConfig } = await import("./load-from-file-S5CQ4H6T.js");
|
|
153
|
-
await core.init({
|
|
154
|
-
config: loadConfig(core, buildConfig)
|
|
155
|
-
});
|
|
156
|
-
})()
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
await prev.init;
|
|
160
|
-
return core;
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
function createIntegratedConfigLoader(core) {
|
|
165
|
-
return {
|
|
166
|
-
async getCore() {
|
|
167
|
-
return core;
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export {
|
|
173
|
-
toNode,
|
|
174
|
-
toVite,
|
|
175
|
-
toWebpack,
|
|
176
|
-
toBun,
|
|
177
|
-
createStandaloneConfigLoader,
|
|
178
|
-
createIntegratedConfigLoader
|
|
179
|
-
};
|
package/dist/chunk-7W73RILB.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
flattenNode,
|
|
3
|
-
remarkInclude
|
|
4
|
-
} from "./chunk-Y7ISNZ7X.js";
|
|
5
|
-
|
|
6
|
-
// src/loaders/mdx/build-mdx.ts
|
|
7
|
-
import { createProcessor } from "@mdx-js/mdx";
|
|
8
|
-
import { VFile } from "vfile";
|
|
9
|
-
|
|
10
|
-
// src/loaders/mdx/remark-postprocess.ts
|
|
11
|
-
import { visit } from "unist-util-visit";
|
|
12
|
-
import { toMarkdown } from "mdast-util-to-markdown";
|
|
13
|
-
import { valueToEstree } from "estree-util-value-to-estree";
|
|
14
|
-
import { removePosition } from "unist-util-remove-position";
|
|
15
|
-
import remarkMdx from "remark-mdx";
|
|
16
|
-
function remarkPostprocess({
|
|
17
|
-
_format,
|
|
18
|
-
includeProcessedMarkdown = false,
|
|
19
|
-
includeMDAST = false,
|
|
20
|
-
extractLinkReferences = false,
|
|
21
|
-
valueToExport = []
|
|
22
|
-
}) {
|
|
23
|
-
let _stringifyProcessor;
|
|
24
|
-
const getStringifyProcessor = () => {
|
|
25
|
-
return _stringifyProcessor ??= _format === "mdx" ? this : (
|
|
26
|
-
// force Markdown processor to stringify MDX nodes
|
|
27
|
-
this().use(remarkMdx).freeze()
|
|
28
|
-
);
|
|
29
|
-
};
|
|
30
|
-
return (tree, file) => {
|
|
31
|
-
const frontmatter = file.data.frontmatter ??= {};
|
|
32
|
-
if (!frontmatter.title) {
|
|
33
|
-
visit(tree, "heading", (node) => {
|
|
34
|
-
if (node.depth === 1) {
|
|
35
|
-
frontmatter.title = flattenNode(node);
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
file.data["mdx-export"] ??= [];
|
|
41
|
-
file.data["mdx-export"].push({
|
|
42
|
-
name: "frontmatter",
|
|
43
|
-
value: frontmatter
|
|
44
|
-
});
|
|
45
|
-
if (extractLinkReferences) {
|
|
46
|
-
const urls = [];
|
|
47
|
-
visit(tree, "link", (node) => {
|
|
48
|
-
urls.push({
|
|
49
|
-
href: node.url
|
|
50
|
-
});
|
|
51
|
-
return "skip";
|
|
52
|
-
});
|
|
53
|
-
file.data["mdx-export"].push({
|
|
54
|
-
name: "extractedReferences",
|
|
55
|
-
value: urls
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
if (includeProcessedMarkdown) {
|
|
59
|
-
const processor = getStringifyProcessor();
|
|
60
|
-
const markdown = toMarkdown(tree, {
|
|
61
|
-
...processor.data("settings"),
|
|
62
|
-
// from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
|
|
63
|
-
extensions: processor.data("toMarkdownExtensions") || []
|
|
64
|
-
});
|
|
65
|
-
file.data["mdx-export"].push({
|
|
66
|
-
name: "_markdown",
|
|
67
|
-
value: markdown
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
if (includeMDAST) {
|
|
71
|
-
const options = includeMDAST === true ? {} : includeMDAST;
|
|
72
|
-
const mdast = JSON.stringify(
|
|
73
|
-
options.removePosition ? removePosition(structuredClone(tree)) : tree
|
|
74
|
-
);
|
|
75
|
-
file.data["mdx-export"].push({
|
|
76
|
-
name: "_mdast",
|
|
77
|
-
value: mdast
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
for (const { name, value } of file.data["mdx-export"]) {
|
|
81
|
-
tree.children.unshift(getMdastExport(name, value));
|
|
82
|
-
}
|
|
83
|
-
file.data["mdx-export"] = [];
|
|
84
|
-
for (const name of valueToExport) {
|
|
85
|
-
if (!(name in file.data)) continue;
|
|
86
|
-
tree.children.unshift(getMdastExport(name, file.data[name]));
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function getMdastExport(name, value) {
|
|
91
|
-
return {
|
|
92
|
-
type: "mdxjsEsm",
|
|
93
|
-
value: "",
|
|
94
|
-
data: {
|
|
95
|
-
estree: {
|
|
96
|
-
type: "Program",
|
|
97
|
-
sourceType: "module",
|
|
98
|
-
body: [
|
|
99
|
-
{
|
|
100
|
-
type: "ExportNamedDeclaration",
|
|
101
|
-
attributes: [],
|
|
102
|
-
specifiers: [],
|
|
103
|
-
source: null,
|
|
104
|
-
declaration: {
|
|
105
|
-
type: "VariableDeclaration",
|
|
106
|
-
kind: "let",
|
|
107
|
-
declarations: [
|
|
108
|
-
{
|
|
109
|
-
type: "VariableDeclarator",
|
|
110
|
-
id: {
|
|
111
|
-
type: "Identifier",
|
|
112
|
-
name
|
|
113
|
-
},
|
|
114
|
-
init: valueToEstree(value)
|
|
115
|
-
}
|
|
116
|
-
]
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
]
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// src/loaders/mdx/build-mdx.ts
|
|
126
|
-
async function buildMDX(core, collection, {
|
|
127
|
-
filePath,
|
|
128
|
-
frontmatter,
|
|
129
|
-
source,
|
|
130
|
-
_compiler,
|
|
131
|
-
environment,
|
|
132
|
-
isDevelopment
|
|
133
|
-
}) {
|
|
134
|
-
const mdxOptions = await core.getConfig().getMDXOptions(collection, environment);
|
|
135
|
-
function getProcessor(format) {
|
|
136
|
-
const cache = core.cache;
|
|
137
|
-
const key = `build-mdx:${collection?.name ?? "global"}:${format}`;
|
|
138
|
-
let processor = cache.get(key);
|
|
139
|
-
if (!processor) {
|
|
140
|
-
const postprocessOptions = {
|
|
141
|
-
_format: format,
|
|
142
|
-
...collection?.postprocess
|
|
143
|
-
};
|
|
144
|
-
processor = createProcessor({
|
|
145
|
-
outputFormat: "program",
|
|
146
|
-
development: isDevelopment,
|
|
147
|
-
...mdxOptions,
|
|
148
|
-
remarkPlugins: [
|
|
149
|
-
remarkInclude,
|
|
150
|
-
...mdxOptions.remarkPlugins ?? [],
|
|
151
|
-
[remarkPostprocess, postprocessOptions]
|
|
152
|
-
],
|
|
153
|
-
format
|
|
154
|
-
});
|
|
155
|
-
cache.set(key, processor);
|
|
156
|
-
}
|
|
157
|
-
return processor;
|
|
158
|
-
}
|
|
159
|
-
let vfile = new VFile({
|
|
160
|
-
value: source,
|
|
161
|
-
path: filePath,
|
|
162
|
-
cwd: collection?.cwd,
|
|
163
|
-
data: { frontmatter, _compiler, _getProcessor: getProcessor }
|
|
164
|
-
});
|
|
165
|
-
if (collection) {
|
|
166
|
-
vfile = await core.transformVFile({ collection, filePath, source }, vfile);
|
|
167
|
-
}
|
|
168
|
-
return getProcessor(filePath.endsWith(".mdx") ? "mdx" : "md").process(vfile);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export {
|
|
172
|
-
buildMDX
|
|
173
|
-
};
|