@rspress/core 2.0.0-beta.0 → 2.0.0-beta.10
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/README.md +1 -1
- package/dist/index.d.ts +153 -0
- package/dist/index.js +386 -436
- package/dist/loader.d.ts +2 -5
- package/dist/loader.js +93 -269
- package/dist/runtime/App.d.ts +1 -4
- package/dist/runtime/App.js +3 -6
- package/dist/runtime/ClientApp.js +6 -1
- package/dist/runtime/csrClientEntry.js +3 -11
- package/dist/runtime/initPageData.d.ts +0 -1
- package/dist/runtime/initPageData.js +3 -6
- package/dist/runtime/ssrClientEntry.js +4 -11
- package/dist/runtime/ssrServerEntry.d.ts +3 -2
- package/dist/runtime/ssrServerEntry.js +7 -5
- package/package.json +28 -25
- package/dist/runtime/tsconfig.js +0 -4
package/dist/index.js
CHANGED
|
@@ -1,70 +1,46 @@
|
|
|
1
1
|
import __rslib_shim_module__ from 'module';
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
3
3
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_plugin_container_syntax_12d3c700__ from "@rspress/plugin-container-syntax";
|
|
4
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
|
|
5
4
|
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__ from "node:fs/promises";
|
|
6
5
|
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
7
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__ from "@rsbuild/plugin-react";
|
|
8
6
|
import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__ from "@rsbuild/plugin-react";
|
|
8
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
|
|
9
9
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__ from "@rspress/shared/logger";
|
|
10
10
|
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
11
11
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__ from "@rspress/shared/constants";
|
|
12
12
|
import * as __WEBPACK_EXTERNAL_MODULE_tinyglobby__ from "tinyglobby";
|
|
13
13
|
import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
|
|
14
14
|
import * as __WEBPACK_EXTERNAL_MODULE_rspack_plugin_virtual_module_609978fd__ from "rspack-plugin-virtual-module";
|
|
15
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__ from "@rspress/shared/node-utils";
|
|
15
16
|
import * as __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__ from "lodash-es";
|
|
16
17
|
import * as __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__ from "node:crypto";
|
|
17
18
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_mdx_rs_d2f3021f__ from "@rspress/mdx-rs";
|
|
18
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__ from "@rspress/shared/node-utils";
|
|
19
19
|
import * as __WEBPACK_EXTERNAL_MODULE_html_to_text_2c51ed38__ from "html-to-text";
|
|
20
20
|
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
21
21
|
import * as __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__ from "@mdx-js/mdx";
|
|
22
22
|
import * as __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__ from "enhanced-resolve";
|
|
23
|
-
import * as
|
|
24
|
-
import * as __WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__ from "react-helmet-async";
|
|
23
|
+
import * as __WEBPACK_EXTERNAL_MODULE__unhead_react_server_7e85c952__ from "@unhead/react/server";
|
|
25
24
|
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
25
|
+
import * as __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__ from "unist-util-visit";
|
|
26
26
|
export * from "@rspress/shared";
|
|
27
|
-
function _check_private_redeclaration(obj, privateCollection) {
|
|
28
|
-
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
29
|
-
}
|
|
30
|
-
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
31
|
-
if (descriptor.get) return descriptor.get.call(receiver);
|
|
32
|
-
return descriptor.value;
|
|
33
|
-
}
|
|
34
|
-
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
35
|
-
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
36
|
-
else {
|
|
37
|
-
if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
|
|
38
|
-
descriptor.value = value;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
42
|
-
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
43
|
-
return privateMap.get(receiver);
|
|
44
|
-
}
|
|
45
|
-
function _class_private_field_get(receiver, privateMap) {
|
|
46
|
-
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
47
|
-
return _class_apply_descriptor_get(receiver, descriptor);
|
|
48
|
-
}
|
|
49
|
-
function _class_private_field_init(obj, privateMap, value) {
|
|
50
|
-
_check_private_redeclaration(obj, privateMap);
|
|
51
|
-
privateMap.set(obj, value);
|
|
52
|
-
}
|
|
53
|
-
function _class_private_field_set(receiver, privateMap, value) {
|
|
54
|
-
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
55
|
-
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
56
|
-
return value;
|
|
57
|
-
}
|
|
58
|
-
var _config = /*#__PURE__*/ new WeakMap(), _plugins = /*#__PURE__*/ new WeakMap(), _isProd = /*#__PURE__*/ new WeakMap();
|
|
59
27
|
class PluginDriver {
|
|
28
|
+
#config;
|
|
29
|
+
#plugins;
|
|
30
|
+
#isProd;
|
|
31
|
+
constructor(config, isProd){
|
|
32
|
+
this.#config = config;
|
|
33
|
+
this.#isProd = isProd;
|
|
34
|
+
this.#plugins = [];
|
|
35
|
+
}
|
|
60
36
|
async init() {
|
|
61
|
-
var _themeConfig_locales, _themeConfig_locales_, _themeConfig_locales1, _themeConfig_locales_1, _themeConfig_locales2;
|
|
62
37
|
this.clearPlugins();
|
|
63
|
-
const config =
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
38
|
+
const config = this.#config;
|
|
39
|
+
const markdownConfig = config.markdown || {};
|
|
40
|
+
const themeConfig = config?.themeConfig || {};
|
|
41
|
+
const enableLastUpdated = themeConfig?.lastUpdated || themeConfig?.locales?.some((locale)=>locale.lastUpdated);
|
|
42
|
+
const mediumZoomConfig = config?.mediumZoom ?? true;
|
|
43
|
+
const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar || themeConfig.locales?.[0]?.nav || themeConfig.locales?.[0]?.sidebar;
|
|
68
44
|
if (enableLastUpdated) {
|
|
69
45
|
const { pluginLastUpdated } = await import("@rspress/plugin-last-updated");
|
|
70
46
|
this.addPlugin(pluginLastUpdated());
|
|
@@ -74,91 +50,92 @@ class PluginDriver {
|
|
|
74
50
|
this.addPlugin(pluginMediumZoom('object' == typeof mediumZoomConfig ? mediumZoomConfig : void 0));
|
|
75
51
|
}
|
|
76
52
|
this.addPlugin((0, __WEBPACK_EXTERNAL_MODULE__rspress_plugin_container_syntax_12d3c700__.pluginContainerSyntax)());
|
|
77
|
-
|
|
78
|
-
const SourceBuildPlugin = await import("@rspress/theme-default/node/source-build-plugin.js").then((r)=>r.SourceBuildPlugin, ()=>null);
|
|
79
|
-
if (SourceBuildPlugin) this.addPlugin(SourceBuildPlugin());
|
|
80
|
-
}
|
|
53
|
+
const { pluginShiki } = await import("@rspress/plugin-shiki");
|
|
81
54
|
(config.plugins || []).forEach((plugin)=>{
|
|
82
55
|
this.addPlugin(plugin);
|
|
83
56
|
});
|
|
57
|
+
this.addPlugin(pluginShiki(markdownConfig.shiki));
|
|
84
58
|
if (!haveNavSidebarConfig) {
|
|
85
59
|
const { pluginAutoNavSidebar } = await import("@rspress/plugin-auto-nav-sidebar");
|
|
86
60
|
this.addPlugin(pluginAutoNavSidebar());
|
|
87
61
|
}
|
|
88
62
|
}
|
|
89
63
|
addPlugin(plugin) {
|
|
90
|
-
const existedIndex =
|
|
64
|
+
const existedIndex = this.#plugins.findIndex((item)=>item.name === plugin.name);
|
|
91
65
|
if (-1 !== existedIndex) throw new Error(`The plugin "${plugin.name}" has been registered`);
|
|
92
|
-
|
|
66
|
+
this.#plugins.push(plugin);
|
|
93
67
|
}
|
|
94
68
|
getPlugins() {
|
|
95
|
-
return
|
|
69
|
+
return this.#plugins;
|
|
96
70
|
}
|
|
97
71
|
clearPlugins() {
|
|
98
|
-
|
|
72
|
+
this.#plugins = [];
|
|
99
73
|
}
|
|
100
74
|
removePlugin(pluginName) {
|
|
101
|
-
const index =
|
|
102
|
-
if (-1 !== index)
|
|
75
|
+
const index = this.#plugins.findIndex((item)=>item.name === pluginName);
|
|
76
|
+
if (-1 !== index) this.#plugins.splice(index, 1);
|
|
103
77
|
}
|
|
104
78
|
async modifyConfig() {
|
|
105
|
-
let config =
|
|
106
|
-
for(let i = 0; i <
|
|
107
|
-
const plugin =
|
|
79
|
+
let config = this.#config;
|
|
80
|
+
for(let i = 0; i < this.#plugins.length; i++){
|
|
81
|
+
const plugin = this.#plugins[i];
|
|
108
82
|
if ('function' == typeof plugin.config) config = await plugin.config(config || {}, {
|
|
109
83
|
addPlugin: this.addPlugin.bind(this),
|
|
110
84
|
removePlugin: (pluginName)=>{
|
|
111
|
-
const index =
|
|
85
|
+
const index = this.#plugins.findIndex((item)=>item.name === pluginName);
|
|
112
86
|
this.removePlugin(pluginName);
|
|
113
87
|
if (index <= i && index > 0) i--;
|
|
114
88
|
}
|
|
115
|
-
},
|
|
89
|
+
}, this.#isProd);
|
|
116
90
|
}
|
|
117
|
-
|
|
118
|
-
return
|
|
91
|
+
this.#config = config;
|
|
92
|
+
return this.#config;
|
|
119
93
|
}
|
|
120
94
|
async beforeBuild() {
|
|
121
|
-
return this._runParallelAsyncHook('beforeBuild',
|
|
95
|
+
return this._runParallelAsyncHook('beforeBuild', this.#config || {}, this.#isProd);
|
|
122
96
|
}
|
|
123
97
|
async afterBuild() {
|
|
124
|
-
return this._runParallelAsyncHook('afterBuild',
|
|
98
|
+
return this._runParallelAsyncHook('afterBuild', this.#config || {}, this.#isProd);
|
|
125
99
|
}
|
|
126
100
|
async modifySearchIndexData(pages) {
|
|
127
|
-
return this._runParallelAsyncHook('modifySearchIndexData', pages,
|
|
101
|
+
return this._runParallelAsyncHook('modifySearchIndexData', pages, this.#isProd);
|
|
128
102
|
}
|
|
129
103
|
async extendPageData(pageData) {
|
|
130
|
-
return this._runParallelAsyncHook('extendPageData', pageData,
|
|
104
|
+
return this._runParallelAsyncHook('extendPageData', pageData, this.#isProd);
|
|
131
105
|
}
|
|
132
106
|
async addPages() {
|
|
133
|
-
const result = await this._runParallelAsyncHook('addPages',
|
|
107
|
+
const result = await this._runParallelAsyncHook('addPages', this.#config || {}, this.#isProd);
|
|
134
108
|
return result.flat();
|
|
135
109
|
}
|
|
136
110
|
async routeGenerated(routes) {
|
|
137
|
-
return this._runParallelAsyncHook('routeGenerated', routes,
|
|
111
|
+
return this._runParallelAsyncHook('routeGenerated', routes, this.#isProd);
|
|
112
|
+
}
|
|
113
|
+
async routeServiceGenerated(routeService) {
|
|
114
|
+
return this._runParallelAsyncHook('routeServiceGenerated', routeService, this.#isProd);
|
|
138
115
|
}
|
|
139
116
|
async addRuntimeModules() {
|
|
140
|
-
const result = await this._runParallelAsyncHook('addRuntimeModules',
|
|
117
|
+
const result = await this._runParallelAsyncHook('addRuntimeModules', this.#config || {}, this.#isProd);
|
|
141
118
|
return result.reduce((prev, current)=>({
|
|
142
119
|
...prev,
|
|
143
120
|
...current
|
|
144
121
|
}), {});
|
|
145
122
|
}
|
|
146
123
|
async addSSGRoutes() {
|
|
147
|
-
const result = await this._runParallelAsyncHook('addSSGRoutes',
|
|
124
|
+
const result = await this._runParallelAsyncHook('addSSGRoutes', this.#config || {}, this.#isProd);
|
|
148
125
|
return result.flat();
|
|
149
126
|
}
|
|
150
127
|
globalUIComponents() {
|
|
151
|
-
const result =
|
|
128
|
+
const result = this.#plugins.map((plugin)=>plugin.globalUIComponents || []);
|
|
152
129
|
return result.flat();
|
|
153
130
|
}
|
|
154
131
|
globalStyles() {
|
|
155
|
-
return
|
|
132
|
+
return this.#plugins.filter((plugin)=>'string' == typeof plugin.globalStyles).map((plugin)=>plugin.globalStyles);
|
|
156
133
|
}
|
|
157
134
|
_runParallelAsyncHook(hookName, ...args) {
|
|
158
|
-
return Promise.all(
|
|
135
|
+
return Promise.all(this.#plugins.filter((plugin)=>'function' == typeof plugin[hookName]).map((plugin)=>plugin[hookName](...args)));
|
|
159
136
|
}
|
|
160
137
|
_runSerialAsyncHook(hookName, ...args) {
|
|
161
|
-
return
|
|
138
|
+
return this.#plugins.reduce(async (prev, plugin)=>{
|
|
162
139
|
if ('function' == typeof plugin[hookName]) {
|
|
163
140
|
await prev;
|
|
164
141
|
return plugin[hookName](...args);
|
|
@@ -166,30 +143,13 @@ class PluginDriver {
|
|
|
166
143
|
return prev;
|
|
167
144
|
}, Promise.resolve());
|
|
168
145
|
}
|
|
169
|
-
constructor(config, isProd){
|
|
170
|
-
_class_private_field_init(this, _config, {
|
|
171
|
-
writable: true,
|
|
172
|
-
value: void 0
|
|
173
|
-
});
|
|
174
|
-
_class_private_field_init(this, _plugins, {
|
|
175
|
-
writable: true,
|
|
176
|
-
value: void 0
|
|
177
|
-
});
|
|
178
|
-
_class_private_field_init(this, _isProd, {
|
|
179
|
-
writable: true,
|
|
180
|
-
value: void 0
|
|
181
|
-
});
|
|
182
|
-
_class_private_field_set(this, _config, config);
|
|
183
|
-
_class_private_field_set(this, _isProd, isProd);
|
|
184
|
-
_class_private_field_set(this, _plugins, []);
|
|
185
|
-
}
|
|
186
146
|
}
|
|
187
147
|
const PLUGIN_VIRTUAL_MODULE_NAME = 'rsbuild:virtual-module';
|
|
188
148
|
const pluginVirtualModule = (pluginOptions = {})=>({
|
|
189
149
|
name: PLUGIN_VIRTUAL_MODULE_NAME,
|
|
190
150
|
async setup (api) {
|
|
191
|
-
const
|
|
192
|
-
const
|
|
151
|
+
const { virtualModules = {}, tempDir: virtualFolderName = '.rsbuild-virtual-module' } = pluginOptions;
|
|
152
|
+
const TEMP_DIR = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(api.context.rootPath, 'node_modules', virtualFolderName);
|
|
193
153
|
const virtualFileAbsolutePaths = Object.keys(virtualModules).map((i)=>{
|
|
194
154
|
let absolutePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(TEMP_DIR, i);
|
|
195
155
|
if (!(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.extname)(absolutePath)) absolutePath = `${absolutePath}.js`;
|
|
@@ -198,6 +158,13 @@ const pluginVirtualModule = (pluginOptions = {})=>({
|
|
|
198
158
|
absolutePath
|
|
199
159
|
];
|
|
200
160
|
});
|
|
161
|
+
api.modifyRsbuildConfig((config)=>{
|
|
162
|
+
if (!config.source) config.source = {};
|
|
163
|
+
config.source.include = [
|
|
164
|
+
...config.source.include || [],
|
|
165
|
+
TEMP_DIR
|
|
166
|
+
];
|
|
167
|
+
});
|
|
201
168
|
api.onBeforeCreateCompiler(async ()=>{
|
|
202
169
|
await (0, __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__.mkdir)(TEMP_DIR, {
|
|
203
170
|
recursive: true
|
|
@@ -215,7 +182,7 @@ const pluginVirtualModule = (pluginOptions = {})=>({
|
|
|
215
182
|
}
|
|
216
183
|
}
|
|
217
184
|
});
|
|
218
|
-
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.
|
|
185
|
+
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.10"}');
|
|
219
186
|
const RSPRESS_VERSION = package_namespaceObject.i8;
|
|
220
187
|
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
221
188
|
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
@@ -237,8 +204,6 @@ const OUTPUT_DIR = 'doc_build';
|
|
|
237
204
|
const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
238
205
|
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
239
206
|
const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
|
|
240
|
-
const HTML_START_TAG = '<html';
|
|
241
|
-
const BODY_START_TAG = '<body';
|
|
242
207
|
const DEFAULT_TITLE = 'Rspress';
|
|
243
208
|
const PUBLIC_DIR = 'public';
|
|
244
209
|
const constants_TEMP_DIR = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'node_modules', __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR);
|
|
@@ -346,71 +311,49 @@ const normalizeRoutePath = (routePath, base, lang, version, langs, versions, ext
|
|
|
346
311
|
version: versionPart || version
|
|
347
312
|
};
|
|
348
313
|
};
|
|
349
|
-
function RouteService_check_private_redeclaration(obj, privateCollection) {
|
|
350
|
-
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
351
|
-
}
|
|
352
|
-
function RouteService_class_apply_descriptor_get(receiver, descriptor) {
|
|
353
|
-
if (descriptor.get) return descriptor.get.call(receiver);
|
|
354
|
-
return descriptor.value;
|
|
355
|
-
}
|
|
356
|
-
function RouteService_class_apply_descriptor_set(receiver, descriptor, value) {
|
|
357
|
-
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
358
|
-
else {
|
|
359
|
-
if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
|
|
360
|
-
descriptor.value = value;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
function RouteService_class_extract_field_descriptor(receiver, privateMap, action) {
|
|
364
|
-
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
365
|
-
return privateMap.get(receiver);
|
|
366
|
-
}
|
|
367
|
-
function RouteService_class_private_field_get(receiver, privateMap) {
|
|
368
|
-
var descriptor = RouteService_class_extract_field_descriptor(receiver, privateMap, "get");
|
|
369
|
-
return RouteService_class_apply_descriptor_get(receiver, descriptor);
|
|
370
|
-
}
|
|
371
|
-
function RouteService_class_private_field_init(obj, privateMap, value) {
|
|
372
|
-
RouteService_check_private_redeclaration(obj, privateMap);
|
|
373
|
-
privateMap.set(obj, value);
|
|
374
|
-
}
|
|
375
|
-
function RouteService_class_private_field_set(receiver, privateMap, value) {
|
|
376
|
-
var descriptor = RouteService_class_extract_field_descriptor(receiver, privateMap, "set");
|
|
377
|
-
RouteService_class_apply_descriptor_set(receiver, descriptor, value);
|
|
378
|
-
return value;
|
|
379
|
-
}
|
|
380
|
-
function _class_private_method_get(receiver, privateSet, fn) {
|
|
381
|
-
if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
|
|
382
|
-
return fn;
|
|
383
|
-
}
|
|
384
|
-
function _class_private_method_init(obj, privateSet) {
|
|
385
|
-
RouteService_check_private_redeclaration(obj, privateSet);
|
|
386
|
-
privateSet.add(obj);
|
|
387
|
-
}
|
|
388
|
-
function _define_property(obj, key, value) {
|
|
389
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
390
|
-
value: value,
|
|
391
|
-
enumerable: true,
|
|
392
|
-
configurable: true,
|
|
393
|
-
writable: true
|
|
394
|
-
});
|
|
395
|
-
else obj[key] = value;
|
|
396
|
-
return obj;
|
|
397
|
-
}
|
|
398
|
-
var _scanDir = /*#__PURE__*/ new WeakMap(), _defaultLang = /*#__PURE__*/ new WeakMap(), _defaultVersion = /*#__PURE__*/ new WeakMap(), _extensions = /*#__PURE__*/ new WeakMap(), _langs = /*#__PURE__*/ new WeakMap(), _versions = /*#__PURE__*/ new WeakMap(), _include = /*#__PURE__*/ new WeakMap(), _exclude = /*#__PURE__*/ new WeakMap(), _base = /*#__PURE__*/ new WeakMap(), _tempDir = /*#__PURE__*/ new WeakMap(), _pluginDriver = /*#__PURE__*/ new WeakMap(), _writeTempFile = /*#__PURE__*/ new WeakSet(), _generateRouteInfo = /*#__PURE__*/ new WeakSet();
|
|
399
314
|
class RouteService {
|
|
315
|
+
routeData = new Map();
|
|
316
|
+
#scanDir;
|
|
317
|
+
#defaultLang;
|
|
318
|
+
#defaultVersion = '';
|
|
319
|
+
#extensions = [];
|
|
320
|
+
#langs = [];
|
|
321
|
+
#versions = [];
|
|
322
|
+
#include = [];
|
|
323
|
+
#exclude = [];
|
|
324
|
+
#base = '';
|
|
325
|
+
#tempDir = '';
|
|
326
|
+
#pluginDriver;
|
|
327
|
+
constructor(scanDir, userConfig, tempDir, pluginDriver){
|
|
328
|
+
const routeOptions = userConfig?.route || {};
|
|
329
|
+
this.#scanDir = scanDir;
|
|
330
|
+
this.#extensions = routeOptions.extensions || __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS;
|
|
331
|
+
this.#include = routeOptions.include || [];
|
|
332
|
+
this.#exclude = routeOptions.exclude || [];
|
|
333
|
+
this.#defaultLang = userConfig?.lang || '';
|
|
334
|
+
this.#langs = (userConfig?.locales ?? userConfig?.themeConfig?.locales ?? []).map((item)=>item.lang);
|
|
335
|
+
this.#base = userConfig?.base || '';
|
|
336
|
+
this.#tempDir = tempDir;
|
|
337
|
+
this.#pluginDriver = pluginDriver;
|
|
338
|
+
if (userConfig.multiVersion) {
|
|
339
|
+
this.#defaultVersion = userConfig.multiVersion.default || '';
|
|
340
|
+
this.#versions = userConfig.multiVersion.versions || [];
|
|
341
|
+
}
|
|
342
|
+
}
|
|
400
343
|
get extensions() {
|
|
401
|
-
return
|
|
344
|
+
return this.#extensions;
|
|
402
345
|
}
|
|
403
346
|
async init() {
|
|
404
|
-
const extensions =
|
|
347
|
+
const extensions = this.#extensions.map((i)=>i.slice(1));
|
|
405
348
|
const files = (await (0, __WEBPACK_EXTERNAL_MODULE_tinyglobby__.glob)([
|
|
406
349
|
`**/*.{${extensions.join(',')}}`,
|
|
407
|
-
...
|
|
350
|
+
...this.#include
|
|
408
351
|
], {
|
|
409
|
-
cwd:
|
|
352
|
+
cwd: this.#scanDir,
|
|
410
353
|
absolute: true,
|
|
411
354
|
onlyFiles: true,
|
|
412
355
|
ignore: [
|
|
413
|
-
...
|
|
356
|
+
...this.#exclude,
|
|
414
357
|
'**/node_modules/**',
|
|
415
358
|
'**/.eslintrc.js',
|
|
416
359
|
'**/.nx/**',
|
|
@@ -418,9 +361,9 @@ class RouteService {
|
|
|
418
361
|
]
|
|
419
362
|
})).sort();
|
|
420
363
|
files.forEach((filePath)=>{
|
|
421
|
-
const fileRelativePath = normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(
|
|
364
|
+
const fileRelativePath = normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(this.#scanDir, filePath));
|
|
422
365
|
const { routePath, lang, version } = this.normalizeRoutePath(fileRelativePath);
|
|
423
|
-
const absolutePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(
|
|
366
|
+
const absolutePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(this.#scanDir, fileRelativePath);
|
|
424
367
|
const routeInfo = {
|
|
425
368
|
routePath,
|
|
426
369
|
absolutePath: normalizePath(absolutePath),
|
|
@@ -431,32 +374,32 @@ class RouteService {
|
|
|
431
374
|
};
|
|
432
375
|
this.addRoute(routeInfo);
|
|
433
376
|
});
|
|
434
|
-
const externalPages = await
|
|
377
|
+
const externalPages = await this.#pluginDriver.addPages();
|
|
435
378
|
await Promise.all(externalPages.map(async (route, index)=>{
|
|
436
379
|
const { routePath, content, filepath } = route;
|
|
437
380
|
if (filepath) {
|
|
438
|
-
const routeInfo =
|
|
381
|
+
const routeInfo = this.#generateRouteInfo(routePath, filepath);
|
|
439
382
|
this.addRoute(routeInfo);
|
|
440
383
|
return;
|
|
441
384
|
}
|
|
442
385
|
if (content) {
|
|
443
|
-
const filepath = await
|
|
444
|
-
const routeInfo =
|
|
386
|
+
const filepath = await this.#writeTempFile(index, content);
|
|
387
|
+
const routeInfo = this.#generateRouteInfo(routePath, filepath);
|
|
445
388
|
this.addRoute(routeInfo);
|
|
446
389
|
}
|
|
447
390
|
}));
|
|
448
|
-
await
|
|
391
|
+
await this.#pluginDriver.routeGenerated(this.getRoutes());
|
|
449
392
|
}
|
|
450
393
|
addRoute(routeInfo) {
|
|
451
394
|
const { routePath, absolutePath } = routeInfo;
|
|
452
395
|
if (this.routeData.has(routePath)) {
|
|
453
|
-
const preRouteExtIndex =
|
|
454
|
-
const currRouteExtIndex =
|
|
396
|
+
const preRouteExtIndex = this.#extensions.indexOf(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(this.routeData.get(routePath).absolutePath));
|
|
397
|
+
const currRouteExtIndex = this.#extensions.indexOf(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(absolutePath));
|
|
455
398
|
if (-1 !== currRouteExtIndex && (currRouteExtIndex < preRouteExtIndex || -1 === preRouteExtIndex)) this.routeData.set(routePath, routeInfo);
|
|
456
399
|
} else this.routeData.set(routePath, routeInfo);
|
|
457
400
|
}
|
|
458
401
|
removeRoute(filePath) {
|
|
459
|
-
const fileRelativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(
|
|
402
|
+
const fileRelativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(this.#scanDir, filePath);
|
|
460
403
|
const { routePath } = this.normalizeRoutePath(fileRelativePath);
|
|
461
404
|
this.routeData.delete(routePath);
|
|
462
405
|
}
|
|
@@ -491,125 +434,49 @@ ${routeMeta.map((route, index)=>{
|
|
|
491
434
|
`;
|
|
492
435
|
}
|
|
493
436
|
getRoutePathParts(routePath) {
|
|
494
|
-
return getRoutePathParts(routePath,
|
|
437
|
+
return getRoutePathParts(routePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions);
|
|
495
438
|
}
|
|
496
439
|
normalizeRoutePath(routePath) {
|
|
497
|
-
return normalizeRoutePath(routePath,
|
|
440
|
+
return normalizeRoutePath(routePath, this.#base, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions, this.#extensions);
|
|
498
441
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
value: ''
|
|
515
|
-
});
|
|
516
|
-
RouteService_class_private_field_init(this, _extensions, {
|
|
517
|
-
writable: true,
|
|
518
|
-
value: []
|
|
519
|
-
});
|
|
520
|
-
RouteService_class_private_field_init(this, _langs, {
|
|
521
|
-
writable: true,
|
|
522
|
-
value: []
|
|
523
|
-
});
|
|
524
|
-
RouteService_class_private_field_init(this, _versions, {
|
|
525
|
-
writable: true,
|
|
526
|
-
value: []
|
|
527
|
-
});
|
|
528
|
-
RouteService_class_private_field_init(this, _include, {
|
|
529
|
-
writable: true,
|
|
530
|
-
value: []
|
|
531
|
-
});
|
|
532
|
-
RouteService_class_private_field_init(this, _exclude, {
|
|
533
|
-
writable: true,
|
|
534
|
-
value: []
|
|
535
|
-
});
|
|
536
|
-
RouteService_class_private_field_init(this, _base, {
|
|
537
|
-
writable: true,
|
|
538
|
-
value: ''
|
|
539
|
-
});
|
|
540
|
-
RouteService_class_private_field_init(this, _tempDir, {
|
|
541
|
-
writable: true,
|
|
542
|
-
value: ''
|
|
543
|
-
});
|
|
544
|
-
RouteService_class_private_field_init(this, _pluginDriver, {
|
|
545
|
-
writable: true,
|
|
546
|
-
value: void 0
|
|
547
|
-
});
|
|
548
|
-
const routeOptions = (null == userConfig ? void 0 : userConfig.route) || {};
|
|
549
|
-
RouteService_class_private_field_set(this, _scanDir, scanDir);
|
|
550
|
-
RouteService_class_private_field_set(this, _extensions, routeOptions.extensions || __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS);
|
|
551
|
-
RouteService_class_private_field_set(this, _include, routeOptions.include || []);
|
|
552
|
-
RouteService_class_private_field_set(this, _exclude, routeOptions.exclude || []);
|
|
553
|
-
RouteService_class_private_field_set(this, _defaultLang, (null == userConfig ? void 0 : userConfig.lang) || '');
|
|
554
|
-
RouteService_class_private_field_set(this, _langs, ((null == userConfig ? void 0 : userConfig.locales) ?? (null == userConfig ? void 0 : null == (_userConfig_themeConfig = userConfig.themeConfig) ? void 0 : _userConfig_themeConfig.locales) ?? []).map((item)=>item.lang));
|
|
555
|
-
RouteService_class_private_field_set(this, _base, (null == userConfig ? void 0 : userConfig.base) || '');
|
|
556
|
-
RouteService_class_private_field_set(this, _tempDir, tempDir);
|
|
557
|
-
RouteService_class_private_field_set(this, _pluginDriver, pluginDriver);
|
|
558
|
-
if (userConfig.multiVersion) {
|
|
559
|
-
RouteService_class_private_field_set(this, _defaultVersion, userConfig.multiVersion.default || '');
|
|
560
|
-
RouteService_class_private_field_set(this, _versions, userConfig.multiVersion.versions || []);
|
|
561
|
-
}
|
|
442
|
+
async #writeTempFile(index, content) {
|
|
443
|
+
const tempFilePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(this.#tempDir, `temp-${index}.mdx`);
|
|
444
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(tempFilePath, content);
|
|
445
|
+
return tempFilePath;
|
|
446
|
+
}
|
|
447
|
+
#generateRouteInfo(routePath, filepath) {
|
|
448
|
+
const { routePath: normalizedPath, lang, version } = this.normalizeRoutePath(routePath);
|
|
449
|
+
return {
|
|
450
|
+
routePath: normalizedPath,
|
|
451
|
+
absolutePath: normalizePath(filepath),
|
|
452
|
+
relativePath: normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(this.#scanDir, filepath)),
|
|
453
|
+
pageName: getPageKey(routePath),
|
|
454
|
+
lang,
|
|
455
|
+
version
|
|
456
|
+
};
|
|
562
457
|
}
|
|
563
|
-
}
|
|
564
|
-
async function writeTempFile(index, content) {
|
|
565
|
-
const tempFilePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(RouteService_class_private_field_get(this, _tempDir), `temp-${index}.mdx`);
|
|
566
|
-
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(tempFilePath, content);
|
|
567
|
-
return tempFilePath;
|
|
568
|
-
}
|
|
569
|
-
function generateRouteInfo(routePath, filepath) {
|
|
570
|
-
const { routePath: normalizedPath, lang, version } = this.normalizeRoutePath(routePath);
|
|
571
|
-
return {
|
|
572
|
-
routePath: normalizedPath,
|
|
573
|
-
absolutePath: normalizePath(filepath),
|
|
574
|
-
relativePath: normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(RouteService_class_private_field_get(this, _scanDir), filepath)),
|
|
575
|
-
pageName: getPageKey(routePath),
|
|
576
|
-
lang,
|
|
577
|
-
version
|
|
578
|
-
};
|
|
579
458
|
}
|
|
580
459
|
let init_routeService = null;
|
|
581
460
|
async function initRouteService(options) {
|
|
582
461
|
const { scanDir, config, runtimeTempDir, pluginDriver } = options;
|
|
583
462
|
init_routeService = new RouteService(scanDir, config, runtimeTempDir, pluginDriver);
|
|
584
463
|
await init_routeService.init();
|
|
464
|
+
await pluginDriver.routeServiceGenerated(init_routeService);
|
|
585
465
|
return init_routeService;
|
|
586
466
|
}
|
|
467
|
+
function createHash(str) {
|
|
468
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__.createHash)('sha256').update(str).digest('hex').slice(0, 8);
|
|
469
|
+
}
|
|
587
470
|
var types_RuntimeModuleID = /*#__PURE__*/ function(RuntimeModuleID) {
|
|
588
471
|
RuntimeModuleID["GlobalStyles"] = "virtual-global-styles";
|
|
589
472
|
RuntimeModuleID["GlobalComponents"] = "virtual-global-components";
|
|
590
|
-
RuntimeModuleID["
|
|
591
|
-
RuntimeModuleID["RouteForSSR"] = "virtual-routes-ssr";
|
|
473
|
+
RuntimeModuleID["Routes"] = "virtual-routes";
|
|
592
474
|
RuntimeModuleID["SiteData"] = "virtual-site-data";
|
|
593
475
|
RuntimeModuleID["SearchIndexHash"] = "virtual-search-index-hash";
|
|
594
476
|
RuntimeModuleID["I18nText"] = "virtual-i18n-text";
|
|
595
477
|
RuntimeModuleID["SearchHooks"] = "virtual-search-hooks";
|
|
596
|
-
RuntimeModuleID["PrismLanguages"] = "virtual-prism-languages";
|
|
597
478
|
return RuntimeModuleID;
|
|
598
479
|
}({});
|
|
599
|
-
async function routeVMPlugin(context) {
|
|
600
|
-
const { routeService, isSSR } = context;
|
|
601
|
-
if (!isSSR) return {
|
|
602
|
-
[types_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
|
|
603
|
-
[types_RuntimeModuleID.RouteForSSR]: ''
|
|
604
|
-
};
|
|
605
|
-
return {
|
|
606
|
-
[types_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
|
|
607
|
-
[types_RuntimeModuleID.RouteForSSR]: routeService.generateRoutesCode(true)
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
function createHash(str) {
|
|
611
|
-
return (0, __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__.createHash)('sha256').update(str).digest('hex').slice(0, 8);
|
|
612
|
-
}
|
|
613
480
|
let flattenMdxContent_resolver;
|
|
614
481
|
let startFlatten = false;
|
|
615
482
|
const processor = (0, __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__.createProcessor)();
|
|
@@ -665,10 +532,7 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
665
532
|
deps
|
|
666
533
|
};
|
|
667
534
|
}
|
|
668
|
-
const importNodes = ast.children.filter((node)=>'mdxjsEsm' === node.type).flatMap((node)=>
|
|
669
|
-
var _node_data_estree, _node_data;
|
|
670
|
-
return (null == (_node_data = node.data) ? void 0 : null == (_node_data_estree = _node_data.estree) ? void 0 : _node_data_estree.body) || [];
|
|
671
|
-
}).filter((node)=>'ImportDeclaration' === node.type);
|
|
535
|
+
const importNodes = ast.children.filter((node)=>'mdxjsEsm' === node.type).flatMap((node)=>node.data?.estree?.body || []).filter((node)=>'ImportDeclaration' === node.type);
|
|
672
536
|
for (const importNode of importNodes){
|
|
673
537
|
const id = importNode.specifiers[0].local.name;
|
|
674
538
|
const importPath = importNode.source.value;
|
|
@@ -706,6 +570,7 @@ async function extractPageData(replaceRules, alias, domain, root, routeService,
|
|
|
706
570
|
id: index,
|
|
707
571
|
title: '',
|
|
708
572
|
content: '',
|
|
573
|
+
_flattenContent: '',
|
|
709
574
|
_html: '',
|
|
710
575
|
routePath: route.routePath,
|
|
711
576
|
lang: route.lang,
|
|
@@ -718,9 +583,9 @@ async function extractPageData(replaceRules, alias, domain, root, routeService,
|
|
|
718
583
|
};
|
|
719
584
|
if (!__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_OR_MD_REGEXP.test(route.absolutePath)) return defaultIndexInfo;
|
|
720
585
|
let content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, 'utf8');
|
|
721
|
-
const { frontmatter, content:
|
|
586
|
+
const { frontmatter, content: contentWithoutFrontMatter } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.loadFrontMatter)(content, route.absolutePath, root);
|
|
722
587
|
applyReplaceRulesToNestedObject(frontmatter, replaceRules);
|
|
723
|
-
const { flattenContent } = await flattenMdxContent(applyReplaceRules(
|
|
588
|
+
const { flattenContent } = await flattenMdxContent(applyReplaceRules(contentWithoutFrontMatter, replaceRules), route.absolutePath, alias);
|
|
724
589
|
content = flattenContent.replace(importStatementRegex, '');
|
|
725
590
|
const { html: rawHtml, title, toc: rawToc, languages } = await (0, __WEBPACK_EXTERNAL_MODULE__rspress_mdx_rs_d2f3021f__.compile)({
|
|
726
591
|
value: content,
|
|
@@ -789,6 +654,7 @@ async function extractPageData(replaceRules, alias, domain, root, routeService,
|
|
|
789
654
|
title: frontmatter.title || title,
|
|
790
655
|
toc,
|
|
791
656
|
content,
|
|
657
|
+
_flattenContent: flattenContent,
|
|
792
658
|
_html: html,
|
|
793
659
|
frontmatter: {
|
|
794
660
|
...frontmatter,
|
|
@@ -798,45 +664,6 @@ async function extractPageData(replaceRules, alias, domain, root, routeService,
|
|
|
798
664
|
}));
|
|
799
665
|
return pageData.filter(Boolean);
|
|
800
666
|
}
|
|
801
|
-
const highlightLanguages_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url);
|
|
802
|
-
let highlightLanguages_supportedLanguages;
|
|
803
|
-
function handleHighlightLanguages(highlightLanguages, defaultLanguages) {
|
|
804
|
-
const aliases = {};
|
|
805
|
-
if (highlightLanguages.size) {
|
|
806
|
-
if (!highlightLanguages_supportedLanguages) {
|
|
807
|
-
const langs = highlightLanguages_require('react-syntax-highlighter/dist/cjs/languages/prism/supported-languages').default;
|
|
808
|
-
highlightLanguages_supportedLanguages = new Set(langs);
|
|
809
|
-
}
|
|
810
|
-
let useDeprecatedTypeWarning = true;
|
|
811
|
-
const names = {};
|
|
812
|
-
[
|
|
813
|
-
...__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.DEFAULT_HIGHLIGHT_LANGUAGES,
|
|
814
|
-
...defaultLanguages
|
|
815
|
-
].forEach((lang)=>{
|
|
816
|
-
if (Array.isArray(lang)) {
|
|
817
|
-
const [alias, name] = lang;
|
|
818
|
-
names[alias] = name;
|
|
819
|
-
} else if (useDeprecatedTypeWarning) {
|
|
820
|
-
console.log(`${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellowBright('warning')} Automatic import is supported. \`highlightLanguages\` is now used only as alias, and string types will be ignored. \n`);
|
|
821
|
-
useDeprecatedTypeWarning = false;
|
|
822
|
-
}
|
|
823
|
-
});
|
|
824
|
-
[
|
|
825
|
-
...highlightLanguages.values()
|
|
826
|
-
].forEach((lang)=>{
|
|
827
|
-
const name = names[lang];
|
|
828
|
-
if (name && highlightLanguages_supportedLanguages.has(name)) {
|
|
829
|
-
const temp = aliases[name] || (aliases[name] = []);
|
|
830
|
-
if (!temp.includes(lang)) temp.push(lang);
|
|
831
|
-
highlightLanguages.delete(lang);
|
|
832
|
-
highlightLanguages.add(name);
|
|
833
|
-
return;
|
|
834
|
-
}
|
|
835
|
-
if (!highlightLanguages_supportedLanguages.has(lang)) highlightLanguages.delete(lang);
|
|
836
|
-
});
|
|
837
|
-
}
|
|
838
|
-
return aliases;
|
|
839
|
-
}
|
|
840
667
|
const DEFAULT_I18N_SOURCE = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), 'i18n.json');
|
|
841
668
|
function getI18nData(docConfig) {
|
|
842
669
|
const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
|
|
@@ -866,7 +693,7 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
866
693
|
const hasMultiVersion = versions.length > 0;
|
|
867
694
|
docConfig.themeConfig = docConfig.themeConfig || {};
|
|
868
695
|
const { themeConfig } = docConfig;
|
|
869
|
-
const locales = siteLocales ?? (
|
|
696
|
+
const locales = siteLocales ?? (themeConfig?.locales || []);
|
|
870
697
|
const i18nTextData = getI18nData(docConfig);
|
|
871
698
|
const normalizeLinkPrefix = (link = '', currentLang = '')=>{
|
|
872
699
|
const normalizedLink = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(link);
|
|
@@ -874,8 +701,7 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
874
701
|
return lang === currentLang ? normalizedLink : `/${currentLang}${(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)(normalizedLink)}`;
|
|
875
702
|
};
|
|
876
703
|
const getI18nText = (key = '', currentLang = '')=>{
|
|
877
|
-
|
|
878
|
-
const text = null == (_i18nTextData_key = i18nTextData[key]) ? void 0 : _i18nTextData_key[currentLang];
|
|
704
|
+
const text = i18nTextData[key]?.[currentLang];
|
|
879
705
|
return text || key;
|
|
880
706
|
};
|
|
881
707
|
const normalizeSidebar = (sidebar, currentLang = '')=>{
|
|
@@ -900,9 +726,9 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
900
726
|
const normalizedItem = normalizeLinkPrefix(item, currentLang);
|
|
901
727
|
const page = pages.find((page)=>page.routePath === (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(normalizedItem, base));
|
|
902
728
|
return {
|
|
903
|
-
text: applyReplaceRules(
|
|
729
|
+
text: applyReplaceRules(page?.title || '', replaceRules),
|
|
904
730
|
link: normalizedItem,
|
|
905
|
-
_fileKey:
|
|
731
|
+
_fileKey: page?._relativePath.replace(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(page._relativePath), '')
|
|
906
732
|
};
|
|
907
733
|
}
|
|
908
734
|
return {
|
|
@@ -948,19 +774,18 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
948
774
|
}, {});
|
|
949
775
|
};
|
|
950
776
|
if (locales.length) themeConfig.locales = locales.map(({ lang: currentLang, label })=>{
|
|
951
|
-
|
|
952
|
-
const localeInThemeConfig = null == (_themeConfig_locales = themeConfig.locales) ? void 0 : _themeConfig_locales.find((locale)=>locale.lang === currentLang);
|
|
777
|
+
const localeInThemeConfig = themeConfig.locales?.find((locale)=>locale.lang === currentLang);
|
|
953
778
|
return {
|
|
954
779
|
lang: currentLang,
|
|
955
780
|
label,
|
|
956
781
|
...localeInThemeConfig || {},
|
|
957
|
-
sidebar: normalizeSidebar(
|
|
958
|
-
nav: normalizeNav(
|
|
782
|
+
sidebar: normalizeSidebar(localeInThemeConfig?.sidebar ?? themeConfig.sidebar, currentLang),
|
|
783
|
+
nav: normalizeNav(localeInThemeConfig?.nav ?? themeConfig.nav, currentLang)
|
|
959
784
|
};
|
|
960
785
|
});
|
|
961
786
|
else {
|
|
962
|
-
themeConfig.sidebar = normalizeSidebar(
|
|
963
|
-
themeConfig.nav = normalizeNav(
|
|
787
|
+
themeConfig.sidebar = normalizeSidebar(themeConfig?.sidebar);
|
|
788
|
+
themeConfig.nav = normalizeNav(themeConfig?.nav);
|
|
964
789
|
}
|
|
965
790
|
return themeConfig;
|
|
966
791
|
}
|
|
@@ -973,22 +798,20 @@ function deletePrivateField(obj) {
|
|
|
973
798
|
return newObj;
|
|
974
799
|
}
|
|
975
800
|
async function siteDataVMPlugin(context) {
|
|
976
|
-
var _userConfig_themeConfig, _userConfig_multiVersion, _userConfig_multiVersion1, _userConfig_markdown, _userConfig_markdown1, _userConfig_markdown2, _siteData_pages_;
|
|
977
801
|
const { config, alias, userDocRoot, routeService, pluginDriver } = context;
|
|
978
802
|
const userConfig = config;
|
|
979
803
|
const tempSearchObj = Object.assign({}, userConfig.search);
|
|
980
804
|
if (tempSearchObj) tempSearchObj.searchHooks = void 0;
|
|
981
805
|
const highlightLanguages = new Set();
|
|
982
|
-
const replaceRules =
|
|
983
|
-
const searchConfig =
|
|
984
|
-
const domain =
|
|
806
|
+
const replaceRules = userConfig?.replaceRules || [];
|
|
807
|
+
const searchConfig = userConfig?.search || {};
|
|
808
|
+
const domain = searchConfig?.mode === 'remote' ? searchConfig.domain ?? '' : '';
|
|
985
809
|
const searchCodeBlocks = 'codeBlocks' in searchConfig ? Boolean(searchConfig.codeBlocks) : true;
|
|
986
810
|
const pages = await extractPageData(replaceRules, alias, domain, userDocRoot, routeService, highlightLanguages, searchCodeBlocks);
|
|
987
811
|
await pluginDriver.modifySearchIndexData(pages);
|
|
988
812
|
const versioned = userConfig.search && 'remote' !== userConfig.search.mode && userConfig.search.versioned;
|
|
989
813
|
const groupedPages = (0, __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__.groupBy)(pages, (page)=>{
|
|
990
|
-
|
|
991
|
-
if ((null == (_page_frontmatter = page.frontmatter) ? void 0 : _page_frontmatter.pageType) === 'home') return 'noindex';
|
|
814
|
+
if (page.frontmatter?.pageType === 'home') return 'noindex';
|
|
992
815
|
const version = versioned ? page.version : '';
|
|
993
816
|
const lang = page.lang || '';
|
|
994
817
|
return `${version}###${lang}`;
|
|
@@ -1009,55 +832,44 @@ async function siteDataVMPlugin(context) {
|
|
|
1009
832
|
}));
|
|
1010
833
|
await Promise.all(pages.map(async (pageData)=>pluginDriver.extendPageData(pageData)));
|
|
1011
834
|
const siteData = {
|
|
1012
|
-
title:
|
|
1013
|
-
description:
|
|
1014
|
-
icon: (
|
|
1015
|
-
route:
|
|
835
|
+
title: userConfig?.title || '',
|
|
836
|
+
description: userConfig?.description || '',
|
|
837
|
+
icon: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getIconUrlPath)(userConfig?.icon) || '',
|
|
838
|
+
route: userConfig?.route || {},
|
|
1016
839
|
themeConfig: normalizeThemeConfig(userConfig, pages),
|
|
1017
|
-
base:
|
|
1018
|
-
lang:
|
|
1019
|
-
locales:
|
|
1020
|
-
logo:
|
|
1021
|
-
logoText:
|
|
1022
|
-
ssg: Boolean(
|
|
840
|
+
base: userConfig?.base || '/',
|
|
841
|
+
lang: userConfig?.lang || '',
|
|
842
|
+
locales: userConfig?.locales || userConfig.themeConfig?.locales || [],
|
|
843
|
+
logo: userConfig?.logo || '',
|
|
844
|
+
logoText: userConfig?.logoText || '',
|
|
845
|
+
ssg: Boolean(userConfig?.ssg ?? true),
|
|
1023
846
|
multiVersion: {
|
|
1024
|
-
default:
|
|
1025
|
-
versions:
|
|
847
|
+
default: userConfig?.multiVersion?.default || '',
|
|
848
|
+
versions: userConfig?.multiVersion?.versions || []
|
|
1026
849
|
},
|
|
1027
850
|
search: tempSearchObj ?? {
|
|
1028
851
|
mode: 'local'
|
|
1029
852
|
},
|
|
1030
853
|
pages: pages.map((page)=>{
|
|
1031
|
-
const { content, id, domain, _filepath, _html, ...rest } = page;
|
|
854
|
+
const { content, id, domain, _filepath, _html, _flattenContent, ...rest } = page;
|
|
1032
855
|
return isProduction() ? rest : {
|
|
1033
856
|
...rest,
|
|
1034
857
|
_filepath
|
|
1035
858
|
};
|
|
1036
859
|
}),
|
|
1037
860
|
markdown: {
|
|
1038
|
-
showLineNumbers:
|
|
1039
|
-
defaultWrapCode:
|
|
1040
|
-
|
|
861
|
+
showLineNumbers: userConfig?.markdown?.showLineNumbers ?? false,
|
|
862
|
+
defaultWrapCode: userConfig?.markdown?.defaultWrapCode ?? false,
|
|
863
|
+
shiki: {}
|
|
1041
864
|
}
|
|
1042
865
|
};
|
|
1043
|
-
|
|
1044
|
-
if (Array.isArray(null == (_siteData_pages_ = siteData.pages[0]) ? void 0 : _siteData_pages_.extraHighlightLanguages)) siteData.pages[0].extraHighlightLanguages.forEach((lang)=>highlightLanguages.add(lang));
|
|
1045
|
-
const aliases = handleHighlightLanguages(highlightLanguages, defaultLanguages);
|
|
1046
|
-
const sortedAliases = Object.fromEntries(Object.entries(aliases).sort());
|
|
1047
|
-
const sortedHighlightLanguages = Array.from(highlightLanguages).sort();
|
|
866
|
+
if (Array.isArray(siteData.pages[0]?.extraHighlightLanguages)) siteData.pages[0].extraHighlightLanguages.forEach((lang)=>highlightLanguages.add(lang));
|
|
1048
867
|
return {
|
|
1049
868
|
[`${types_RuntimeModuleID.SiteData}.mjs`]: `export default ${JSON.stringify(siteData, null, 2)}`,
|
|
1050
|
-
[types_RuntimeModuleID.SearchIndexHash]: `export default ${JSON.stringify(indexHashByGroup, null, 2)}
|
|
1051
|
-
[types_RuntimeModuleID.PrismLanguages]: `export const aliases = ${JSON.stringify(sortedAliases, null, 2)};
|
|
1052
|
-
export const languages = {
|
|
1053
|
-
${sortedHighlightLanguages.map((lang)=>`"${lang}": require(
|
|
1054
|
-
"react-syntax-highlighter/dist/cjs/languages/prism/${lang}"
|
|
1055
|
-
).default`)}
|
|
1056
|
-
}`
|
|
869
|
+
[types_RuntimeModuleID.SearchIndexHash]: `export default ${JSON.stringify(indexHashByGroup, null, 2)}`
|
|
1057
870
|
};
|
|
1058
871
|
}
|
|
1059
872
|
const runtimeModuleFactory = [
|
|
1060
|
-
routeVMPlugin,
|
|
1061
873
|
siteDataVMPlugin
|
|
1062
874
|
];
|
|
1063
875
|
function rsbuildPluginDocVM(factoryContext) {
|
|
@@ -1065,14 +877,12 @@ function rsbuildPluginDocVM(factoryContext) {
|
|
|
1065
877
|
return {
|
|
1066
878
|
name: 'rsbuild-plugin-doc-vm',
|
|
1067
879
|
setup (api) {
|
|
1068
|
-
api.modifyBundlerChain(async (bundlerChain
|
|
1069
|
-
const isServer = 'node' === target;
|
|
880
|
+
api.modifyBundlerChain(async (bundlerChain)=>{
|
|
1070
881
|
const alias = bundlerChain.resolve.alias.entries();
|
|
1071
882
|
const runtimeModule = {};
|
|
1072
883
|
for (const factory of runtimeModuleFactory){
|
|
1073
884
|
const moduleResult = await factory({
|
|
1074
885
|
...factoryContext,
|
|
1075
|
-
isSSR: isServer,
|
|
1076
886
|
alias: alias
|
|
1077
887
|
});
|
|
1078
888
|
Object.assign(runtimeModule, moduleResult);
|
|
@@ -1082,7 +892,7 @@ function rsbuildPluginDocVM(factoryContext) {
|
|
|
1082
892
|
if (runtimeModule[key]) throw new Error(`The runtime module ${key} is duplicated, please check your plugin`);
|
|
1083
893
|
runtimeModule[key] = modulesByPlugin[key];
|
|
1084
894
|
});
|
|
1085
|
-
bundlerChain.plugin('rspress-runtime-module').use(new __WEBPACK_EXTERNAL_MODULE_rspack_plugin_virtual_module_609978fd__.RspackVirtualModulePlugin(runtimeModule
|
|
895
|
+
bundlerChain.plugin('rspress-runtime-module').use(new __WEBPACK_EXTERNAL_MODULE_rspack_plugin_virtual_module_609978fd__.RspackVirtualModulePlugin(runtimeModule));
|
|
1086
896
|
});
|
|
1087
897
|
}
|
|
1088
898
|
};
|
|
@@ -1092,7 +902,7 @@ const globalStylesVMPlugin = (context)=>({
|
|
|
1092
902
|
const { config, pluginDriver } = context;
|
|
1093
903
|
const globalStylesByPlugins = pluginDriver.globalStyles();
|
|
1094
904
|
const moduleContent = [
|
|
1095
|
-
|
|
905
|
+
config?.globalStyles,
|
|
1096
906
|
...globalStylesByPlugins
|
|
1097
907
|
].filter(Boolean).map((source)=>`import ${JSON.stringify(source)};`).join('');
|
|
1098
908
|
return moduleContent;
|
|
@@ -1104,7 +914,7 @@ const globalUIComponentsVMPlugin = (context)=>({
|
|
|
1104
914
|
let index = 0;
|
|
1105
915
|
const globalUIComponentsByPlugins = pluginDriver.globalUIComponents();
|
|
1106
916
|
const globalComponents = [
|
|
1107
|
-
...
|
|
917
|
+
...config?.globalUIComponents || [],
|
|
1108
918
|
...globalUIComponentsByPlugins
|
|
1109
919
|
];
|
|
1110
920
|
const moduleContent = globalComponents.map((source)=>{
|
|
@@ -1122,6 +932,12 @@ const Props_${index++} = ${JSON.stringify(source[1])};\n`;
|
|
|
1122
932
|
return moduleContent;
|
|
1123
933
|
}
|
|
1124
934
|
});
|
|
935
|
+
const routeListVMPlugin = (context)=>{
|
|
936
|
+
const { routeService } = context;
|
|
937
|
+
return {
|
|
938
|
+
[types_RuntimeModuleID.Routes]: ({ environment })=>'node' === environment.name ? routeService.generateRoutesCode(true) : routeService.generateRoutesCode(false)
|
|
939
|
+
};
|
|
940
|
+
};
|
|
1125
941
|
const searchHookVMPlugin = (context)=>({
|
|
1126
942
|
[`${types_RuntimeModuleID.SearchHooks}`]: ()=>{
|
|
1127
943
|
const { config } = context;
|
|
@@ -1131,11 +947,10 @@ const searchHookVMPlugin = (context)=>({
|
|
|
1131
947
|
}
|
|
1132
948
|
});
|
|
1133
949
|
async function writeSearchIndex(config) {
|
|
1134
|
-
|
|
1135
|
-
if ((null == config ? void 0 : config.search) === false) return;
|
|
950
|
+
if (config?.search === false) return;
|
|
1136
951
|
const cwd = process.cwd();
|
|
1137
952
|
const searchIndexFiles = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readdir(constants_TEMP_DIR);
|
|
1138
|
-
const outDir =
|
|
953
|
+
const outDir = config?.outDir ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, OUTPUT_DIR);
|
|
1139
954
|
const targetDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outDir, 'static');
|
|
1140
955
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(targetDir, {
|
|
1141
956
|
recursive: true
|
|
@@ -1151,7 +966,7 @@ async function writeSearchIndex(config) {
|
|
|
1151
966
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].rename(source, target);
|
|
1152
967
|
scanning = true;
|
|
1153
968
|
}
|
|
1154
|
-
if (isProduction() && (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isSCM)() &&
|
|
969
|
+
if (isProduction() && (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isSCM)() && config?.search?.mode === 'remote') {
|
|
1155
970
|
const { apiUrl, indexName } = config.search;
|
|
1156
971
|
try {
|
|
1157
972
|
await fetch(`${apiUrl}?index=${indexName}`, {
|
|
@@ -1169,16 +984,15 @@ async function writeSearchIndex(config) {
|
|
|
1169
984
|
}
|
|
1170
985
|
function serveSearchIndexMiddleware(config) {
|
|
1171
986
|
return (req, res, next)=>{
|
|
1172
|
-
var _req_url;
|
|
1173
987
|
const searchIndexRequestMatch = `/${__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME}.`;
|
|
1174
|
-
if (
|
|
988
|
+
if (req.url?.includes(searchIndexRequestMatch)) {
|
|
1175
989
|
res.setHeader('Content-Type', 'application/json');
|
|
1176
|
-
const outDir =
|
|
990
|
+
const outDir = config?.outDir ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), OUTPUT_DIR);
|
|
1177
991
|
const searchIndexFile = req.url.split('/').pop();
|
|
1178
992
|
(0, __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.createReadStream)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outDir, 'static', searchIndexFile), 'utf-8').pipe(res, {
|
|
1179
993
|
end: true
|
|
1180
994
|
});
|
|
1181
|
-
} else
|
|
995
|
+
} else next?.();
|
|
1182
996
|
};
|
|
1183
997
|
}
|
|
1184
998
|
async function renderFrontmatterHead(route) {
|
|
@@ -1231,7 +1045,7 @@ async function renderPages(routeService, config, pluginDriver, ssrBundlePath, ht
|
|
|
1231
1045
|
}
|
|
1232
1046
|
try {
|
|
1233
1047
|
const routes = routeService.getRoutes();
|
|
1234
|
-
const base =
|
|
1048
|
+
const base = config?.base ?? '';
|
|
1235
1049
|
const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route)=>({
|
|
1236
1050
|
routePath: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(route.path, base)
|
|
1237
1051
|
}));
|
|
@@ -1244,36 +1058,24 @@ async function renderPages(routeService, config, pluginDriver, ssrBundlePath, ht
|
|
|
1244
1058
|
routePath: '/404'
|
|
1245
1059
|
});
|
|
1246
1060
|
await Promise.all(allRoutes.filter((route)=>!route.routePath.includes(':')).map(async (route)=>{
|
|
1247
|
-
const
|
|
1061
|
+
const head = (0, __WEBPACK_EXTERNAL_MODULE__unhead_react_server_7e85c952__.createHead)();
|
|
1248
1062
|
const { routePath } = route;
|
|
1249
1063
|
let appHtml = '';
|
|
1250
1064
|
if (render) try {
|
|
1251
|
-
({ appHtml } = await render(routePath,
|
|
1065
|
+
({ appHtml } = await render(routePath, head));
|
|
1252
1066
|
} catch (e) {
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1067
|
+
if (e instanceof Error) {
|
|
1068
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering failed.\n ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(e.toString())}`);
|
|
1069
|
+
throw e;
|
|
1070
|
+
}
|
|
1256
1071
|
}
|
|
1257
|
-
const
|
|
1258
|
-
let html = htmlTemplate.replace(/<title>(.*?)<\/title>/gi, '').replace(APP_HTML_MARKER, ()=>appHtml).replace(META_GENERATOR, ()=>`<meta name="generator" content="Rspress v${RSPRESS_VERSION}">`).replace(HEAD_MARKER, [
|
|
1072
|
+
const replacedHtmlTemplate = htmlTemplate.replace(/<title>(.*?)<\/title>/gi, '').replace(APP_HTML_MARKER, ()=>appHtml).replace(META_GENERATOR, ()=>`<meta name="generator" content="Rspress v${RSPRESS_VERSION}">`).replace(HEAD_MARKER, [
|
|
1259
1073
|
await renderConfigHead(config, route),
|
|
1260
|
-
helmet.title.toString(),
|
|
1261
|
-
helmet.meta.toString(),
|
|
1262
|
-
helmet.link.toString(),
|
|
1263
|
-
helmet.style.toString(),
|
|
1264
|
-
helmet.script.toString(),
|
|
1265
1074
|
await renderFrontmatterHead(route)
|
|
1266
1075
|
].join(''));
|
|
1267
|
-
|
|
1268
|
-
var _helmet_htmlAttributes;
|
|
1269
|
-
html = html.replace(HTML_START_TAG, `${HTML_START_TAG} ${null == (_helmet_htmlAttributes = helmet.htmlAttributes) ? void 0 : _helmet_htmlAttributes.toString()}`);
|
|
1270
|
-
}
|
|
1271
|
-
if (helmet.bodyAttributes) {
|
|
1272
|
-
var _helmet_bodyAttributes;
|
|
1273
|
-
html = html.replace(BODY_START_TAG, `${BODY_START_TAG} ${null == (_helmet_bodyAttributes = helmet.bodyAttributes) ? void 0 : _helmet_bodyAttributes.toString()}`);
|
|
1274
|
-
}
|
|
1076
|
+
const html = await (0, __WEBPACK_EXTERNAL_MODULE__unhead_react_server_7e85c952__.transformHtmlTemplate)(head, replacedHtmlTemplate);
|
|
1275
1077
|
const normalizeHtmlFilePath = (path)=>{
|
|
1276
|
-
const normalizedBase = `${(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeSlash)(
|
|
1078
|
+
const normalizedBase = `${(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeSlash)(config?.base || '/')}/`;
|
|
1277
1079
|
if (path.endsWith('/')) return `${path}index.html`.replace(normalizedBase, '');
|
|
1278
1080
|
return `${path}.html`.replace(normalizedBase, '');
|
|
1279
1081
|
};
|
|
@@ -1346,17 +1148,49 @@ const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
|
|
|
1346
1148
|
}
|
|
1347
1149
|
});
|
|
1348
1150
|
const { CachedInputFileSystem: detectReactVersion_CachedInputFileSystem, ResolverFactory: detectReactVersion_ResolverFactory } = __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__["default"];
|
|
1349
|
-
|
|
1350
|
-
async function detectReactVersion() {
|
|
1151
|
+
async function detectPackageMajorVersion(name) {
|
|
1351
1152
|
const cwd = process.cwd();
|
|
1352
|
-
const
|
|
1353
|
-
if (await pathExists(
|
|
1354
|
-
|
|
1355
|
-
const
|
|
1356
|
-
const version = Number(null == (_reactPkg_version = reactPkg.version) ? void 0 : _reactPkg_version.split('.')[0]);
|
|
1153
|
+
const pkgPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(cwd, 'node_modules', name);
|
|
1154
|
+
if (await pathExists(pkgPath)) {
|
|
1155
|
+
const pkgJson = await readJson(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(pkgPath, 'package.json'));
|
|
1156
|
+
const version = Number(pkgJson.version?.split('.')[0]);
|
|
1357
1157
|
return version;
|
|
1358
1158
|
}
|
|
1359
|
-
|
|
1159
|
+
}
|
|
1160
|
+
const DEFAULT_REACT_VERSION = 19;
|
|
1161
|
+
async function detectReactVersion() {
|
|
1162
|
+
return await detectPackageMajorVersion('react') ?? DEFAULT_REACT_VERSION;
|
|
1163
|
+
}
|
|
1164
|
+
async function resolveReactRouterDomAlias() {
|
|
1165
|
+
const alias = {};
|
|
1166
|
+
const resolver = detectReactVersion_ResolverFactory.createResolver({
|
|
1167
|
+
fileSystem: new detectReactVersion_CachedInputFileSystem(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"], 0),
|
|
1168
|
+
mainFields: [
|
|
1169
|
+
'browser',
|
|
1170
|
+
'module',
|
|
1171
|
+
'main'
|
|
1172
|
+
],
|
|
1173
|
+
extensions: [
|
|
1174
|
+
'.js'
|
|
1175
|
+
],
|
|
1176
|
+
alias
|
|
1177
|
+
});
|
|
1178
|
+
try {
|
|
1179
|
+
const pkgPath = await new Promise((resolve, reject)=>{
|
|
1180
|
+
resolver.resolve({
|
|
1181
|
+
importer: PACKAGE_ROOT
|
|
1182
|
+
}, PACKAGE_ROOT, 'react-router-dom', {}, (err, filePath)=>{
|
|
1183
|
+
if (err || !filePath) return reject(err);
|
|
1184
|
+
return resolve(filePath);
|
|
1185
|
+
});
|
|
1186
|
+
});
|
|
1187
|
+
return {
|
|
1188
|
+
'react-router-dom': pkgPath
|
|
1189
|
+
};
|
|
1190
|
+
} catch (e) {
|
|
1191
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn('react-router-dom not found: \n', e);
|
|
1192
|
+
}
|
|
1193
|
+
return {};
|
|
1360
1194
|
}
|
|
1361
1195
|
async function resolveReactAlias(reactVersion, isSSR) {
|
|
1362
1196
|
const basedir = reactVersion === DEFAULT_REACT_VERSION ? PACKAGE_ROOT : process.cwd();
|
|
@@ -1365,9 +1199,9 @@ async function resolveReactAlias(reactVersion, isSSR) {
|
|
|
1365
1199
|
'react/jsx-runtime',
|
|
1366
1200
|
'react/jsx-dev-runtime',
|
|
1367
1201
|
'react-dom',
|
|
1202
|
+
'react-dom/client',
|
|
1368
1203
|
'react-dom/server'
|
|
1369
1204
|
];
|
|
1370
|
-
if (reactVersion >= DEFAULT_REACT_VERSION) libPaths.push('react-dom/client');
|
|
1371
1205
|
const alias = {};
|
|
1372
1206
|
const resolver = detectReactVersion_ResolverFactory.createResolver({
|
|
1373
1207
|
fileSystem: new detectReactVersion_CachedInputFileSystem(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"], 0),
|
|
@@ -1441,33 +1275,33 @@ function getSocialIcons(socialLinks = []) {
|
|
|
1441
1275
|
return icons;
|
|
1442
1276
|
}
|
|
1443
1277
|
function isPluginIncluded(config, pluginName) {
|
|
1444
|
-
|
|
1445
|
-
return Boolean((null == (_config_builderPlugins = config.builderPlugins) ? void 0 : _config_builderPlugins.some((plugin)=>plugin.name === pluginName)) || (null == (_config_builderConfig = config.builderConfig) ? void 0 : null == (_config_builderConfig_plugins = _config_builderConfig.plugins) ? void 0 : _config_builderConfig_plugins.some((plugin)=>plugin && plugin.name === pluginName)));
|
|
1278
|
+
return Boolean(config.builderPlugins?.some((plugin)=>plugin.name === pluginName) || config.builderConfig?.plugins?.some((plugin)=>plugin && plugin.name === pluginName));
|
|
1446
1279
|
}
|
|
1447
|
-
async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver
|
|
1448
|
-
var _config_builderConfig_output, _config_builderConfig, _config_themeConfig, _config_themeConfig1;
|
|
1280
|
+
async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver) {
|
|
1449
1281
|
const cwd = process.cwd();
|
|
1450
|
-
const CUSTOM_THEME_DIR =
|
|
1451
|
-
const outDir =
|
|
1282
|
+
const CUSTOM_THEME_DIR = config?.themeDir ?? __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'theme');
|
|
1283
|
+
const outDir = config?.outDir ?? OUTPUT_DIR;
|
|
1452
1284
|
const DEFAULT_THEME = require.resolve('@rspress/theme-default');
|
|
1453
|
-
const base =
|
|
1454
|
-
const assetPrefix = isProduction() ? (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeTrailingSlash)(
|
|
1285
|
+
const base = config?.base ?? '';
|
|
1286
|
+
const assetPrefix = isProduction() ? (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeTrailingSlash)(config?.builderConfig?.output?.assetPrefix ?? base) : '';
|
|
1455
1287
|
const reactVersion = await detectReactVersion();
|
|
1456
1288
|
const normalizeIcon = (icon)=>{
|
|
1457
1289
|
if (!icon) return;
|
|
1458
|
-
|
|
1290
|
+
icon = icon.toString();
|
|
1291
|
+
if (icon.startsWith('file://')) icon = (0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(icon);
|
|
1292
|
+
else if (__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].isAbsolute(icon)) return __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(userDocRoot, PUBLIC_DIR, icon);
|
|
1459
1293
|
return icon;
|
|
1460
1294
|
};
|
|
1461
1295
|
await hintThemeBreakingChange(CUSTOM_THEME_DIR);
|
|
1462
|
-
const [detectCustomIconAlias, reactCSRAlias, reactSSRAlias] = await Promise.all([
|
|
1296
|
+
const [detectCustomIconAlias, reactCSRAlias, reactSSRAlias, reactRouterDomAlias] = await Promise.all([
|
|
1463
1297
|
detectCustomIcon(CUSTOM_THEME_DIR),
|
|
1464
1298
|
resolveReactAlias(reactVersion, false),
|
|
1465
|
-
enableSSG ? resolveReactAlias(reactVersion, true) : Promise.resolve({})
|
|
1299
|
+
enableSSG ? resolveReactAlias(reactVersion, true) : Promise.resolve({}),
|
|
1300
|
+
resolveReactRouterDomAlias()
|
|
1466
1301
|
]);
|
|
1467
1302
|
const context = {
|
|
1468
1303
|
userDocRoot,
|
|
1469
1304
|
config,
|
|
1470
|
-
runtimeTempDir,
|
|
1471
1305
|
routeService,
|
|
1472
1306
|
pluginDriver
|
|
1473
1307
|
};
|
|
@@ -1478,11 +1312,13 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1478
1312
|
],
|
|
1479
1313
|
rsbuildPluginDocVM(context),
|
|
1480
1314
|
pluginVirtualModule({
|
|
1315
|
+
tempDir: '.rspress/runtime',
|
|
1481
1316
|
virtualModules: {
|
|
1482
1317
|
...i18nVMPlugin(context),
|
|
1483
1318
|
...globalUIComponentsVMPlugin(context),
|
|
1484
1319
|
...globalStylesVMPlugin(context),
|
|
1485
|
-
...searchHookVMPlugin(context)
|
|
1320
|
+
...searchHookVMPlugin(context),
|
|
1321
|
+
...routeListVMPlugin(context)
|
|
1486
1322
|
}
|
|
1487
1323
|
}),
|
|
1488
1324
|
...enableSSG ? [
|
|
@@ -1501,6 +1337,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1501
1337
|
}
|
|
1502
1338
|
},
|
|
1503
1339
|
dev: {
|
|
1340
|
+
lazyCompilation: 'false' !== process.env.RSPRESS_LAZY_COMPILATION,
|
|
1504
1341
|
progressBar: false,
|
|
1505
1342
|
setupMiddlewares: [
|
|
1506
1343
|
(middlewares)=>{
|
|
@@ -1512,11 +1349,11 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1512
1349
|
}
|
|
1513
1350
|
},
|
|
1514
1351
|
html: {
|
|
1515
|
-
title:
|
|
1516
|
-
favicon: normalizeIcon(
|
|
1352
|
+
title: config?.title ?? DEFAULT_TITLE,
|
|
1353
|
+
favicon: normalizeIcon(config?.icon),
|
|
1517
1354
|
template: TEMPLATE_PATH,
|
|
1518
1355
|
tags: [
|
|
1519
|
-
|
|
1356
|
+
config.themeConfig?.darkMode !== false ? {
|
|
1520
1357
|
tag: "script",
|
|
1521
1358
|
children: inlineThemeScript,
|
|
1522
1359
|
append: false
|
|
@@ -1539,8 +1376,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1539
1376
|
],
|
|
1540
1377
|
'@theme-assets': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(DEFAULT_THEME, '../assets'),
|
|
1541
1378
|
'@rspress/core': PACKAGE_ROOT,
|
|
1542
|
-
'react-lazy-with-preload': require.resolve('react-lazy-with-preload')
|
|
1543
|
-
'react-syntax-highlighter': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(require.resolve('react-syntax-highlighter/package.json'))
|
|
1379
|
+
'react-lazy-with-preload': require.resolve('react-lazy-with-preload')
|
|
1544
1380
|
}
|
|
1545
1381
|
},
|
|
1546
1382
|
source: {
|
|
@@ -1549,9 +1385,8 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1549
1385
|
__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(cwd, 'node_modules', __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR)
|
|
1550
1386
|
],
|
|
1551
1387
|
define: {
|
|
1552
|
-
'process.env.__REACT_GTE_18__': JSON.stringify(reactVersion >= 18),
|
|
1553
1388
|
'process.env.TEST': JSON.stringify(process.env.TEST),
|
|
1554
|
-
'process.env.RSPRESS_SOCIAL_ICONS': JSON.stringify(getSocialIcons(
|
|
1389
|
+
'process.env.RSPRESS_SOCIAL_ICONS': JSON.stringify(getSocialIcons(config.themeConfig?.socialLinks))
|
|
1555
1390
|
}
|
|
1556
1391
|
},
|
|
1557
1392
|
performance: {
|
|
@@ -1571,11 +1406,10 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1571
1406
|
},
|
|
1572
1407
|
tools: {
|
|
1573
1408
|
bundlerChain (chain, { CHAIN_ID, target }) {
|
|
1574
|
-
var _config_markdown;
|
|
1575
1409
|
const isServer = 'node' === target;
|
|
1576
1410
|
const jsModuleRule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
1577
1411
|
const swcLoaderOptions = jsModuleRule.use(CHAIN_ID.USE.SWC).get('options');
|
|
1578
|
-
const checkDeadLinks = (
|
|
1412
|
+
const checkDeadLinks = (config?.markdown?.checkDeadLinks && !isServer) ?? false;
|
|
1579
1413
|
chain.module.rule('MDX').type("javascript/auto").test(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_OR_MD_REGEXP).resolve.merge({
|
|
1580
1414
|
conditionNames: jsModuleRule.resolve.conditionNames.values(),
|
|
1581
1415
|
mainFields: jsModuleRule.resolve.mainFields.values()
|
|
@@ -1599,12 +1433,6 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1599
1433
|
sideEffects: true
|
|
1600
1434
|
});
|
|
1601
1435
|
if (isServer) chain.output.filename(NODE_SSR_BUNDLE_NAME);
|
|
1602
|
-
const enableIncremental = !isProduction() && !process.env.DISABLE_RSPACK_INCREMENTAL;
|
|
1603
|
-
if (enableIncremental) chain.merge({
|
|
1604
|
-
experiments: {
|
|
1605
|
-
incremental: true
|
|
1606
|
-
}
|
|
1607
|
-
});
|
|
1608
1436
|
}
|
|
1609
1437
|
},
|
|
1610
1438
|
environments: {
|
|
@@ -1612,7 +1440,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1612
1440
|
resolve: {
|
|
1613
1441
|
alias: {
|
|
1614
1442
|
...reactCSRAlias,
|
|
1615
|
-
|
|
1443
|
+
...reactRouterDomAlias
|
|
1616
1444
|
}
|
|
1617
1445
|
},
|
|
1618
1446
|
source: {
|
|
@@ -1635,7 +1463,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1635
1463
|
resolve: {
|
|
1636
1464
|
alias: {
|
|
1637
1465
|
...reactSSRAlias,
|
|
1638
|
-
|
|
1466
|
+
...reactRouterDomAlias
|
|
1639
1467
|
}
|
|
1640
1468
|
},
|
|
1641
1469
|
tools: {
|
|
@@ -1669,10 +1497,9 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1669
1497
|
};
|
|
1670
1498
|
}
|
|
1671
1499
|
async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuildConfig) {
|
|
1672
|
-
var _pluginDriver_getPlugins;
|
|
1673
1500
|
const cwd = process.cwd();
|
|
1674
|
-
const userDocRoot = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(rootDir ||
|
|
1675
|
-
const builderPlugins =
|
|
1501
|
+
const userDocRoot = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(rootDir || config?.root || cwd);
|
|
1502
|
+
const builderPlugins = config?.builderPlugins ?? [];
|
|
1676
1503
|
const runtimeTempDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR, 'runtime');
|
|
1677
1504
|
const runtimeAbsTempDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(cwd, 'node_modules', runtimeTempDir);
|
|
1678
1505
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(runtimeAbsTempDir, {
|
|
@@ -1685,9 +1512,10 @@ async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuil
|
|
|
1685
1512
|
pluginDriver
|
|
1686
1513
|
});
|
|
1687
1514
|
const { createRsbuild, mergeRsbuildConfig } = await import("@rsbuild/core");
|
|
1688
|
-
const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver
|
|
1515
|
+
const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver);
|
|
1689
1516
|
const rsbuild = await createRsbuild({
|
|
1690
|
-
|
|
1517
|
+
callerName: 'rspress',
|
|
1518
|
+
rsbuildConfig: mergeRsbuildConfig(internalRsbuildConfig, ...pluginDriver.getPlugins()?.map((plugin)=>plugin.builderConfig ?? {}) || [], config?.builderConfig || {}, extraRsbuildConfig || {})
|
|
1691
1519
|
});
|
|
1692
1520
|
rsbuild.addPlugins(builderPlugins);
|
|
1693
1521
|
return rsbuild;
|
|
@@ -1736,15 +1564,14 @@ async function collectModuleFiles(contentPath, lang, includedDir, excludedDirs,
|
|
|
1736
1564
|
return fileLangMap;
|
|
1737
1565
|
}
|
|
1738
1566
|
async function checkLanguageParity(config) {
|
|
1739
|
-
|
|
1740
|
-
if (!(null == config ? void 0 : config.languageParity) || false === config.languageParity.enabled) return;
|
|
1567
|
+
if (!config?.languageParity || false === config.languageParity.enabled) return;
|
|
1741
1568
|
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Checking language parity...');
|
|
1742
1569
|
const contentPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(config.root);
|
|
1743
|
-
const includedDirs =
|
|
1570
|
+
const includedDirs = config.languageParity.include?.length ? config.languageParity.include : [
|
|
1744
1571
|
''
|
|
1745
1572
|
];
|
|
1746
1573
|
const excludedDirs = config.languageParity.exclude ?? [];
|
|
1747
|
-
const supportedLanguages = (
|
|
1574
|
+
const supportedLanguages = (config.locales ?? config.themeConfig?.locales)?.map((locale)=>locale.lang) || [];
|
|
1748
1575
|
if (!supportedLanguages.length) return void __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error('No supported languages found in the configuration.');
|
|
1749
1576
|
const missingLanguagesFile = [];
|
|
1750
1577
|
try {
|
|
@@ -1816,13 +1643,12 @@ async function build(options) {
|
|
|
1816
1643
|
await pluginDriver.afterBuild();
|
|
1817
1644
|
}
|
|
1818
1645
|
async function serve(options) {
|
|
1819
|
-
var _builderConfig_server, _builderConfig_server1;
|
|
1820
1646
|
const { config, port: userPort, host: userHost } = options;
|
|
1821
1647
|
const envPort = process.env.PORT;
|
|
1822
1648
|
const envHost = process.env.HOST;
|
|
1823
1649
|
const { builderConfig } = config;
|
|
1824
|
-
const port = Number(envPort || userPort ||
|
|
1825
|
-
const host = envHost || userHost ||
|
|
1650
|
+
const port = Number(envPort || userPort || builderConfig?.server?.port || 4173);
|
|
1651
|
+
const host = envHost || userHost || builderConfig?.server?.host || 'localhost';
|
|
1826
1652
|
config.builderConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(builderConfig, {
|
|
1827
1653
|
server: {
|
|
1828
1654
|
port,
|
|
@@ -1835,5 +1661,129 @@ async function serve(options) {
|
|
|
1835
1661
|
const rsbuild = await initRsbuild(config.root, modifiedConfig, pluginDriver, false);
|
|
1836
1662
|
return rsbuild.preview();
|
|
1837
1663
|
}
|
|
1664
|
+
const getASTNodeImport = (name, from)=>({
|
|
1665
|
+
type: 'mdxjsEsm',
|
|
1666
|
+
value: `import ${name} from ${JSON.stringify(from)}`,
|
|
1667
|
+
data: {
|
|
1668
|
+
estree: {
|
|
1669
|
+
type: 'Program',
|
|
1670
|
+
sourceType: 'module',
|
|
1671
|
+
body: [
|
|
1672
|
+
{
|
|
1673
|
+
type: 'ImportDeclaration',
|
|
1674
|
+
specifiers: [
|
|
1675
|
+
{
|
|
1676
|
+
type: 'ImportDefaultSpecifier',
|
|
1677
|
+
local: {
|
|
1678
|
+
type: 'Identifier',
|
|
1679
|
+
name
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
],
|
|
1683
|
+
source: {
|
|
1684
|
+
type: 'Literal',
|
|
1685
|
+
value: from,
|
|
1686
|
+
raw: `${JSON.stringify(from)}`
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
]
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
});
|
|
1693
|
+
function normalizeLink(nodeUrl, routeService, relativePath, cleanUrls) {
|
|
1694
|
+
if (!nodeUrl) return '';
|
|
1695
|
+
if (nodeUrl.startsWith('#')) return `#${nodeUrl.slice(1)}`;
|
|
1696
|
+
let { url, hash } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.parseUrl)(nodeUrl);
|
|
1697
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(url)) return url + (hash ? `#${hash}` : '');
|
|
1698
|
+
const extname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(url);
|
|
1699
|
+
if ((routeService?.extensions ?? __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS).includes(extname)) url = url.replace(new RegExp(`\\${extname}$`), '');
|
|
1700
|
+
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);
|
|
1701
|
+
else if (routeService) {
|
|
1702
|
+
const [pathVersion, pathLang] = routeService.getRoutePathParts((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(relativePath));
|
|
1703
|
+
const [urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
|
|
1704
|
+
url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)(urlPath);
|
|
1705
|
+
if (pathLang && urlLang !== pathLang) url = `/${pathLang}${url}`;
|
|
1706
|
+
if (pathVersion && urlVersion !== pathVersion) url = `/${pathVersion}${url}`;
|
|
1707
|
+
}
|
|
1708
|
+
if ('boolean' == typeof cleanUrls) url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeHref)(url, cleanUrls);
|
|
1709
|
+
else {
|
|
1710
|
+
url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeHref)(url, false);
|
|
1711
|
+
url = url.replace(/\.html$/, cleanUrls);
|
|
1712
|
+
}
|
|
1713
|
+
if (hash) url += `#${hash}`;
|
|
1714
|
+
return url;
|
|
1715
|
+
}
|
|
1716
|
+
const normalizeImageUrl = (imageUrl)=>{
|
|
1717
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(imageUrl) || imageUrl.startsWith('/')) return '';
|
|
1718
|
+
return imageUrl;
|
|
1719
|
+
};
|
|
1720
|
+
const remarkPluginNormalizeLink = ({ root, cleanUrls, routeService })=>(tree, file)=>{
|
|
1721
|
+
const images = [];
|
|
1722
|
+
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'link', (node)=>{
|
|
1723
|
+
const { url: nodeUrl } = node;
|
|
1724
|
+
const relativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, file.path);
|
|
1725
|
+
node.url = normalizeLink(nodeUrl, routeService, relativePath, cleanUrls);
|
|
1726
|
+
});
|
|
1727
|
+
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'definition', (node)=>{
|
|
1728
|
+
const { url: nodeUrl } = node;
|
|
1729
|
+
const relativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, file.path);
|
|
1730
|
+
node.url = normalizeLink(nodeUrl, routeService, relativePath, cleanUrls);
|
|
1731
|
+
});
|
|
1732
|
+
const getMdxSrcAttribute = (tempVar)=>({
|
|
1733
|
+
type: 'mdxJsxAttribute',
|
|
1734
|
+
name: 'src',
|
|
1735
|
+
value: {
|
|
1736
|
+
type: 'mdxJsxAttributeValueExpression',
|
|
1737
|
+
value: tempVar,
|
|
1738
|
+
data: {
|
|
1739
|
+
estree: {
|
|
1740
|
+
type: 'Program',
|
|
1741
|
+
sourceType: 'module',
|
|
1742
|
+
body: [
|
|
1743
|
+
{
|
|
1744
|
+
type: 'ExpressionStatement',
|
|
1745
|
+
expression: {
|
|
1746
|
+
type: 'Identifier',
|
|
1747
|
+
name: tempVar
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
]
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
});
|
|
1755
|
+
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'image', (node)=>{
|
|
1756
|
+
const { alt, url } = node;
|
|
1757
|
+
if (!url) return;
|
|
1758
|
+
const imagePath = normalizeImageUrl(url);
|
|
1759
|
+
if (!imagePath) return;
|
|
1760
|
+
const tempVariableName = `image${images.length}`;
|
|
1761
|
+
Object.assign(node, {
|
|
1762
|
+
type: 'mdxJsxFlowElement',
|
|
1763
|
+
name: 'img',
|
|
1764
|
+
children: [],
|
|
1765
|
+
attributes: [
|
|
1766
|
+
alt && {
|
|
1767
|
+
type: 'mdxJsxAttribute',
|
|
1768
|
+
name: 'alt',
|
|
1769
|
+
value: alt
|
|
1770
|
+
},
|
|
1771
|
+
getMdxSrcAttribute(tempVariableName)
|
|
1772
|
+
].filter(Boolean)
|
|
1773
|
+
});
|
|
1774
|
+
images.push(getASTNodeImport(tempVariableName, imagePath));
|
|
1775
|
+
});
|
|
1776
|
+
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, (node)=>{
|
|
1777
|
+
if ('mdxJsxFlowElement' !== node.type && 'mdxJsxTextElement' !== node.type || 'img' !== node.name) return;
|
|
1778
|
+
const srcAttr = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'src', true);
|
|
1779
|
+
if ('string' != typeof srcAttr?.value) return;
|
|
1780
|
+
const imagePath = normalizeImageUrl(srcAttr.value);
|
|
1781
|
+
if (!imagePath) return;
|
|
1782
|
+
const tempVariableName = `image${images.length}`;
|
|
1783
|
+
Object.assign(srcAttr, getMdxSrcAttribute(tempVariableName));
|
|
1784
|
+
images.push(getASTNodeImport(tempVariableName, imagePath));
|
|
1785
|
+
});
|
|
1786
|
+
tree.children.unshift(...images);
|
|
1787
|
+
};
|
|
1838
1788
|
var __webpack_exports__mergeDocConfig = __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.mergeDocConfig;
|
|
1839
|
-
export { build, dev, serve, __webpack_exports__mergeDocConfig as mergeDocConfig };
|
|
1789
|
+
export { build, dev, remarkPluginNormalizeLink, serve, __webpack_exports__mergeDocConfig as mergeDocConfig };
|