@rspress/core 2.0.0-beta.11 → 2.0.0-beta.12
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/index.js +192 -193
- package/dist/loader.d.ts +4 -18
- package/dist/loader.js +28 -397
- package/dist/processor.d.ts +73 -0
- package/dist/processor.js +424 -0
- package/dist/runtime/App.js +16 -16
- package/dist/runtime/ClientApp.js +16 -16
- package/dist/runtime/csrClientEntry.js +4 -4
- package/dist/runtime/initPageData.js +17 -17
- package/dist/runtime/ssrClientEntry.js +8 -8
- package/dist/runtime/ssrServerEntry.js +21 -22
- package/package.json +13 -13
package/dist/loader.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { AdditionalPage } from '@rspress/shared';
|
|
2
2
|
import { DefaultThemeConfig } from '@rspress/shared';
|
|
3
|
-
import type { FrontMatterMeta } from '@rspress/shared';
|
|
4
3
|
import type { PageIndexInfo } from '@rspress/shared';
|
|
5
4
|
import type { RouteMeta } from '@rspress/shared';
|
|
6
5
|
import type { Rspack as Rspack_2 } from '@rsbuild/core';
|
|
7
6
|
import type { RspressPlugin } from '@rspress/shared';
|
|
8
7
|
import type { UserConfig } from '@rspress/shared';
|
|
9
8
|
|
|
10
|
-
declare
|
|
9
|
+
declare function mdxLoader(this: Rspack_2.LoaderContext<MdxLoaderOptions>, source: string): Promise<void>;
|
|
10
|
+
export default mdxLoader;
|
|
11
|
+
|
|
12
|
+
declare interface MdxLoaderOptions {
|
|
11
13
|
config: UserConfig;
|
|
12
14
|
docDirectory: string;
|
|
13
15
|
checkDeadLinks: boolean;
|
|
@@ -15,16 +17,6 @@ declare interface LoaderOptions {
|
|
|
15
17
|
pluginDriver: PluginDriver;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
declare function mdxLoader(this: Rspack_2.LoaderContext<LoaderOptions>, source: string): Promise<void>;
|
|
19
|
-
export default mdxLoader;
|
|
20
|
-
|
|
21
|
-
export declare interface PageMeta {
|
|
22
|
-
toc: TocItem[];
|
|
23
|
-
title: string;
|
|
24
|
-
headingTitle: string;
|
|
25
|
-
frontmatter?: FrontMatterMeta;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
20
|
declare class PluginDriver {
|
|
29
21
|
#private;
|
|
30
22
|
constructor(config: UserConfig, isProd: boolean);
|
|
@@ -76,10 +68,4 @@ declare class RouteService {
|
|
|
76
68
|
|
|
77
69
|
declare type RspressPluginHookKeys = 'beforeBuild' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
|
|
78
70
|
|
|
79
|
-
declare interface TocItem {
|
|
80
|
-
id: string;
|
|
81
|
-
text: string;
|
|
82
|
-
depth: number;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
71
|
export { }
|
package/dist/loader.js
CHANGED
|
@@ -1,411 +1,42 @@
|
|
|
1
1
|
import __rslib_shim_module__ from 'module';
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__ from "@rspress/shared/logger";
|
|
6
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__ from "@rspress/shared/node-utils";
|
|
7
|
-
import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
|
|
8
|
-
import * as __WEBPACK_EXTERNAL_MODULE_rehype_external_links_09bed11a__ from "rehype-external-links";
|
|
9
|
-
import * as __WEBPACK_EXTERNAL_MODULE_rehype_raw_434f4cf9__ from "rehype-raw";
|
|
10
|
-
import * as __WEBPACK_EXTERNAL_MODULE_remark_gfm_073acf21__ from "remark-gfm";
|
|
11
|
-
import * as __WEBPACK_EXTERNAL_MODULE_github_slugger_8e9a17cb__ from "github-slugger";
|
|
12
|
-
import * as __WEBPACK_EXTERNAL_MODULE_hast_util_heading_rank_cff646ba__ from "hast-util-heading-rank";
|
|
13
|
-
import * as __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__ from "unist-util-visit";
|
|
14
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
|
|
15
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__ from "@rspress/shared/constants";
|
|
16
|
-
import * as __WEBPACK_EXTERNAL_MODULE_unist_util_visit_children_71921007__ from "unist-util-visit-children";
|
|
17
|
-
function applyReplaceRules(code = '', replaceRules = []) {
|
|
18
|
-
let result = code;
|
|
19
|
-
for (const rule of replaceRules)result = result.replace(rule.search, rule.replace);
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
function escapeMarkdownHeadingIds(content) {
|
|
23
|
-
const markdownHeadingRegexp = /(?:^|\n)#{1,6}(?!#).*/g;
|
|
24
|
-
return content.replace(markdownHeadingRegexp, (substring)=>substring.replace('{#', '\\{#').replace('\\\\{#', '\\{#'));
|
|
25
|
-
}
|
|
26
|
-
const isWindows = 'win32' === __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__["default"].platform();
|
|
27
|
-
function slash(p) {
|
|
28
|
-
return p.replace(/\\/g, '/');
|
|
29
|
-
}
|
|
30
|
-
function normalizePath(id) {
|
|
31
|
-
return __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].posix.normalize(isWindows ? slash(id) : id);
|
|
32
|
-
}
|
|
33
|
-
const rehypeHeaderAnchor = ()=>{
|
|
34
|
-
const slugger = new __WEBPACK_EXTERNAL_MODULE_github_slugger_8e9a17cb__["default"]();
|
|
35
|
-
return (tree)=>{
|
|
36
|
-
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'element', (node)=>{
|
|
37
|
-
if (!(0, __WEBPACK_EXTERNAL_MODULE_hast_util_heading_rank_cff646ba__.headingRank)(node)) return;
|
|
38
|
-
if (!node.properties?.id) {
|
|
39
|
-
const [text, customId] = collectHeaderText(node);
|
|
40
|
-
node.properties ??= {};
|
|
41
|
-
node.properties.id = customId || slugger.slug(text);
|
|
42
|
-
}
|
|
43
|
-
node.children.unshift(create(node));
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
const collectHeaderText = (node)=>{
|
|
48
|
-
let text = '';
|
|
49
|
-
let id = '';
|
|
50
|
-
node.children.forEach((child)=>{
|
|
51
|
-
if ('text' === child.type) {
|
|
52
|
-
const [textPart, idPart] = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.extractTextAndId)(child.value);
|
|
53
|
-
child.value = textPart;
|
|
54
|
-
text += textPart;
|
|
55
|
-
id = idPart;
|
|
56
|
-
} else if ('element' === child.type) child.children.forEach((c)=>{
|
|
57
|
-
if ('text' === c.type) text += c.value;
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
return [
|
|
61
|
-
text,
|
|
62
|
-
id
|
|
63
|
-
];
|
|
64
|
-
};
|
|
65
|
-
function create(node) {
|
|
66
|
-
return {
|
|
67
|
-
type: 'element',
|
|
68
|
-
tagName: 'a',
|
|
69
|
-
properties: {
|
|
70
|
-
class: 'header-anchor',
|
|
71
|
-
ariaHidden: 'true',
|
|
72
|
-
href: `#${node.properties.id}`
|
|
73
|
-
},
|
|
74
|
-
children: [
|
|
75
|
-
{
|
|
76
|
-
type: 'text',
|
|
77
|
-
value: '#'
|
|
78
|
-
}
|
|
79
|
-
]
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
const getASTNodeImport = (name, from)=>({
|
|
83
|
-
type: 'mdxjsEsm',
|
|
84
|
-
value: `import ${name} from ${JSON.stringify(from)}`,
|
|
85
|
-
data: {
|
|
86
|
-
estree: {
|
|
87
|
-
type: 'Program',
|
|
88
|
-
sourceType: 'module',
|
|
89
|
-
body: [
|
|
90
|
-
{
|
|
91
|
-
type: 'ImportDeclaration',
|
|
92
|
-
specifiers: [
|
|
93
|
-
{
|
|
94
|
-
type: 'ImportDefaultSpecifier',
|
|
95
|
-
local: {
|
|
96
|
-
type: 'Identifier',
|
|
97
|
-
name
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
],
|
|
101
|
-
source: {
|
|
102
|
-
type: 'Literal',
|
|
103
|
-
value: from,
|
|
104
|
-
raw: `${JSON.stringify(from)}`
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
]
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
const remarkBuiltin = ({ globalComponents })=>(tree)=>{
|
|
112
|
-
const demos = globalComponents.map((componentPath)=>{
|
|
113
|
-
const filename = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].parse(componentPath).name;
|
|
114
|
-
const componentName = filename[0].toUpperCase() + filename.slice(1);
|
|
115
|
-
return getASTNodeImport(componentName, componentPath);
|
|
116
|
-
});
|
|
117
|
-
tree.children.unshift(...demos);
|
|
118
|
-
};
|
|
119
|
-
const IGNORE_REGEXP = /^(https?|mailto|tel|#)/;
|
|
120
|
-
function checkLinks(links, filepath, root, routeService) {
|
|
121
|
-
const errorInfos = [];
|
|
122
|
-
links.filter((link)=>!IGNORE_REGEXP.test(link)).map((link)=>normalizePath(link)).forEach((link)=>{
|
|
123
|
-
const relativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, filepath);
|
|
124
|
-
if (!routeService.isExistRoute((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.cleanUrl)(link))) errorInfos.push(`Internal link to "${link}" is dead, check it in "${relativePath}"`);
|
|
125
|
-
});
|
|
126
|
-
if (errorInfos.length > 0) {
|
|
127
|
-
errorInfos?.forEach((err)=>{
|
|
128
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(err);
|
|
129
|
-
});
|
|
130
|
-
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isProduction)()) throw new Error('Dead link found');
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
const remarkCheckDeadLinks = (checkLink)=>{
|
|
134
|
-
const { root, routeService } = checkLink;
|
|
135
|
-
return (tree, vfile)=>{
|
|
136
|
-
const internalLinks = new Set();
|
|
137
|
-
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'link', ({ url })=>{
|
|
138
|
-
if (!url) return;
|
|
139
|
-
if (internalLinks.has(url)) return;
|
|
140
|
-
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
|
141
|
-
const { routePath: normalizeUrl } = routeService.normalizeRoutePath(url.split(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].sep).join('/')?.split('#')[0]);
|
|
142
|
-
internalLinks.add(normalizeUrl);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
checkLinks(Array.from(internalLinks), vfile.path, root, routeService);
|
|
146
|
-
};
|
|
147
|
-
};
|
|
148
|
-
function normalizeLink(nodeUrl, routeService, relativePath, cleanUrls) {
|
|
149
|
-
if (!nodeUrl) return '';
|
|
150
|
-
if (nodeUrl.startsWith('#')) return `#${nodeUrl.slice(1)}`;
|
|
151
|
-
let { url, hash } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.parseUrl)(nodeUrl);
|
|
152
|
-
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(url)) return url + (hash ? `#${hash}` : '');
|
|
153
|
-
const extname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(url);
|
|
154
|
-
if ((routeService?.extensions ?? __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS).includes(extname)) url = url.replace(new RegExp(`\\${extname}$`), '');
|
|
155
|
-
if (url.startsWith('.')) url = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].posix.join((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(relativePath)), url);
|
|
156
|
-
else if (routeService) {
|
|
157
|
-
const [pathVersion, pathLang] = routeService.getRoutePathParts((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(relativePath));
|
|
158
|
-
const [urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
|
|
159
|
-
url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)(urlPath);
|
|
160
|
-
if (pathLang && urlLang !== pathLang) url = `/${pathLang}${url}`;
|
|
161
|
-
if (pathVersion && urlVersion !== pathVersion) url = `/${pathVersion}${url}`;
|
|
162
|
-
}
|
|
163
|
-
if ('boolean' == typeof cleanUrls) url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeHref)(url, cleanUrls);
|
|
164
|
-
else {
|
|
165
|
-
url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeHref)(url, false);
|
|
166
|
-
url = url.replace(/\.html$/, cleanUrls);
|
|
167
|
-
}
|
|
168
|
-
if (hash) url += `#${hash}`;
|
|
169
|
-
return url;
|
|
170
|
-
}
|
|
171
|
-
const normalizeImageUrl = (imageUrl)=>{
|
|
172
|
-
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(imageUrl) || imageUrl.startsWith('/')) return '';
|
|
173
|
-
return imageUrl;
|
|
174
|
-
};
|
|
175
|
-
const remarkPluginNormalizeLink = ({ root, cleanUrls, routeService })=>(tree, file)=>{
|
|
176
|
-
const images = [];
|
|
177
|
-
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'link', (node)=>{
|
|
178
|
-
const { url: nodeUrl } = node;
|
|
179
|
-
const relativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, file.path);
|
|
180
|
-
node.url = normalizeLink(nodeUrl, routeService, relativePath, cleanUrls);
|
|
181
|
-
});
|
|
182
|
-
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'definition', (node)=>{
|
|
183
|
-
const { url: nodeUrl } = node;
|
|
184
|
-
const relativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, file.path);
|
|
185
|
-
node.url = normalizeLink(nodeUrl, routeService, relativePath, cleanUrls);
|
|
186
|
-
});
|
|
187
|
-
const getMdxSrcAttribute = (tempVar)=>({
|
|
188
|
-
type: 'mdxJsxAttribute',
|
|
189
|
-
name: 'src',
|
|
190
|
-
value: {
|
|
191
|
-
type: 'mdxJsxAttributeValueExpression',
|
|
192
|
-
value: tempVar,
|
|
193
|
-
data: {
|
|
194
|
-
estree: {
|
|
195
|
-
type: 'Program',
|
|
196
|
-
sourceType: 'module',
|
|
197
|
-
body: [
|
|
198
|
-
{
|
|
199
|
-
type: 'ExpressionStatement',
|
|
200
|
-
expression: {
|
|
201
|
-
type: 'Identifier',
|
|
202
|
-
name: tempVar
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
]
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'image', (node)=>{
|
|
211
|
-
const { alt, url } = node;
|
|
212
|
-
if (!url) return;
|
|
213
|
-
const imagePath = normalizeImageUrl(url);
|
|
214
|
-
if (!imagePath) return;
|
|
215
|
-
const tempVariableName = `image${images.length}`;
|
|
216
|
-
Object.assign(node, {
|
|
217
|
-
type: 'mdxJsxFlowElement',
|
|
218
|
-
name: 'img',
|
|
219
|
-
children: [],
|
|
220
|
-
attributes: [
|
|
221
|
-
alt && {
|
|
222
|
-
type: 'mdxJsxAttribute',
|
|
223
|
-
name: 'alt',
|
|
224
|
-
value: alt
|
|
225
|
-
},
|
|
226
|
-
getMdxSrcAttribute(tempVariableName)
|
|
227
|
-
].filter(Boolean)
|
|
228
|
-
});
|
|
229
|
-
images.push(getASTNodeImport(tempVariableName, imagePath));
|
|
230
|
-
});
|
|
231
|
-
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, (node)=>{
|
|
232
|
-
if ('mdxJsxFlowElement' !== node.type && 'mdxJsxTextElement' !== node.type || 'img' !== node.name) return;
|
|
233
|
-
const srcAttr = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'src', true);
|
|
234
|
-
if ('string' != typeof srcAttr?.value) return;
|
|
235
|
-
const imagePath = normalizeImageUrl(srcAttr.value);
|
|
236
|
-
if (!imagePath) return;
|
|
237
|
-
const tempVariableName = `image${images.length}`;
|
|
238
|
-
Object.assign(srcAttr, getMdxSrcAttribute(tempVariableName));
|
|
239
|
-
images.push(getASTNodeImport(tempVariableName, imagePath));
|
|
240
|
-
});
|
|
241
|
-
tree.children.unshift(...images);
|
|
242
|
-
};
|
|
243
|
-
const parseToc = (tree)=>{
|
|
244
|
-
let title = '';
|
|
245
|
-
const toc = [];
|
|
246
|
-
const slugger = new __WEBPACK_EXTERNAL_MODULE_github_slugger_8e9a17cb__["default"]();
|
|
247
|
-
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_children_71921007__.visitChildren)((node)=>{
|
|
248
|
-
if ('heading' !== node.type || !node.depth || !node.children) return;
|
|
249
|
-
if (node.depth >= 1 && node.depth < 5) {
|
|
250
|
-
let customId = '';
|
|
251
|
-
const text = node.children.map((child)=>{
|
|
252
|
-
if ('link' === child.type) return child.children?.map((item)=>item.value).join('');
|
|
253
|
-
if ('strong' === child.type) return `**${child.children?.map((item)=>item.value).join('')}**`;
|
|
254
|
-
if ('emphasis' === child.type) return `*${child.children?.map((item)=>item.value).join('')}*`;
|
|
255
|
-
if ('delete' === child.type) return `~~${child.children?.map((item)=>item.value).join('')}~~`;
|
|
256
|
-
if ('text' === child.type) {
|
|
257
|
-
const [textPart, idPart] = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.extractTextAndId)(child.value);
|
|
258
|
-
customId = idPart;
|
|
259
|
-
return textPart;
|
|
260
|
-
}
|
|
261
|
-
if ('inlineCode' === child.type) return `\`${child.value}\``;
|
|
262
|
-
return '';
|
|
263
|
-
}).join('');
|
|
264
|
-
if (1 === node.depth) {
|
|
265
|
-
if (!title) title = text;
|
|
266
|
-
} else {
|
|
267
|
-
const id = customId ? customId : slugger.slug(text);
|
|
268
|
-
const { depth } = node;
|
|
269
|
-
toc.push({
|
|
270
|
-
id,
|
|
271
|
-
text,
|
|
272
|
-
depth
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
})(tree);
|
|
277
|
-
return {
|
|
278
|
-
title,
|
|
279
|
-
toc
|
|
280
|
-
};
|
|
281
|
-
};
|
|
282
|
-
const remarkPluginToc = function() {
|
|
283
|
-
const data = this.data();
|
|
284
|
-
return (tree)=>{
|
|
285
|
-
const { toc, title } = parseToc(tree);
|
|
286
|
-
data.pageMeta.toc = toc;
|
|
287
|
-
if (title) data.pageMeta.title = title;
|
|
288
|
-
};
|
|
289
|
-
};
|
|
290
|
-
const rehypeCodeMeta = ()=>(tree)=>{
|
|
291
|
-
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'element', (node)=>{
|
|
292
|
-
if ('pre' === node.tagName && node.children[0]?.type === 'element' && 'code' === node.children[0].tagName) {
|
|
293
|
-
const codeNode = node.children[0];
|
|
294
|
-
codeNode.properties.metastring = codeNode.data?.meta;
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
};
|
|
298
|
-
async function createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver) {
|
|
299
|
-
const format = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(filepath).slice(1);
|
|
300
|
-
const cleanUrls = config?.route?.cleanUrls ?? false;
|
|
301
|
-
const { remarkPlugins: remarkPluginsFromConfig = [], rehypePlugins: rehypePluginsFromConfig = [], globalComponents: globalComponentsFromConfig = [] } = config?.markdown || {};
|
|
302
|
-
const rspressPlugins = pluginDriver.getPlugins();
|
|
303
|
-
const remarkPluginsFromPlugins = rspressPlugins.flatMap((plugin)=>plugin.markdown?.remarkPlugins || []);
|
|
304
|
-
const rehypePluginsFromPlugins = rspressPlugins.flatMap((plugin)=>plugin.markdown?.rehypePlugins || []);
|
|
305
|
-
const globalComponents = [
|
|
306
|
-
...rspressPlugins.flatMap((plugin)=>plugin.markdown?.globalComponents || []),
|
|
307
|
-
...globalComponentsFromConfig
|
|
308
|
-
];
|
|
309
|
-
return {
|
|
310
|
-
providerImportSource: '@mdx-js/react',
|
|
311
|
-
format,
|
|
312
|
-
remarkPlugins: [
|
|
313
|
-
__WEBPACK_EXTERNAL_MODULE_remark_gfm_073acf21__["default"],
|
|
314
|
-
remarkPluginToc,
|
|
315
|
-
[
|
|
316
|
-
remarkPluginNormalizeLink,
|
|
317
|
-
{
|
|
318
|
-
cleanUrls,
|
|
319
|
-
root: docDirectory,
|
|
320
|
-
routeService
|
|
321
|
-
}
|
|
322
|
-
],
|
|
323
|
-
checkDeadLinks && [
|
|
324
|
-
remarkCheckDeadLinks,
|
|
325
|
-
{
|
|
326
|
-
root: docDirectory,
|
|
327
|
-
base: config?.base || '',
|
|
328
|
-
routeService
|
|
329
|
-
}
|
|
330
|
-
],
|
|
331
|
-
globalComponents.length && [
|
|
332
|
-
remarkBuiltin,
|
|
333
|
-
{
|
|
334
|
-
globalComponents
|
|
335
|
-
}
|
|
336
|
-
],
|
|
337
|
-
...remarkPluginsFromConfig,
|
|
338
|
-
...remarkPluginsFromPlugins
|
|
339
|
-
].filter(Boolean),
|
|
340
|
-
rehypePlugins: [
|
|
341
|
-
rehypeHeaderAnchor,
|
|
342
|
-
...'md' === format ? [
|
|
343
|
-
rehypeCodeMeta,
|
|
344
|
-
[
|
|
345
|
-
__WEBPACK_EXTERNAL_MODULE_rehype_raw_434f4cf9__["default"],
|
|
346
|
-
{
|
|
347
|
-
passThrough: __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__.nodeTypes
|
|
348
|
-
}
|
|
349
|
-
]
|
|
350
|
-
] : [],
|
|
351
|
-
[
|
|
352
|
-
__WEBPACK_EXTERNAL_MODULE_rehype_external_links_09bed11a__["default"],
|
|
353
|
-
{
|
|
354
|
-
target: '_blank',
|
|
355
|
-
rel: 'noopener noreferrer'
|
|
356
|
-
}
|
|
357
|
-
],
|
|
358
|
-
...rehypePluginsFromConfig,
|
|
359
|
-
...rehypePluginsFromPlugins
|
|
360
|
-
]
|
|
361
|
-
};
|
|
362
|
-
}
|
|
3
|
+
import { logger } from "@rspress/shared/logger";
|
|
4
|
+
import { compile, compileWithCrossCompilerCache } from "./processor.js";
|
|
363
5
|
async function mdxLoader(source) {
|
|
364
6
|
this.cacheable(true);
|
|
365
7
|
const callback = this.async();
|
|
366
8
|
const options = this.getOptions();
|
|
367
9
|
const filepath = this.resourcePath;
|
|
368
10
|
const { config, docDirectory, checkDeadLinks, routeService, pluginDriver } = options;
|
|
369
|
-
const
|
|
370
|
-
const replacedSource = applyReplaceRules(emptyLinesSource, config.replaceRules);
|
|
371
|
-
const preprocessedContent = escapeMarkdownHeadingIds(replacedSource);
|
|
11
|
+
const crossCompilerCache = config?.markdown?.crossCompilerCache ?? true;
|
|
372
12
|
try {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
frontmatter
|
|
397
|
-
};
|
|
398
|
-
const result = `const frontmatter = ${JSON.stringify(frontmatter)};
|
|
399
|
-
${compileResult}
|
|
400
|
-
MDXContent.__RSPRESS_PAGE_META = {};
|
|
401
|
-
|
|
402
|
-
MDXContent.__RSPRESS_PAGE_META["${encodeURIComponent(normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(docDirectory, filepath)))}"] = ${JSON.stringify(pageMeta)};
|
|
403
|
-
`;
|
|
404
|
-
callback(null, result);
|
|
13
|
+
if (crossCompilerCache && 'production' === process.env.NODE_ENV) {
|
|
14
|
+
const compileResult = await compileWithCrossCompilerCache({
|
|
15
|
+
source,
|
|
16
|
+
filepath,
|
|
17
|
+
docDirectory,
|
|
18
|
+
checkDeadLinks,
|
|
19
|
+
config,
|
|
20
|
+
pluginDriver,
|
|
21
|
+
routeService
|
|
22
|
+
});
|
|
23
|
+
callback(null, compileResult);
|
|
24
|
+
} else {
|
|
25
|
+
const compileResult = await compile({
|
|
26
|
+
source,
|
|
27
|
+
filepath,
|
|
28
|
+
docDirectory,
|
|
29
|
+
checkDeadLinks,
|
|
30
|
+
config,
|
|
31
|
+
pluginDriver,
|
|
32
|
+
routeService
|
|
33
|
+
});
|
|
34
|
+
callback(null, compileResult);
|
|
35
|
+
}
|
|
405
36
|
} catch (e) {
|
|
406
37
|
if (e instanceof Error) {
|
|
407
|
-
|
|
408
|
-
|
|
38
|
+
logger.error(`MDX compile error: ${e.message} in ${filepath}`);
|
|
39
|
+
logger.debug(e);
|
|
409
40
|
callback({
|
|
410
41
|
message: e.message,
|
|
411
42
|
name: `${filepath} compile error`
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { AdditionalPage } from '@rspress/shared';
|
|
2
|
+
import { DefaultThemeConfig } from '@rspress/shared';
|
|
3
|
+
import type { PageIndexInfo } from '@rspress/shared';
|
|
4
|
+
import type { RouteMeta } from '@rspress/shared';
|
|
5
|
+
import type { RspressPlugin } from '@rspress/shared';
|
|
6
|
+
import type { UserConfig } from '@rspress/shared';
|
|
7
|
+
|
|
8
|
+
export declare function compile(options: CompileOptions): Promise<string>;
|
|
9
|
+
|
|
10
|
+
declare interface CompileOptions {
|
|
11
|
+
source: string;
|
|
12
|
+
filepath: string;
|
|
13
|
+
checkDeadLinks: boolean;
|
|
14
|
+
docDirectory: string;
|
|
15
|
+
config: UserConfig;
|
|
16
|
+
routeService: RouteService;
|
|
17
|
+
pluginDriver: PluginDriver;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare function compileWithCrossCompilerCache(options: CompileOptions): Promise<string>;
|
|
21
|
+
|
|
22
|
+
declare class PluginDriver {
|
|
23
|
+
#private;
|
|
24
|
+
constructor(config: UserConfig, isProd: boolean);
|
|
25
|
+
init(): Promise<void>;
|
|
26
|
+
addPlugin(plugin: RspressPlugin): void;
|
|
27
|
+
getPlugins(): RspressPlugin[];
|
|
28
|
+
clearPlugins(): void;
|
|
29
|
+
removePlugin(pluginName: string): void;
|
|
30
|
+
modifyConfig(): Promise<UserConfig<DefaultThemeConfig>>;
|
|
31
|
+
beforeBuild(): Promise<void[]>;
|
|
32
|
+
afterBuild(): Promise<void[]>;
|
|
33
|
+
modifySearchIndexData(pages: PageIndexInfo[]): Promise<void[]>;
|
|
34
|
+
extendPageData(pageData: PageIndexInfo): Promise<void[]>;
|
|
35
|
+
addPages(): Promise<AdditionalPage[]>;
|
|
36
|
+
routeGenerated(routes: RouteMeta[]): Promise<void[]>;
|
|
37
|
+
routeServiceGenerated(routeService: RouteService): Promise<void[]>;
|
|
38
|
+
addRuntimeModules(): Promise<Record<string, string>>;
|
|
39
|
+
addSSGRoutes(): Promise<({
|
|
40
|
+
path: string;
|
|
41
|
+
} | {
|
|
42
|
+
path: string;
|
|
43
|
+
})[]>;
|
|
44
|
+
globalUIComponents(): (string | [string, object])[];
|
|
45
|
+
globalStyles(): string[];
|
|
46
|
+
_runParallelAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): Promise<Awaited<ReturnType<Required<RspressPlugin>[H]>>[]>;
|
|
47
|
+
_runSerialAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): RspressPlugin;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class RouteService {
|
|
51
|
+
#private;
|
|
52
|
+
routeData: Map<string, RouteMeta>;
|
|
53
|
+
constructor(scanDir: string, userConfig: UserConfig, tempDir: string, pluginDriver: PluginDriver);
|
|
54
|
+
get extensions(): readonly string[];
|
|
55
|
+
init(): Promise<void>;
|
|
56
|
+
addRoute(routeInfo: RouteMeta): void;
|
|
57
|
+
removeRoute(filePath: string): void;
|
|
58
|
+
getRoutes(): RouteMeta[];
|
|
59
|
+
isExistRoute(routePath: string): boolean;
|
|
60
|
+
isEmpty(): boolean;
|
|
61
|
+
generateRoutesCode(): string;
|
|
62
|
+
generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[]): string;
|
|
63
|
+
getRoutePathParts(routePath: string): readonly [string, string, string];
|
|
64
|
+
normalizeRoutePath(routePath: string): {
|
|
65
|
+
routePath: string;
|
|
66
|
+
lang: string;
|
|
67
|
+
version: string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
declare type RspressPluginHookKeys = 'beforeBuild' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
|
|
72
|
+
|
|
73
|
+
export { }
|