@rspress/core 1.41.1 → 1.41.3
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/193.js +12 -0
- package/dist/index.d.ts +39 -31
- package/dist/index.js +1701 -2167
- package/dist/loader.d.ts +78 -70
- package/dist/loader.js +544 -682
- package/dist/runtime/App.js +106 -132
- package/dist/runtime/clientEntry.js +71 -54
- package/dist/runtime/ssrEntry.js +30 -19
- package/dist/runtime/tsconfig.js +4 -0
- package/package.json +15 -15
- package/src/runtime/App.tsx +5 -2
- package/dist/index.js.map +0 -1
- package/dist/loader.js.map +0 -1
- package/dist/runtime/tsconfig.json +0 -10
package/dist/index.js
CHANGED
|
@@ -1,2293 +1,1827 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
54
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
55
|
-
__accessCheck(obj, member, "write to private field");
|
|
56
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
57
|
-
return value;
|
|
58
|
-
};
|
|
59
|
-
var __privateMethod = (obj, member, method) => {
|
|
60
|
-
__accessCheck(obj, member, "access private method");
|
|
61
|
-
return method;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// package.json
|
|
65
|
-
var require_package = __commonJS({
|
|
66
|
-
"package.json"(exports, module) {
|
|
67
|
-
module.exports = {
|
|
68
|
-
name: "@rspress/core",
|
|
69
|
-
version: "1.41.1",
|
|
70
|
-
description: "The Rspress Documentation Framework",
|
|
71
|
-
bugs: "https://github.com/web-infra-dev/rspress/issues",
|
|
72
|
-
repository: {
|
|
73
|
-
type: "git",
|
|
74
|
-
url: "https://github.com/web-infra-dev/rspress",
|
|
75
|
-
directory: "packages/cli/core"
|
|
76
|
-
},
|
|
77
|
-
license: "MIT",
|
|
78
|
-
sideEffects: [
|
|
79
|
-
"*.css",
|
|
80
|
-
"*.less",
|
|
81
|
-
"*.sass",
|
|
82
|
-
"*.scss",
|
|
83
|
-
"**/virtual-global-styles.js",
|
|
84
|
-
"virtual-global-styles",
|
|
85
|
-
"./src/theme-default/styles/index.ts"
|
|
86
|
-
],
|
|
87
|
-
type: "module",
|
|
88
|
-
exports: {
|
|
89
|
-
".": {
|
|
90
|
-
types: "./dist/index.d.ts",
|
|
91
|
-
import: "./dist/index.js"
|
|
92
|
-
},
|
|
93
|
-
"./dist/*": "./dist/*",
|
|
94
|
-
"./package.json": "./package.json",
|
|
95
|
-
"./theme": {
|
|
96
|
-
default: "./theme.ts"
|
|
97
|
-
},
|
|
98
|
-
"./theme.css": "./theme.css",
|
|
99
|
-
"./runtime": {
|
|
100
|
-
default: "./runtime.ts"
|
|
1
|
+
import __rslib_shim_module__ from 'module';
|
|
2
|
+
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
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
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__ from "node:fs/promises";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_less_4c557a99__ from "@rsbuild/plugin-less";
|
|
8
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__ from "@rsbuild/plugin-react";
|
|
9
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_sass_b13a7d33__ from "@rsbuild/plugin-sass";
|
|
10
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
|
|
11
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__ from "@rspress/shared/constants";
|
|
12
|
+
import * as __WEBPACK_EXTERNAL_MODULE_tinyglobby__ from "tinyglobby";
|
|
13
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
|
|
14
|
+
import * as __WEBPACK_EXTERNAL_MODULE_rspack_plugin_virtual_module_609978fd__ from "rspack-plugin-virtual-module";
|
|
15
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__ from "@rspress/shared/logger";
|
|
16
|
+
import * as __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__ from "lodash-es";
|
|
17
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__ from "node:crypto";
|
|
18
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_mdx_rs_d2f3021f__ from "@rspress/mdx-rs";
|
|
19
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__ from "@rspress/shared/node-utils";
|
|
20
|
+
import * as __WEBPACK_EXTERNAL_MODULE_html_to_text_2c51ed38__ from "html-to-text";
|
|
21
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
22
|
+
import * as __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__ from "@mdx-js/mdx";
|
|
23
|
+
import * as __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__ from "enhanced-resolve";
|
|
24
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
|
|
25
|
+
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
26
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
27
|
+
export * from "@rspress/shared";
|
|
28
|
+
var __webpack_modules__ = {};
|
|
29
|
+
var __webpack_module_cache__ = {};
|
|
30
|
+
function __webpack_require__(moduleId) {
|
|
31
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
32
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
33
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
34
|
+
exports: {}
|
|
35
|
+
};
|
|
36
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
37
|
+
return module.exports;
|
|
38
|
+
}
|
|
39
|
+
__webpack_require__.m = __webpack_modules__;
|
|
40
|
+
(()=>{
|
|
41
|
+
var getProto = Object.getPrototypeOf ? function(obj) {
|
|
42
|
+
return Object.getPrototypeOf(obj);
|
|
43
|
+
} : function(obj) {
|
|
44
|
+
return obj.__proto__;
|
|
45
|
+
};
|
|
46
|
+
var leafPrototypes;
|
|
47
|
+
__webpack_require__.t = function(value, mode) {
|
|
48
|
+
if (1 & mode) value = this(value);
|
|
49
|
+
if (8 & mode) return value;
|
|
50
|
+
if ('object' == typeof value && value) {
|
|
51
|
+
if (4 & mode && value.__esModule) return value;
|
|
52
|
+
if (16 & mode && 'function' == typeof value.then) return value;
|
|
101
53
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
dependencies: {
|
|
122
|
-
"@mdx-js/loader": "2.3.0",
|
|
123
|
-
"@mdx-js/mdx": "2.3.0",
|
|
124
|
-
"@mdx-js/react": "2.3.0",
|
|
125
|
-
"@rsbuild/core": "1.2.3",
|
|
126
|
-
"@rsbuild/plugin-less": "~1.1.0",
|
|
127
|
-
"@rsbuild/plugin-react": "~1.1.0",
|
|
128
|
-
"@rsbuild/plugin-sass": "~1.2.0",
|
|
129
|
-
"@rspress/mdx-rs": "0.6.6",
|
|
130
|
-
"@rspress/plugin-auto-nav-sidebar": "workspace:*",
|
|
131
|
-
"@rspress/plugin-container-syntax": "workspace:*",
|
|
132
|
-
"@rspress/plugin-last-updated": "workspace:*",
|
|
133
|
-
"@rspress/plugin-medium-zoom": "workspace:*",
|
|
134
|
-
"@rspress/runtime": "workspace:*",
|
|
135
|
-
"@rspress/shared": "workspace:*",
|
|
136
|
-
"@rspress/theme-default": "workspace:*",
|
|
137
|
-
"enhanced-resolve": "5.18.0",
|
|
138
|
-
"github-slugger": "^2.0.0",
|
|
139
|
-
"hast-util-from-html": "^2.0.3",
|
|
140
|
-
"hast-util-heading-rank": "^3.0.0",
|
|
141
|
-
"html-to-text": "^9.0.5",
|
|
142
|
-
htmr: "^1.0.2",
|
|
143
|
-
"lodash-es": "^4.17.21",
|
|
144
|
-
"mdast-util-mdxjs-esm": "^1.3.1",
|
|
145
|
-
memfs: "^4.17.0",
|
|
146
|
-
react: "^18.3.1",
|
|
147
|
-
"react-dom": "^18.3.1",
|
|
148
|
-
"react-helmet-async": "^1.3.0",
|
|
149
|
-
"react-lazy-with-preload": "^2.2.1",
|
|
150
|
-
"react-syntax-highlighter": "^15.6.1",
|
|
151
|
-
"rehype-external-links": "^3.0.0",
|
|
152
|
-
remark: "^14.0.3",
|
|
153
|
-
"remark-gfm": "3.0.1",
|
|
154
|
-
"rspack-plugin-virtual-module": "0.1.13",
|
|
155
|
-
tinyglobby: "^0.2.10",
|
|
156
|
-
unified: "^10.1.2",
|
|
157
|
-
"unist-util-visit": "^4.1.2",
|
|
158
|
-
"unist-util-visit-children": "^3.0.0"
|
|
159
|
-
},
|
|
160
|
-
devDependencies: {
|
|
161
|
-
"@modern-js/plugin-tailwindcss": "2.64.0",
|
|
162
|
-
"@modern-js/tsconfig": "2.64.0",
|
|
163
|
-
"@types/hast": "3.0.4",
|
|
164
|
-
"@types/html-to-text": "^9.0.4",
|
|
165
|
-
"@types/jest": "~29.5.14",
|
|
166
|
-
"@types/lodash-es": "^4.17.12",
|
|
167
|
-
"@types/mdast": "^3.0.15",
|
|
168
|
-
"@types/node": "^18.11.17",
|
|
169
|
-
"@types/react": "^18.3.18",
|
|
170
|
-
"@types/react-dom": "^18.3.5",
|
|
171
|
-
postcss: "8.5.1",
|
|
172
|
-
"rehype-stringify": "^9.0.4",
|
|
173
|
-
"remark-parse": "^10.0.2",
|
|
174
|
-
"remark-rehype": "^10.1.0",
|
|
175
|
-
rimraf: "^3.0.2",
|
|
176
|
-
tailwindcss: "^3.4.17",
|
|
177
|
-
typescript: "^5.5.3",
|
|
178
|
-
vitest: "2.1.9"
|
|
179
|
-
},
|
|
180
|
-
engines: {
|
|
181
|
-
node: ">=14.17.6"
|
|
182
|
-
},
|
|
183
|
-
publishConfig: {
|
|
184
|
-
access: "public",
|
|
185
|
-
provenance: true,
|
|
186
|
-
registry: "https://registry.npmjs.org/"
|
|
187
|
-
},
|
|
188
|
-
"jsnext:source": "./src/index.ts"
|
|
54
|
+
var ns = Object.create(null);
|
|
55
|
+
__webpack_require__.r(ns);
|
|
56
|
+
var def = {};
|
|
57
|
+
leafPrototypes = leafPrototypes || [
|
|
58
|
+
null,
|
|
59
|
+
getProto({}),
|
|
60
|
+
getProto([]),
|
|
61
|
+
getProto(getProto)
|
|
62
|
+
];
|
|
63
|
+
for(var current = 2 & mode && value; 'object' == typeof current && !~leafPrototypes.indexOf(current); current = getProto(current))Object.getOwnPropertyNames(current).forEach(function(key) {
|
|
64
|
+
def[key] = function() {
|
|
65
|
+
return value[key];
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
def['default'] = function() {
|
|
69
|
+
return value;
|
|
70
|
+
};
|
|
71
|
+
__webpack_require__.d(ns, def);
|
|
72
|
+
return ns;
|
|
189
73
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
74
|
+
})();
|
|
75
|
+
(()=>{
|
|
76
|
+
__webpack_require__.d = function(exports, definition) {
|
|
77
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: definition[key]
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
})();
|
|
83
|
+
(()=>{
|
|
84
|
+
__webpack_require__.f = {};
|
|
85
|
+
__webpack_require__.e = function(chunkId) {
|
|
86
|
+
return Promise.all(Object.keys(__webpack_require__.f).reduce(function(promises, key) {
|
|
87
|
+
__webpack_require__.f[key](chunkId, promises);
|
|
88
|
+
return promises;
|
|
89
|
+
}, []));
|
|
90
|
+
};
|
|
91
|
+
})();
|
|
92
|
+
(()=>{
|
|
93
|
+
__webpack_require__.u = function(chunkId) {
|
|
94
|
+
return "" + chunkId + ".js";
|
|
95
|
+
};
|
|
96
|
+
})();
|
|
97
|
+
(()=>{
|
|
98
|
+
__webpack_require__.o = function(obj, prop) {
|
|
99
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
100
|
+
};
|
|
101
|
+
})();
|
|
102
|
+
(()=>{
|
|
103
|
+
__webpack_require__.r = function(exports) {
|
|
104
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, {
|
|
105
|
+
value: 'Module'
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(exports, '__esModule', {
|
|
108
|
+
value: true
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
})();
|
|
112
|
+
(()=>{
|
|
113
|
+
var installedChunks = {
|
|
114
|
+
980: 0
|
|
115
|
+
};
|
|
116
|
+
var installChunk = function(data) {
|
|
117
|
+
var ids = data.ids;
|
|
118
|
+
var modules = data.modules;
|
|
119
|
+
var runtime = data.runtime;
|
|
120
|
+
var moduleId, chunkId, i = 0;
|
|
121
|
+
for(moduleId in modules)if (__webpack_require__.o(modules, moduleId)) __webpack_require__.m[moduleId] = modules[moduleId];
|
|
122
|
+
if (runtime) runtime(__webpack_require__);
|
|
123
|
+
for(; i < ids.length; i++){
|
|
124
|
+
chunkId = ids[i];
|
|
125
|
+
if (__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) installedChunks[chunkId][0]();
|
|
126
|
+
installedChunks[ids[i]] = 0;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
__webpack_require__.f.j = function(chunkId, promises) {
|
|
130
|
+
var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : void 0;
|
|
131
|
+
if (0 !== installedChunkData) {
|
|
132
|
+
if (installedChunkData) promises.push(installedChunkData[1]);
|
|
133
|
+
else {
|
|
134
|
+
var promise = import("./" + __webpack_require__.u(chunkId)).then(installChunk, function(e) {
|
|
135
|
+
if (0 !== installedChunks[chunkId]) installedChunks[chunkId] = void 0;
|
|
136
|
+
throw e;
|
|
137
|
+
});
|
|
138
|
+
var promise = Promise.race([
|
|
139
|
+
promise,
|
|
140
|
+
new Promise(function(resolve) {
|
|
141
|
+
installedChunkData = installedChunks[chunkId] = [
|
|
142
|
+
resolve
|
|
143
|
+
];
|
|
144
|
+
})
|
|
145
|
+
]);
|
|
146
|
+
promises.push(installedChunkData[1] = promise);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
})();
|
|
151
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
152
|
+
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
153
|
+
}
|
|
154
|
+
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
155
|
+
if (descriptor.get) return descriptor.get.call(receiver);
|
|
156
|
+
return descriptor.value;
|
|
157
|
+
}
|
|
158
|
+
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
159
|
+
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
160
|
+
else {
|
|
161
|
+
if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
|
|
162
|
+
descriptor.value = value;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
166
|
+
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
167
|
+
return privateMap.get(receiver);
|
|
168
|
+
}
|
|
169
|
+
function _class_private_field_get(receiver, privateMap) {
|
|
170
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
171
|
+
return _class_apply_descriptor_get(receiver, descriptor);
|
|
172
|
+
}
|
|
173
|
+
function _class_private_field_init(obj, privateMap, value) {
|
|
174
|
+
_check_private_redeclaration(obj, privateMap);
|
|
175
|
+
privateMap.set(obj, value);
|
|
176
|
+
}
|
|
177
|
+
function _class_private_field_set(receiver, privateMap, value) {
|
|
178
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
179
|
+
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
180
|
+
return value;
|
|
181
|
+
}
|
|
182
|
+
var _config = /*#__PURE__*/ new WeakMap(), _plugins = /*#__PURE__*/ new WeakMap(), _isProd = /*#__PURE__*/ new WeakMap();
|
|
183
|
+
class PluginDriver {
|
|
184
|
+
async init() {
|
|
185
|
+
var _themeConfig_locales, _themeConfig_locales_, _themeConfig_locales1, _themeConfig_locales_1, _themeConfig_locales2;
|
|
186
|
+
this.clearPlugins();
|
|
187
|
+
const config = _class_private_field_get(this, _config);
|
|
188
|
+
const themeConfig = (null == config ? void 0 : config.themeConfig) || {};
|
|
189
|
+
const enableLastUpdated = (null == themeConfig ? void 0 : themeConfig.lastUpdated) || (null == themeConfig ? void 0 : null === (_themeConfig_locales = themeConfig.locales) || void 0 === _themeConfig_locales ? void 0 : _themeConfig_locales.some((locale)=>locale.lastUpdated));
|
|
190
|
+
const mediumZoomConfig = (null == config ? void 0 : config.mediumZoom) ?? true;
|
|
191
|
+
const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar || (null === (_themeConfig_locales1 = themeConfig.locales) || void 0 === _themeConfig_locales1 ? void 0 : null === (_themeConfig_locales_ = _themeConfig_locales1[0]) || void 0 === _themeConfig_locales_ ? void 0 : _themeConfig_locales_.nav) || (null === (_themeConfig_locales2 = themeConfig.locales) || void 0 === _themeConfig_locales2 ? void 0 : null === (_themeConfig_locales_1 = _themeConfig_locales2[0]) || void 0 === _themeConfig_locales_1 ? void 0 : _themeConfig_locales_1.sidebar);
|
|
192
|
+
if (enableLastUpdated) {
|
|
193
|
+
const { pluginLastUpdated } = await import("@rspress/plugin-last-updated");
|
|
194
|
+
this.addPlugin(pluginLastUpdated());
|
|
195
|
+
}
|
|
196
|
+
if (mediumZoomConfig) {
|
|
197
|
+
const { pluginMediumZoom } = await import("@rspress/plugin-medium-zoom");
|
|
198
|
+
this.addPlugin(pluginMediumZoom('object' == typeof mediumZoomConfig ? mediumZoomConfig : void 0));
|
|
199
|
+
}
|
|
200
|
+
this.addPlugin((0, __WEBPACK_EXTERNAL_MODULE__rspress_plugin_container_syntax_12d3c700__.pluginContainerSyntax)());
|
|
201
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isDevDebugMode)()) {
|
|
202
|
+
const SourceBuildPlugin = await import("@rspress/theme-default/node/source-build-plugin.js").then((r)=>r.SourceBuildPlugin, ()=>null);
|
|
203
|
+
if (SourceBuildPlugin) this.addPlugin(SourceBuildPlugin());
|
|
204
|
+
}
|
|
205
|
+
(config.plugins || []).forEach((plugin)=>{
|
|
206
|
+
this.addPlugin(plugin);
|
|
207
|
+
});
|
|
208
|
+
if (!haveNavSidebarConfig) {
|
|
209
|
+
const { pluginAutoNavSidebar } = await import("@rspress/plugin-auto-nav-sidebar");
|
|
210
|
+
this.addPlugin(pluginAutoNavSidebar());
|
|
211
|
+
}
|
|
217
212
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
typeof mediumZoomConfig === "object" ? mediumZoomConfig : void 0
|
|
223
|
-
)
|
|
224
|
-
);
|
|
213
|
+
addPlugin(plugin) {
|
|
214
|
+
const existedIndex = _class_private_field_get(this, _plugins).findIndex((item)=>item.name === plugin.name);
|
|
215
|
+
if (-1 !== existedIndex) throw new Error(`The plugin "${plugin.name}" has been registered`);
|
|
216
|
+
_class_private_field_get(this, _plugins).push(plugin);
|
|
225
217
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const SourceBuildPlugin = await import("@rspress/theme-default/node/source-build-plugin.js").then(
|
|
229
|
-
(r) => r.SourceBuildPlugin,
|
|
230
|
-
() => null
|
|
231
|
-
);
|
|
232
|
-
if (SourceBuildPlugin) {
|
|
233
|
-
this.addPlugin(SourceBuildPlugin());
|
|
234
|
-
}
|
|
218
|
+
getPlugins() {
|
|
219
|
+
return _class_private_field_get(this, _plugins);
|
|
235
220
|
}
|
|
236
|
-
(
|
|
237
|
-
|
|
238
|
-
});
|
|
239
|
-
if (!haveNavSidebarConfig) {
|
|
240
|
-
const { pluginAutoNavSidebar } = await import("@rspress/plugin-auto-nav-sidebar");
|
|
241
|
-
this.addPlugin(pluginAutoNavSidebar());
|
|
221
|
+
clearPlugins() {
|
|
222
|
+
_class_private_field_set(this, _plugins, []);
|
|
242
223
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
(item) => item.name === plugin.name
|
|
247
|
-
);
|
|
248
|
-
if (existedIndex !== -1) {
|
|
249
|
-
throw new Error(`The plugin "${plugin.name}" has been registered`);
|
|
224
|
+
removePlugin(pluginName) {
|
|
225
|
+
const index = _class_private_field_get(this, _plugins).findIndex((item)=>item.name === pluginName);
|
|
226
|
+
if (-1 !== index) _class_private_field_get(this, _plugins).splice(index, 1);
|
|
250
227
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
228
|
+
async modifyConfig() {
|
|
229
|
+
let config = _class_private_field_get(this, _config);
|
|
230
|
+
for(let i = 0; i < _class_private_field_get(this, _plugins).length; i++){
|
|
231
|
+
const plugin = _class_private_field_get(this, _plugins)[i];
|
|
232
|
+
if ('function' == typeof plugin.config) config = await plugin.config(config || {}, {
|
|
233
|
+
addPlugin: this.addPlugin.bind(this),
|
|
234
|
+
removePlugin: (pluginName)=>{
|
|
235
|
+
const index = _class_private_field_get(this, _plugins).findIndex((item)=>item.name === pluginName);
|
|
236
|
+
this.removePlugin(pluginName);
|
|
237
|
+
if (index <= i && index > 0) i--;
|
|
238
|
+
}
|
|
239
|
+
}, _class_private_field_get(this, _isProd));
|
|
240
|
+
}
|
|
241
|
+
_class_private_field_set(this, _config, config);
|
|
242
|
+
return _class_private_field_get(this, _config);
|
|
243
|
+
}
|
|
244
|
+
async beforeBuild() {
|
|
245
|
+
return this._runParallelAsyncHook('beforeBuild', _class_private_field_get(this, _config) || {}, _class_private_field_get(this, _isProd));
|
|
246
|
+
}
|
|
247
|
+
async afterBuild() {
|
|
248
|
+
return this._runParallelAsyncHook('afterBuild', _class_private_field_get(this, _config) || {}, _class_private_field_get(this, _isProd));
|
|
249
|
+
}
|
|
250
|
+
async modifySearchIndexData(pages) {
|
|
251
|
+
return this._runParallelAsyncHook('modifySearchIndexData', pages, _class_private_field_get(this, _isProd));
|
|
252
|
+
}
|
|
253
|
+
async extendPageData(pageData) {
|
|
254
|
+
return this._runParallelAsyncHook('extendPageData', pageData, _class_private_field_get(this, _isProd));
|
|
255
|
+
}
|
|
256
|
+
async addPages() {
|
|
257
|
+
const result = await this._runParallelAsyncHook('addPages', _class_private_field_get(this, _config) || {}, _class_private_field_get(this, _isProd));
|
|
258
|
+
return result.flat();
|
|
259
|
+
}
|
|
260
|
+
async routeGenerated(routes) {
|
|
261
|
+
return this._runParallelAsyncHook('routeGenerated', routes);
|
|
262
|
+
}
|
|
263
|
+
async addRuntimeModules() {
|
|
264
|
+
const result = await this._runParallelAsyncHook('addRuntimeModules', _class_private_field_get(this, _config) || {}, _class_private_field_get(this, _isProd));
|
|
265
|
+
return result.reduce((prev, current)=>({
|
|
266
|
+
...prev,
|
|
267
|
+
...current
|
|
268
|
+
}), {});
|
|
269
|
+
}
|
|
270
|
+
async addSSGRoutes() {
|
|
271
|
+
const result = await this._runParallelAsyncHook('addSSGRoutes', _class_private_field_get(this, _config) || {}, _class_private_field_get(this, _isProd));
|
|
272
|
+
return result.flat();
|
|
273
|
+
}
|
|
274
|
+
globalUIComponents() {
|
|
275
|
+
const result = _class_private_field_get(this, _plugins).map((plugin)=>plugin.globalUIComponents || []);
|
|
276
|
+
return result.flat();
|
|
277
|
+
}
|
|
278
|
+
globalStyles() {
|
|
279
|
+
return _class_private_field_get(this, _plugins).filter((plugin)=>'string' == typeof plugin.globalStyles).map((plugin)=>plugin.globalStyles);
|
|
280
|
+
}
|
|
281
|
+
_runParallelAsyncHook(hookName, ...args) {
|
|
282
|
+
return Promise.all(_class_private_field_get(this, _plugins).filter((plugin)=>'function' == typeof plugin[hookName]).map((plugin)=>plugin[hookName](...args)));
|
|
263
283
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if (typeof plugin.config === "function") {
|
|
270
|
-
config = await plugin.config(
|
|
271
|
-
config || {},
|
|
272
|
-
{
|
|
273
|
-
addPlugin: this.addPlugin.bind(this),
|
|
274
|
-
removePlugin: (pluginName) => {
|
|
275
|
-
const index = __privateGet(this, _plugins).findIndex(
|
|
276
|
-
(item) => item.name === pluginName
|
|
277
|
-
);
|
|
278
|
-
this.removePlugin(pluginName);
|
|
279
|
-
if (index <= i && index > 0) {
|
|
280
|
-
i--;
|
|
281
|
-
}
|
|
284
|
+
_runSerialAsyncHook(hookName, ...args) {
|
|
285
|
+
return _class_private_field_get(this, _plugins).reduce(async (prev, plugin)=>{
|
|
286
|
+
if ('function' == typeof plugin[hookName]) {
|
|
287
|
+
await prev;
|
|
288
|
+
return plugin[hookName](...args);
|
|
282
289
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
);
|
|
286
|
-
}
|
|
290
|
+
return prev;
|
|
291
|
+
}, Promise.resolve());
|
|
287
292
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
async extendPageData(pageData) {
|
|
313
|
-
return this._runParallelAsyncHook("extendPageData", pageData, __privateGet(this, _isProd));
|
|
314
|
-
}
|
|
315
|
-
async addPages() {
|
|
316
|
-
const result = await this._runParallelAsyncHook(
|
|
317
|
-
"addPages",
|
|
318
|
-
__privateGet(this, _config) || {},
|
|
319
|
-
__privateGet(this, _isProd)
|
|
320
|
-
);
|
|
321
|
-
return result.flat();
|
|
322
|
-
}
|
|
323
|
-
async routeGenerated(routes) {
|
|
324
|
-
return this._runParallelAsyncHook("routeGenerated", routes);
|
|
325
|
-
}
|
|
326
|
-
async addRuntimeModules() {
|
|
327
|
-
const result = await this._runParallelAsyncHook(
|
|
328
|
-
"addRuntimeModules",
|
|
329
|
-
__privateGet(this, _config) || {},
|
|
330
|
-
__privateGet(this, _isProd)
|
|
331
|
-
);
|
|
332
|
-
return result.reduce((prev, current) => {
|
|
333
|
-
return {
|
|
334
|
-
...prev,
|
|
335
|
-
...current
|
|
336
|
-
};
|
|
337
|
-
}, {});
|
|
338
|
-
}
|
|
339
|
-
async addSSGRoutes() {
|
|
340
|
-
const result = await this._runParallelAsyncHook(
|
|
341
|
-
"addSSGRoutes",
|
|
342
|
-
__privateGet(this, _config) || {},
|
|
343
|
-
__privateGet(this, _isProd)
|
|
344
|
-
);
|
|
345
|
-
return result.flat();
|
|
346
|
-
}
|
|
347
|
-
globalUIComponents() {
|
|
348
|
-
const result = __privateGet(this, _plugins).map((plugin) => {
|
|
349
|
-
return plugin.globalUIComponents || [];
|
|
350
|
-
});
|
|
351
|
-
return result.flat();
|
|
352
|
-
}
|
|
353
|
-
globalStyles() {
|
|
354
|
-
return __privateGet(this, _plugins).filter((plugin) => typeof plugin.globalStyles === "string").map((plugin) => {
|
|
355
|
-
return plugin.globalStyles;
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
_runParallelAsyncHook(hookName, ...args) {
|
|
359
|
-
return Promise.all(
|
|
360
|
-
__privateGet(this, _plugins).filter((plugin) => typeof plugin[hookName] === "function").map((plugin) => {
|
|
361
|
-
return plugin[hookName](...args);
|
|
362
|
-
})
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
_runSerialAsyncHook(hookName, ...args) {
|
|
366
|
-
return __privateGet(this, _plugins).reduce(async (prev, plugin) => {
|
|
367
|
-
if (typeof plugin[hookName] === "function") {
|
|
368
|
-
await prev;
|
|
369
|
-
return plugin[hookName](...args);
|
|
370
|
-
}
|
|
371
|
-
return prev;
|
|
372
|
-
}, Promise.resolve());
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
_config = new WeakMap();
|
|
376
|
-
_plugins = new WeakMap();
|
|
377
|
-
_isProd = new WeakMap();
|
|
378
|
-
|
|
379
|
-
// src/node/initRsbuild.ts
|
|
380
|
-
import fs9 from "fs/promises";
|
|
381
|
-
import path11 from "path";
|
|
382
|
-
import { PLUGIN_LESS_NAME, pluginLess } from "@rsbuild/plugin-less";
|
|
383
|
-
import { PLUGIN_REACT_NAME, pluginReact } from "@rsbuild/plugin-react";
|
|
384
|
-
import { PLUGIN_SASS_NAME, pluginSass } from "@rsbuild/plugin-sass";
|
|
385
|
-
import {
|
|
386
|
-
MDX_REGEXP as MDX_REGEXP3,
|
|
387
|
-
RSPRESS_TEMP_DIR as RSPRESS_TEMP_DIR2,
|
|
388
|
-
isDebugMode,
|
|
389
|
-
removeLeadingSlash as removeLeadingSlash2,
|
|
390
|
-
removeTrailingSlash
|
|
391
|
-
} from "@rspress/shared";
|
|
392
|
-
|
|
393
|
-
// src/node/constants.ts
|
|
394
|
-
import path from "path";
|
|
395
|
-
import { fileURLToPath } from "url";
|
|
396
|
-
import { APPEARANCE_KEY, RSPRESS_TEMP_DIR } from "@rspress/shared";
|
|
397
|
-
var isProduction = () => process.env.NODE_ENV === "production";
|
|
398
|
-
var importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
399
|
-
var inlineThemeScript = `{
|
|
400
|
-
const saved = localStorage.getItem('${APPEARANCE_KEY}')
|
|
293
|
+
constructor(config, isProd){
|
|
294
|
+
_class_private_field_init(this, _config, {
|
|
295
|
+
writable: true,
|
|
296
|
+
value: void 0
|
|
297
|
+
});
|
|
298
|
+
_class_private_field_init(this, _plugins, {
|
|
299
|
+
writable: true,
|
|
300
|
+
value: void 0
|
|
301
|
+
});
|
|
302
|
+
_class_private_field_init(this, _isProd, {
|
|
303
|
+
writable: true,
|
|
304
|
+
value: void 0
|
|
305
|
+
});
|
|
306
|
+
_class_private_field_set(this, _config, config);
|
|
307
|
+
_class_private_field_set(this, _isProd, isProd);
|
|
308
|
+
_class_private_field_set(this, _plugins, []);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
312
|
+
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
313
|
+
const inlineThemeScript = `{
|
|
314
|
+
const saved = localStorage.getItem('${__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.APPEARANCE_KEY}')
|
|
401
315
|
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
402
316
|
const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
|
|
403
317
|
document.documentElement.classList.toggle('dark', isDark)
|
|
404
318
|
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
405
|
-
}`.replace(/\n/g,
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
);
|
|
420
|
-
var OUTPUT_DIR = "doc_build";
|
|
421
|
-
var APP_HTML_MARKER = "<!--<?- DOC_CONTENT ?>-->";
|
|
422
|
-
var HEAD_MARKER = "<!--<?- HEAD ?>-->";
|
|
423
|
-
var META_GENERATOR = "<!--<?- GENERATOR ?>-->";
|
|
424
|
-
var HTML_START_TAG = "<html";
|
|
425
|
-
var BODY_START_TAG = "<body";
|
|
426
|
-
var DEFAULT_TITLE = "Rspress";
|
|
427
|
-
var PUBLIC_DIR = "public";
|
|
428
|
-
var TEMP_DIR = path.join(
|
|
429
|
-
process.cwd(),
|
|
430
|
-
"node_modules",
|
|
431
|
-
RSPRESS_TEMP_DIR
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
// src/node/route/RouteService.ts
|
|
435
|
-
import fs4 from "fs/promises";
|
|
436
|
-
import path5 from "path";
|
|
437
|
-
import {
|
|
438
|
-
addLeadingSlash,
|
|
439
|
-
addTrailingSlash,
|
|
440
|
-
withBase
|
|
441
|
-
} from "@rspress/shared";
|
|
442
|
-
import { glob } from "tinyglobby";
|
|
443
|
-
|
|
444
|
-
// src/node/utils/normalizePath.ts
|
|
445
|
-
import os from "os";
|
|
446
|
-
import path2 from "path";
|
|
447
|
-
var isWindows = os.platform() === "win32";
|
|
319
|
+
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
320
|
+
const dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(new URL(import.meta.url)));
|
|
321
|
+
const PACKAGE_ROOT = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(dirname, '..');
|
|
322
|
+
const CLIENT_ENTRY = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'clientEntry.js');
|
|
323
|
+
const SSR_ENTRY = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrEntry.js');
|
|
324
|
+
const OUTPUT_DIR = 'doc_build';
|
|
325
|
+
const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
326
|
+
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
327
|
+
const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
|
|
328
|
+
const HTML_START_TAG = '<html';
|
|
329
|
+
const BODY_START_TAG = '<body';
|
|
330
|
+
const DEFAULT_TITLE = 'Rspress';
|
|
331
|
+
const PUBLIC_DIR = 'public';
|
|
332
|
+
const TEMP_DIR = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'node_modules', __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR);
|
|
333
|
+
const isWindows = 'win32' === __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__["default"].platform();
|
|
448
334
|
function slash(p) {
|
|
449
|
-
|
|
335
|
+
return p.replace(/\\/g, '/');
|
|
450
336
|
}
|
|
451
337
|
function normalizePath(id) {
|
|
452
|
-
|
|
338
|
+
return __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].posix.normalize(isWindows ? slash(id) : id);
|
|
453
339
|
}
|
|
454
|
-
|
|
455
|
-
// src/node/utils/getPageKey.ts
|
|
456
|
-
import { removeLeadingSlash } from "@rspress/shared";
|
|
457
340
|
function getPageKey(route) {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// src/node/utils/createHash.ts
|
|
463
|
-
import { createHash as createHashFunc } from "crypto";
|
|
464
|
-
function createHash(str) {
|
|
465
|
-
return createHashFunc("sha256").update(str).digest("hex").slice(0, 8);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
// src/node/utils/detectReactVersion.ts
|
|
469
|
-
import fs2 from "fs";
|
|
470
|
-
import path3 from "path";
|
|
471
|
-
import { logger } from "@rspress/shared/logger";
|
|
472
|
-
import enhancedResolve from "enhanced-resolve";
|
|
473
|
-
|
|
474
|
-
// src/node/utils/fs.ts
|
|
475
|
-
import fs from "fs/promises";
|
|
476
|
-
async function pathExists(path13) {
|
|
477
|
-
try {
|
|
478
|
-
await fs.access(path13);
|
|
479
|
-
return true;
|
|
480
|
-
} catch {
|
|
481
|
-
return false;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
async function readJson(path13) {
|
|
485
|
-
const raw = await fs.readFile(path13, "utf8");
|
|
486
|
-
return JSON.parse(raw);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
// src/node/utils/detectReactVersion.ts
|
|
490
|
-
var { CachedInputFileSystem, ResolverFactory } = enhancedResolve;
|
|
491
|
-
var DEFAULT_REACT_VERSION = 18;
|
|
492
|
-
async function detectReactVersion() {
|
|
493
|
-
const cwd = process.cwd();
|
|
494
|
-
const reactPath = path3.join(cwd, "node_modules", "react");
|
|
495
|
-
if (await pathExists(reactPath)) {
|
|
496
|
-
const reactPkg = await readJson(
|
|
497
|
-
path3.join(reactPath, "package.json")
|
|
498
|
-
);
|
|
499
|
-
const version = Number(reactPkg.version?.split(".")[0]);
|
|
500
|
-
return version;
|
|
501
|
-
}
|
|
502
|
-
return DEFAULT_REACT_VERSION;
|
|
341
|
+
const cleanRoute = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeLeadingSlash)(route);
|
|
342
|
+
return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
|
|
503
343
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
const alias = {};
|
|
517
|
-
const resolver2 = ResolverFactory.createResolver({
|
|
518
|
-
fileSystem: new CachedInputFileSystem(fs2, 0),
|
|
519
|
-
extensions: [".js"],
|
|
520
|
-
alias,
|
|
521
|
-
conditionNames: isSSR ? ["..."] : ["browser", "..."]
|
|
522
|
-
});
|
|
523
|
-
await Promise.all(
|
|
524
|
-
libPaths.map(async (lib) => {
|
|
525
|
-
try {
|
|
526
|
-
alias[lib] = await new Promise((resolve, reject) => {
|
|
527
|
-
resolver2.resolve(
|
|
528
|
-
{ importer: basedir },
|
|
529
|
-
basedir,
|
|
530
|
-
lib,
|
|
531
|
-
{},
|
|
532
|
-
(err, filePath) => {
|
|
533
|
-
if (err || filePath === false) {
|
|
534
|
-
return reject(err);
|
|
535
|
-
}
|
|
536
|
-
return resolve(filePath);
|
|
537
|
-
}
|
|
538
|
-
);
|
|
539
|
-
});
|
|
540
|
-
} catch (e) {
|
|
541
|
-
console.log(e);
|
|
542
|
-
logger.warn(`${lib} not found`);
|
|
543
|
-
}
|
|
544
|
-
})
|
|
545
|
-
);
|
|
546
|
-
return alias;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
// src/node/utils/flattenMdxContent.ts
|
|
550
|
-
import fs3 from "fs";
|
|
551
|
-
import path4 from "path";
|
|
552
|
-
import { createProcessor } from "@mdx-js/mdx";
|
|
553
|
-
import { MDX_REGEXP } from "@rspress/shared";
|
|
554
|
-
import enhancedResolve2 from "enhanced-resolve";
|
|
555
|
-
var resolver;
|
|
556
|
-
var startFlatten = false;
|
|
557
|
-
var processor = createProcessor();
|
|
558
|
-
var { CachedInputFileSystem: CachedInputFileSystem2, ResolverFactory: ResolverFactory2 } = enhancedResolve2;
|
|
559
|
-
async function resolveDepPath(importPath, importer, alias) {
|
|
560
|
-
if (!resolver) {
|
|
561
|
-
resolver = ResolverFactory2.createResolver({
|
|
562
|
-
fileSystem: new CachedInputFileSystem2(fs3, 0),
|
|
563
|
-
extensions: [".mdx", ".md"],
|
|
564
|
-
alias
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
const resolveResult = await new Promise((resolve, reject) => {
|
|
568
|
-
resolver.resolve(
|
|
569
|
-
{
|
|
570
|
-
importer
|
|
571
|
-
},
|
|
572
|
-
importer,
|
|
573
|
-
importPath,
|
|
574
|
-
{},
|
|
575
|
-
(err, filePath) => {
|
|
576
|
-
if (err) {
|
|
577
|
-
return reject(err);
|
|
344
|
+
const normalizeRoutePath = (routePath, base, lang, version, langs, versions, extensions = __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS)=>{
|
|
345
|
+
const hasTrailSlash = routePath.endsWith('/');
|
|
346
|
+
let versionPart = '';
|
|
347
|
+
let langPart = '';
|
|
348
|
+
let purePathPart = '';
|
|
349
|
+
const parts = routePath.split('/').filter(Boolean);
|
|
350
|
+
if (version) {
|
|
351
|
+
const versionToMatch = parts[0];
|
|
352
|
+
if (versions.includes(versionToMatch)) {
|
|
353
|
+
if (versionToMatch !== version) versionPart = versionToMatch;
|
|
354
|
+
parts.shift();
|
|
578
355
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
)
|
|
584
|
-
|
|
356
|
+
}
|
|
357
|
+
if (lang) {
|
|
358
|
+
const langToMatch = parts[0];
|
|
359
|
+
if (langs.includes(langToMatch)) {
|
|
360
|
+
if (langToMatch !== lang) langPart = langToMatch;
|
|
361
|
+
parts.shift();
|
|
585
362
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
);
|
|
589
|
-
|
|
590
|
-
|
|
363
|
+
}
|
|
364
|
+
purePathPart = parts.join('/');
|
|
365
|
+
const extensionsWithoutDot = extensions.map((i)=>i.slice(1));
|
|
366
|
+
const cleanExtensionPattern = new RegExp(`\\.(${extensionsWithoutDot.join('|')})$`, 'i');
|
|
367
|
+
let normalizedRoutePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)([
|
|
368
|
+
versionPart,
|
|
369
|
+
langPart,
|
|
370
|
+
purePathPart
|
|
371
|
+
].filter(Boolean).join('/')).replace(cleanExtensionPattern, '').replace(/\.html$/, '').replace(/\/index$/, '/');
|
|
372
|
+
if (hasTrailSlash) normalizedRoutePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addTrailingSlash)(normalizedRoutePath);
|
|
373
|
+
return {
|
|
374
|
+
routePath: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(normalizedRoutePath, base),
|
|
375
|
+
lang: langPart || lang,
|
|
376
|
+
version: versionPart || version
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
function RouteService_check_private_redeclaration(obj, privateCollection) {
|
|
380
|
+
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
591
381
|
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
extensions: [".mdx", ".md", ".js"],
|
|
602
|
-
alias
|
|
603
|
-
});
|
|
604
|
-
startFlatten = true;
|
|
605
|
-
}
|
|
606
|
-
let ast;
|
|
607
|
-
let result = content;
|
|
608
|
-
try {
|
|
609
|
-
ast = processor.parse(content);
|
|
610
|
-
} catch (e) {
|
|
611
|
-
return { flattenContent: content, deps };
|
|
612
|
-
}
|
|
613
|
-
const importNodes = ast.children.filter((node) => node.type === "mdxjsEsm").flatMap((node) => node.data?.estree?.body || []).filter((node) => node.type === "ImportDeclaration");
|
|
614
|
-
for (const importNode of importNodes) {
|
|
615
|
-
const id = importNode.specifiers[0].local.name;
|
|
616
|
-
const importPath = importNode.source.value;
|
|
617
|
-
let absoluteImportPath;
|
|
618
|
-
try {
|
|
619
|
-
absoluteImportPath = await resolveDepPath(
|
|
620
|
-
importPath,
|
|
621
|
-
path4.dirname(basePath),
|
|
622
|
-
alias
|
|
623
|
-
);
|
|
624
|
-
} catch (e) {
|
|
625
|
-
continue;
|
|
382
|
+
function RouteService_class_apply_descriptor_get(receiver, descriptor) {
|
|
383
|
+
if (descriptor.get) return descriptor.get.call(receiver);
|
|
384
|
+
return descriptor.value;
|
|
385
|
+
}
|
|
386
|
+
function RouteService_class_apply_descriptor_set(receiver, descriptor, value) {
|
|
387
|
+
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
388
|
+
else {
|
|
389
|
+
if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
|
|
390
|
+
descriptor.value = value;
|
|
626
391
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
392
|
+
}
|
|
393
|
+
function RouteService_class_extract_field_descriptor(receiver, privateMap, action) {
|
|
394
|
+
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
395
|
+
return privateMap.get(receiver);
|
|
396
|
+
}
|
|
397
|
+
function RouteService_class_private_field_get(receiver, privateMap) {
|
|
398
|
+
var descriptor = RouteService_class_extract_field_descriptor(receiver, privateMap, "get");
|
|
399
|
+
return RouteService_class_apply_descriptor_get(receiver, descriptor);
|
|
400
|
+
}
|
|
401
|
+
function RouteService_class_private_field_init(obj, privateMap, value) {
|
|
402
|
+
RouteService_check_private_redeclaration(obj, privateMap);
|
|
403
|
+
privateMap.set(obj, value);
|
|
404
|
+
}
|
|
405
|
+
function RouteService_class_private_field_set(receiver, privateMap, value) {
|
|
406
|
+
var descriptor = RouteService_class_extract_field_descriptor(receiver, privateMap, "set");
|
|
407
|
+
RouteService_class_apply_descriptor_set(receiver, descriptor, value);
|
|
408
|
+
return value;
|
|
409
|
+
}
|
|
410
|
+
function _class_private_method_get(receiver, privateSet, fn) {
|
|
411
|
+
if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
|
|
412
|
+
return fn;
|
|
413
|
+
}
|
|
414
|
+
function _class_private_method_init(obj, privateSet) {
|
|
415
|
+
RouteService_check_private_redeclaration(obj, privateSet);
|
|
416
|
+
privateSet.add(obj);
|
|
417
|
+
}
|
|
418
|
+
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();
|
|
419
|
+
class RouteService {
|
|
420
|
+
async init() {
|
|
421
|
+
const extensions = RouteService_class_private_field_get(this, _extensions).map((i)=>i.slice(1));
|
|
422
|
+
const files = (await (0, __WEBPACK_EXTERNAL_MODULE_tinyglobby__.glob)([
|
|
423
|
+
`**/*.{${extensions.join(',')}}`,
|
|
424
|
+
...RouteService_class_private_field_get(this, _include)
|
|
425
|
+
], {
|
|
426
|
+
cwd: RouteService_class_private_field_get(this, _scanDir),
|
|
427
|
+
absolute: true,
|
|
428
|
+
onlyFiles: true,
|
|
429
|
+
ignore: [
|
|
430
|
+
...RouteService_class_private_field_get(this, _exclude),
|
|
431
|
+
'**/node_modules/**',
|
|
432
|
+
'**/.eslintrc.js',
|
|
433
|
+
'**/.nx/**',
|
|
434
|
+
`./${PUBLIC_DIR}/**`
|
|
435
|
+
]
|
|
436
|
+
})).sort();
|
|
437
|
+
files.forEach((filePath)=>{
|
|
438
|
+
const fileRelativePath = normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(RouteService_class_private_field_get(this, _scanDir), filePath));
|
|
439
|
+
const { routePath, lang, version } = this.normalizeRoutePath(fileRelativePath);
|
|
440
|
+
const absolutePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(RouteService_class_private_field_get(this, _scanDir), fileRelativePath);
|
|
441
|
+
const routeInfo = {
|
|
442
|
+
routePath,
|
|
443
|
+
absolutePath: normalizePath(absolutePath),
|
|
444
|
+
relativePath: fileRelativePath,
|
|
445
|
+
pageName: getPageKey(fileRelativePath),
|
|
446
|
+
lang,
|
|
447
|
+
version
|
|
448
|
+
};
|
|
449
|
+
this.addRoute(routeInfo);
|
|
450
|
+
});
|
|
451
|
+
const externalPages = await RouteService_class_private_field_get(this, _pluginDriver).addPages();
|
|
452
|
+
await Promise.all(externalPages.map(async (route, index)=>{
|
|
453
|
+
const { routePath, content, filepath } = route;
|
|
454
|
+
if (filepath) {
|
|
455
|
+
const routeInfo = _class_private_method_get(this, _generateRouteInfo, generateRouteInfo).call(this, routePath, filepath);
|
|
456
|
+
this.addRoute(routeInfo);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (content) {
|
|
460
|
+
const filepath = await _class_private_method_get(this, _writeTempFile, writeTempFile).call(this, index, content);
|
|
461
|
+
const routeInfo = _class_private_method_get(this, _generateRouteInfo, generateRouteInfo).call(this, routePath, filepath);
|
|
462
|
+
this.addRoute(routeInfo);
|
|
463
|
+
}
|
|
464
|
+
}));
|
|
465
|
+
await RouteService_class_private_field_get(this, _pluginDriver).routeGenerated(this.getRoutes());
|
|
635
466
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
for (const rule of replaceRules) {
|
|
644
|
-
result = result.replace(rule.search, rule.replace);
|
|
645
|
-
}
|
|
646
|
-
return result;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
// src/node/route/RouteService.ts
|
|
650
|
-
var DEFAULT_PAGE_EXTENSIONS = ["js", "jsx", "ts", "tsx", "md", "mdx"];
|
|
651
|
-
var normalizeRoutePath = (routePath, base, lang, version, langs, versions, extensions = DEFAULT_PAGE_EXTENSIONS) => {
|
|
652
|
-
const hasTrailSlash = routePath.endsWith("/");
|
|
653
|
-
let versionPart = "";
|
|
654
|
-
let langPart = "";
|
|
655
|
-
let purePathPart = "";
|
|
656
|
-
const parts = routePath.split("/").filter(Boolean);
|
|
657
|
-
if (version) {
|
|
658
|
-
const versionToMatch = parts[0];
|
|
659
|
-
if (versions.includes(versionToMatch)) {
|
|
660
|
-
if (versionToMatch !== version) {
|
|
661
|
-
versionPart = versionToMatch;
|
|
662
|
-
}
|
|
663
|
-
parts.shift();
|
|
467
|
+
addRoute(routeInfo) {
|
|
468
|
+
const { routePath, absolutePath } = routeInfo;
|
|
469
|
+
if (this.routeData.has(routePath)) {
|
|
470
|
+
const preRouteExtIndex = RouteService_class_private_field_get(this, _extensions).indexOf(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(this.routeData.get(routePath).absolutePath));
|
|
471
|
+
const currRouteExtIndex = RouteService_class_private_field_get(this, _extensions).indexOf(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(absolutePath));
|
|
472
|
+
if (-1 !== currRouteExtIndex && (currRouteExtIndex < preRouteExtIndex || -1 === preRouteExtIndex)) this.routeData.set(routePath, routeInfo);
|
|
473
|
+
} else this.routeData.set(routePath, routeInfo);
|
|
664
474
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
if (langToMatch !== lang) {
|
|
670
|
-
langPart = langToMatch;
|
|
671
|
-
}
|
|
672
|
-
parts.shift();
|
|
475
|
+
removeRoute(filePath) {
|
|
476
|
+
const fileRelativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(RouteService_class_private_field_get(this, _scanDir), filePath);
|
|
477
|
+
const { routePath } = this.normalizeRoutePath(fileRelativePath);
|
|
478
|
+
this.routeData.delete(routePath);
|
|
673
479
|
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
let normalizedRoutePath = addLeadingSlash(
|
|
677
|
-
[versionPart, langPart, purePathPart].filter(Boolean).join("/")
|
|
678
|
-
).replace(new RegExp(`\\.(${extensions.join("|")})$`), "").replace(/\.html$/, "").replace(/\/index$/, "/");
|
|
679
|
-
if (hasTrailSlash) {
|
|
680
|
-
normalizedRoutePath = addTrailingSlash(normalizedRoutePath);
|
|
681
|
-
}
|
|
682
|
-
return {
|
|
683
|
-
routePath: withBase(normalizedRoutePath, base),
|
|
684
|
-
lang: langPart || lang,
|
|
685
|
-
version: versionPart || version
|
|
686
|
-
};
|
|
687
|
-
};
|
|
688
|
-
var _scanDir, _defaultLang, _defaultVersion, _extensions, _langs, _versions, _include, _exclude, _base, _tempDir, _pluginDriver, _writeTempFile, writeTempFile_fn, _generateRouteInfo, generateRouteInfo_fn;
|
|
689
|
-
var RouteService = class {
|
|
690
|
-
constructor(scanDir, userConfig, tempDir, pluginDriver) {
|
|
691
|
-
__privateAdd(this, _writeTempFile);
|
|
692
|
-
__privateAdd(this, _generateRouteInfo);
|
|
693
|
-
__publicField(this, "routeData", /* @__PURE__ */ new Map());
|
|
694
|
-
__privateAdd(this, _scanDir, void 0);
|
|
695
|
-
__privateAdd(this, _defaultLang, void 0);
|
|
696
|
-
__privateAdd(this, _defaultVersion, "");
|
|
697
|
-
__privateAdd(this, _extensions, []);
|
|
698
|
-
__privateAdd(this, _langs, []);
|
|
699
|
-
__privateAdd(this, _versions, []);
|
|
700
|
-
__privateAdd(this, _include, []);
|
|
701
|
-
__privateAdd(this, _exclude, []);
|
|
702
|
-
__privateAdd(this, _base, "");
|
|
703
|
-
__privateAdd(this, _tempDir, "");
|
|
704
|
-
__privateAdd(this, _pluginDriver, void 0);
|
|
705
|
-
const routeOptions = userConfig?.route || {};
|
|
706
|
-
__privateSet(this, _scanDir, scanDir);
|
|
707
|
-
__privateSet(this, _extensions, routeOptions.extensions || DEFAULT_PAGE_EXTENSIONS);
|
|
708
|
-
__privateSet(this, _include, routeOptions.include || []);
|
|
709
|
-
__privateSet(this, _exclude, routeOptions.exclude || []);
|
|
710
|
-
__privateSet(this, _defaultLang, userConfig?.lang || "");
|
|
711
|
-
__privateSet(this, _langs, (userConfig?.locales ?? userConfig?.themeConfig?.locales ?? []).map((item) => item.lang));
|
|
712
|
-
__privateSet(this, _base, userConfig?.base || "");
|
|
713
|
-
__privateSet(this, _tempDir, tempDir);
|
|
714
|
-
__privateSet(this, _pluginDriver, pluginDriver);
|
|
715
|
-
if (userConfig.multiVersion) {
|
|
716
|
-
__privateSet(this, _defaultVersion, userConfig.multiVersion.default || "");
|
|
717
|
-
__privateSet(this, _versions, userConfig.multiVersion.versions || []);
|
|
480
|
+
getRoutes() {
|
|
481
|
+
return Array.from(this.routeData.values());
|
|
718
482
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
...__privateGet(this, _exclude),
|
|
726
|
-
"**/node_modules/**",
|
|
727
|
-
"**/.eslintrc.js",
|
|
728
|
-
"**/.nx/**",
|
|
729
|
-
`./${PUBLIC_DIR}/**`
|
|
730
|
-
]
|
|
731
|
-
})).sort();
|
|
732
|
-
files.forEach((filePath) => {
|
|
733
|
-
const fileRelativePath = normalizePath(
|
|
734
|
-
path5.relative(__privateGet(this, _scanDir), filePath)
|
|
735
|
-
);
|
|
736
|
-
const { routePath, lang, version } = this.normalizeRoutePath(fileRelativePath);
|
|
737
|
-
const absolutePath = path5.join(__privateGet(this, _scanDir), fileRelativePath);
|
|
738
|
-
const routeInfo = {
|
|
739
|
-
routePath,
|
|
740
|
-
absolutePath: normalizePath(absolutePath),
|
|
741
|
-
relativePath: fileRelativePath,
|
|
742
|
-
pageName: getPageKey(fileRelativePath),
|
|
743
|
-
lang,
|
|
744
|
-
version
|
|
745
|
-
};
|
|
746
|
-
this.addRoute(routeInfo);
|
|
747
|
-
});
|
|
748
|
-
const externalPages = await __privateGet(this, _pluginDriver).addPages();
|
|
749
|
-
await Promise.all(
|
|
750
|
-
externalPages.map(async (route, index) => {
|
|
751
|
-
const { routePath, content, filepath } = route;
|
|
752
|
-
if (filepath) {
|
|
753
|
-
const routeInfo = __privateMethod(this, _generateRouteInfo, generateRouteInfo_fn).call(this, routePath, filepath);
|
|
754
|
-
this.addRoute(routeInfo);
|
|
755
|
-
return;
|
|
756
|
-
}
|
|
757
|
-
if (content) {
|
|
758
|
-
const filepath2 = await __privateMethod(this, _writeTempFile, writeTempFile_fn).call(this, index, content);
|
|
759
|
-
const routeInfo = __privateMethod(this, _generateRouteInfo, generateRouteInfo_fn).call(this, routePath, filepath2);
|
|
760
|
-
this.addRoute(routeInfo);
|
|
761
|
-
}
|
|
762
|
-
})
|
|
763
|
-
);
|
|
764
|
-
await __privateGet(this, _pluginDriver).routeGenerated(this.getRoutes());
|
|
765
|
-
}
|
|
766
|
-
addRoute(routeInfo) {
|
|
767
|
-
const { routePath, absolutePath } = routeInfo;
|
|
768
|
-
if (this.routeData.has(routePath)) {
|
|
769
|
-
const preRouteExtIndex = __privateGet(this, _extensions).indexOf(
|
|
770
|
-
path5.extname(this.routeData.get(routePath).absolutePath).slice(1)
|
|
771
|
-
);
|
|
772
|
-
const currRouteExtIndex = __privateGet(this, _extensions).indexOf(
|
|
773
|
-
path5.extname(absolutePath).slice(1)
|
|
774
|
-
);
|
|
775
|
-
if (currRouteExtIndex !== -1 && (currRouteExtIndex < preRouteExtIndex || preRouteExtIndex === -1)) {
|
|
776
|
-
this.routeData.set(routePath, routeInfo);
|
|
777
|
-
}
|
|
778
|
-
} else {
|
|
779
|
-
this.routeData.set(routePath, routeInfo);
|
|
483
|
+
isExistRoute(routePath) {
|
|
484
|
+
const { routePath: normalizedRoute } = this.normalizeRoutePath(routePath);
|
|
485
|
+
return Boolean(this.routeData.get(normalizedRoute));
|
|
486
|
+
}
|
|
487
|
+
isEmpty() {
|
|
488
|
+
return 0 === this.routeData.size;
|
|
780
489
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
}
|
|
787
|
-
getRoutes() {
|
|
788
|
-
return Array.from(this.routeData.values());
|
|
789
|
-
}
|
|
790
|
-
isExistRoute(routePath) {
|
|
791
|
-
const { routePath: normalizedRoute } = this.normalizeRoutePath(routePath);
|
|
792
|
-
return this.routeData.get(normalizedRoute);
|
|
793
|
-
}
|
|
794
|
-
isEmpty() {
|
|
795
|
-
return this.routeData.size === 0;
|
|
796
|
-
}
|
|
797
|
-
generateRoutesCode(isStaticImport = false) {
|
|
798
|
-
return this.generateRoutesCodeByRouteMeta(this.getRoutes(), isStaticImport);
|
|
799
|
-
}
|
|
800
|
-
generateRoutesCodeByRouteMeta(routeMeta, isStaticImport) {
|
|
801
|
-
return `
|
|
490
|
+
generateRoutesCode(isStaticImport = false) {
|
|
491
|
+
return this.generateRoutesCodeByRouteMeta(this.getRoutes(), isStaticImport);
|
|
492
|
+
}
|
|
493
|
+
generateRoutesCodeByRouteMeta(routeMeta, isStaticImport) {
|
|
494
|
+
return `
|
|
802
495
|
import React from 'react';
|
|
803
496
|
import { lazyWithPreload } from "react-lazy-with-preload";
|
|
804
|
-
${routeMeta.map((route, index) => {
|
|
805
|
-
return isStaticImport ? `import * as Route${index} from '${route.absolutePath}';` : `const Route${index} = lazyWithPreload(() => import('${route.absolutePath}'))`;
|
|
806
|
-
}).join("\n")}
|
|
497
|
+
${routeMeta.map((route, index)=>isStaticImport ? `import * as Route${index} from '${route.absolutePath}';` : `const Route${index} = lazyWithPreload(() => import('${route.absolutePath}'))`).join('\n')}
|
|
807
498
|
export const routes = [
|
|
808
|
-
${routeMeta.map((route, index)
|
|
809
|
-
|
|
499
|
+
${routeMeta.map((route, index)=>{
|
|
500
|
+
const preload = isStaticImport ? `() => Route${index}` : `async () => {
|
|
810
501
|
await Route${index}.preload();
|
|
811
502
|
return import("${route.absolutePath}");
|
|
812
503
|
}`;
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
504
|
+
const component = isStaticImport ? `Route${index}.default` : `Route${index}`;
|
|
505
|
+
return `{ path: '${route.routePath}', element: React.createElement(${component}), filePath: '${route.relativePath}', preload: ${preload}, lang: '${route.lang}', version: '${route.version}' }`;
|
|
506
|
+
}).join(',\n')}
|
|
816
507
|
];
|
|
817
508
|
`;
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
509
|
+
}
|
|
510
|
+
normalizeRoutePath(routePath) {
|
|
511
|
+
return normalizeRoutePath(routePath, RouteService_class_private_field_get(this, _base), RouteService_class_private_field_get(this, _defaultLang), RouteService_class_private_field_get(this, _defaultVersion), RouteService_class_private_field_get(this, _langs), RouteService_class_private_field_get(this, _versions), RouteService_class_private_field_get(this, _extensions));
|
|
512
|
+
}
|
|
513
|
+
constructor(scanDir, userConfig, tempDir, pluginDriver){
|
|
514
|
+
var _userConfig_themeConfig;
|
|
515
|
+
_class_private_method_init(this, _writeTempFile);
|
|
516
|
+
_class_private_method_init(this, _generateRouteInfo);
|
|
517
|
+
RouteService_class_private_field_init(this, _scanDir, {
|
|
518
|
+
writable: true,
|
|
519
|
+
value: void 0
|
|
520
|
+
});
|
|
521
|
+
RouteService_class_private_field_init(this, _defaultLang, {
|
|
522
|
+
writable: true,
|
|
523
|
+
value: void 0
|
|
524
|
+
});
|
|
525
|
+
RouteService_class_private_field_init(this, _defaultVersion, {
|
|
526
|
+
writable: true,
|
|
527
|
+
value: void 0
|
|
528
|
+
});
|
|
529
|
+
RouteService_class_private_field_init(this, _extensions, {
|
|
530
|
+
writable: true,
|
|
531
|
+
value: void 0
|
|
532
|
+
});
|
|
533
|
+
RouteService_class_private_field_init(this, _langs, {
|
|
534
|
+
writable: true,
|
|
535
|
+
value: void 0
|
|
536
|
+
});
|
|
537
|
+
RouteService_class_private_field_init(this, _versions, {
|
|
538
|
+
writable: true,
|
|
539
|
+
value: void 0
|
|
540
|
+
});
|
|
541
|
+
RouteService_class_private_field_init(this, _include, {
|
|
542
|
+
writable: true,
|
|
543
|
+
value: void 0
|
|
544
|
+
});
|
|
545
|
+
RouteService_class_private_field_init(this, _exclude, {
|
|
546
|
+
writable: true,
|
|
547
|
+
value: void 0
|
|
548
|
+
});
|
|
549
|
+
RouteService_class_private_field_init(this, _base, {
|
|
550
|
+
writable: true,
|
|
551
|
+
value: void 0
|
|
552
|
+
});
|
|
553
|
+
RouteService_class_private_field_init(this, _tempDir, {
|
|
554
|
+
writable: true,
|
|
555
|
+
value: void 0
|
|
556
|
+
});
|
|
557
|
+
RouteService_class_private_field_init(this, _pluginDriver, {
|
|
558
|
+
writable: true,
|
|
559
|
+
value: void 0
|
|
560
|
+
});
|
|
561
|
+
this.routeData = new Map();
|
|
562
|
+
RouteService_class_private_field_set(this, _defaultVersion, '');
|
|
563
|
+
RouteService_class_private_field_set(this, _extensions, []);
|
|
564
|
+
RouteService_class_private_field_set(this, _langs, []);
|
|
565
|
+
RouteService_class_private_field_set(this, _versions, []);
|
|
566
|
+
RouteService_class_private_field_set(this, _include, []);
|
|
567
|
+
RouteService_class_private_field_set(this, _exclude, []);
|
|
568
|
+
RouteService_class_private_field_set(this, _base, '');
|
|
569
|
+
RouteService_class_private_field_set(this, _tempDir, '');
|
|
570
|
+
const routeOptions = (null == userConfig ? void 0 : userConfig.route) || {};
|
|
571
|
+
RouteService_class_private_field_set(this, _scanDir, scanDir);
|
|
572
|
+
RouteService_class_private_field_set(this, _extensions, routeOptions.extensions || __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS);
|
|
573
|
+
RouteService_class_private_field_set(this, _include, routeOptions.include || []);
|
|
574
|
+
RouteService_class_private_field_set(this, _exclude, routeOptions.exclude || []);
|
|
575
|
+
RouteService_class_private_field_set(this, _defaultLang, (null == userConfig ? void 0 : userConfig.lang) || '');
|
|
576
|
+
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 ? void 0 : _userConfig_themeConfig.locales) ?? []).map((item)=>item.lang));
|
|
577
|
+
RouteService_class_private_field_set(this, _base, (null == userConfig ? void 0 : userConfig.base) || '');
|
|
578
|
+
RouteService_class_private_field_set(this, _tempDir, tempDir);
|
|
579
|
+
RouteService_class_private_field_set(this, _pluginDriver, pluginDriver);
|
|
580
|
+
if (userConfig.multiVersion) {
|
|
581
|
+
RouteService_class_private_field_set(this, _defaultVersion, userConfig.multiVersion.default || '');
|
|
582
|
+
RouteService_class_private_field_set(this, _versions, userConfig.multiVersion.versions || []);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
async function writeTempFile(index, content) {
|
|
587
|
+
const tempFilePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(RouteService_class_private_field_get(this, _tempDir), `temp-${index}.mdx`);
|
|
588
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(tempFilePath, content);
|
|
589
|
+
return tempFilePath;
|
|
590
|
+
}
|
|
591
|
+
function generateRouteInfo(routePath, filepath) {
|
|
592
|
+
const { routePath: normalizedPath, lang, version } = this.normalizeRoutePath(routePath);
|
|
593
|
+
return {
|
|
594
|
+
routePath: normalizedPath,
|
|
595
|
+
absolutePath: normalizePath(filepath),
|
|
596
|
+
relativePath: normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(RouteService_class_private_field_get(this, _scanDir), filepath)),
|
|
597
|
+
pageName: getPageKey(routePath),
|
|
598
|
+
lang,
|
|
599
|
+
version
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
let init_routeService = null;
|
|
867
603
|
async function initRouteService(options) {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
pluginDriver
|
|
874
|
-
);
|
|
875
|
-
await routeService.init();
|
|
876
|
-
return routeService;
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
// src/node/runtimeModule/index.ts
|
|
880
|
-
import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
|
|
881
|
-
|
|
882
|
-
// src/node/runtimeModule/globalStyles.ts
|
|
883
|
-
import fs5 from "fs/promises";
|
|
604
|
+
const { scanDir, config, runtimeTempDir, pluginDriver } = options;
|
|
605
|
+
init_routeService = new RouteService(scanDir, config, runtimeTempDir, pluginDriver);
|
|
606
|
+
await init_routeService.init();
|
|
607
|
+
return init_routeService;
|
|
608
|
+
}
|
|
884
609
|
async function globalStylesVMPlugin(context) {
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
}
|
|
893
|
-
const moduleContent = (await Promise.all(
|
|
894
|
-
[config?.globalStyles || "", ...globalStylesByPlugins].filter((source) => source.length > 0).map(async (source) => {
|
|
895
|
-
return `import ${JSON.stringify(source)};`;
|
|
896
|
-
})
|
|
897
|
-
)).join("");
|
|
898
|
-
return {
|
|
899
|
-
["virtual-global-styles" /* GlobalStyles */]: moduleContent
|
|
900
|
-
};
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
// src/node/runtimeModule/globalUIComponents.ts
|
|
904
|
-
async function globalUIComponentsVMPlugin(context) {
|
|
905
|
-
const { config, pluginDriver } = context;
|
|
906
|
-
let index = 0;
|
|
907
|
-
const globalUIComponentsByPlugins = pluginDriver.globalUIComponents();
|
|
908
|
-
const globalComponents = [
|
|
909
|
-
...config?.globalUIComponents || [],
|
|
910
|
-
...globalUIComponentsByPlugins
|
|
911
|
-
];
|
|
912
|
-
const moduleContent = globalComponents.map((source) => {
|
|
913
|
-
const name = `Comp_${index}`;
|
|
914
|
-
if (Array.isArray(source)) {
|
|
915
|
-
return `import ${name} from ${JSON.stringify(source[0])};
|
|
916
|
-
const Props_${index++} = ${JSON.stringify(source[1])};
|
|
917
|
-
`;
|
|
610
|
+
const { config, pluginDriver } = context;
|
|
611
|
+
const globalStylesByPlugins = pluginDriver.globalStyles();
|
|
612
|
+
if (config.globalStyles) {
|
|
613
|
+
const source = config.globalStyles;
|
|
614
|
+
const styleContent = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(source, 'utf-8');
|
|
615
|
+
const patchedStyleContent = styleContent.replace(/--modern-/g, '--rp-').replace(/\.modern-doc/g, '.rspress').replace(/\.modern-/g, '.rspress-');
|
|
616
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(source, patchedStyleContent, 'utf-8');
|
|
918
617
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
618
|
+
const moduleContent = (await Promise.all([
|
|
619
|
+
(null == config ? void 0 : config.globalStyles) || '',
|
|
620
|
+
...globalStylesByPlugins
|
|
621
|
+
].filter((source)=>source.length > 0).map(async (source)=>`import ${JSON.stringify(source)};`))).join('');
|
|
622
|
+
return {
|
|
623
|
+
[runtimeModule_RuntimeModuleID.GlobalStyles]: moduleContent
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
async function globalUIComponentsVMPlugin(context) {
|
|
627
|
+
const { config, pluginDriver } = context;
|
|
628
|
+
let index = 0;
|
|
629
|
+
const globalUIComponentsByPlugins = pluginDriver.globalUIComponents();
|
|
630
|
+
const globalComponents = [
|
|
631
|
+
...(null == config ? void 0 : config.globalUIComponents) || [],
|
|
632
|
+
...globalUIComponentsByPlugins
|
|
633
|
+
];
|
|
634
|
+
const moduleContent = globalComponents.map((source)=>{
|
|
635
|
+
const name = `Comp_${index}`;
|
|
636
|
+
if (Array.isArray(source)) return `import ${name} from ${JSON.stringify(source[0])};
|
|
637
|
+
const Props_${index++} = ${JSON.stringify(source[1])};\n`;
|
|
638
|
+
index++;
|
|
639
|
+
return `import ${name} from ${JSON.stringify(source)};\n`;
|
|
640
|
+
}).concat(`export default [${Array.from({
|
|
641
|
+
length: index
|
|
642
|
+
}, (_, i)=>{
|
|
643
|
+
if (Array.isArray(globalComponents[i])) return `[Comp_${i}, Props_${i}]`;
|
|
644
|
+
return `Comp_${i}`;
|
|
645
|
+
}).join(', ')}];`).join('');
|
|
646
|
+
return {
|
|
647
|
+
[runtimeModule_RuntimeModuleID.GlobalComponents]: moduleContent
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
const DEFAULT_I18N_SOURCE = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), 'i18n.json');
|
|
938
651
|
function getI18nData(docConfig) {
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
652
|
+
const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
|
|
653
|
+
try {
|
|
654
|
+
delete require.cache[i18nSourcePath];
|
|
655
|
+
const i18nSource = require(i18nSourcePath);
|
|
656
|
+
return i18nSource;
|
|
657
|
+
} catch (e) {
|
|
658
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug('getI18nData Failed: \n', e);
|
|
659
|
+
return {};
|
|
660
|
+
}
|
|
947
661
|
}
|
|
948
662
|
function i18nVMPlugin(context) {
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
// src/node/runtimeModule/routeData.ts
|
|
663
|
+
const { config } = context;
|
|
664
|
+
const i18nData = getI18nData(config);
|
|
665
|
+
return {
|
|
666
|
+
[runtimeModule_RuntimeModuleID.I18nText]: `export default ${JSON.stringify(i18nData, null, 2)}`
|
|
667
|
+
};
|
|
668
|
+
}
|
|
957
669
|
async function routeVMPlugin(context) {
|
|
958
|
-
|
|
959
|
-
|
|
670
|
+
const { routeService, isSSR } = context;
|
|
671
|
+
if (!isSSR) return {
|
|
672
|
+
[runtimeModule_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
|
|
673
|
+
[runtimeModule_RuntimeModuleID.RouteForSSR]: ''
|
|
674
|
+
};
|
|
960
675
|
return {
|
|
961
|
-
|
|
676
|
+
[runtimeModule_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
|
|
677
|
+
[runtimeModule_RuntimeModuleID.RouteForSSR]: routeService.generateRoutesCode(true)
|
|
962
678
|
};
|
|
963
|
-
|
|
964
|
-
return {
|
|
965
|
-
["virtual-routes" /* RouteForClient */]: routeService2.generateRoutesCode(false),
|
|
966
|
-
["virtual-routes-ssr" /* RouteForSSR */]: routeService2.generateRoutesCode(true)
|
|
967
|
-
};
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
// src/node/runtimeModule/searchHooks.ts
|
|
971
|
-
import path6 from "path";
|
|
679
|
+
}
|
|
972
680
|
async function searchHookVMPlugin(context) {
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
}
|
|
980
|
-
return {
|
|
981
|
-
[`${"virtual-search-hooks" /* SearchHooks */}${extname}`]: content
|
|
982
|
-
};
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
// src/node/runtimeModule/siteData/index.ts
|
|
986
|
-
import fs7 from "fs/promises";
|
|
987
|
-
import path8 from "path";
|
|
988
|
-
import { SEARCH_INDEX_NAME } from "@rspress/shared";
|
|
989
|
-
import { groupBy } from "lodash-es";
|
|
990
|
-
|
|
991
|
-
// src/node/runtimeModule/siteData/extractPageData.ts
|
|
992
|
-
import fs6 from "fs/promises";
|
|
993
|
-
import path7 from "path";
|
|
994
|
-
import { compile } from "@rspress/mdx-rs";
|
|
995
|
-
import {
|
|
996
|
-
MDX_REGEXP as MDX_REGEXP2
|
|
997
|
-
} from "@rspress/shared";
|
|
998
|
-
import { loadFrontMatter } from "@rspress/shared/node-utils";
|
|
999
|
-
import { htmlToText } from "html-to-text";
|
|
1000
|
-
function applyReplaceRulesToNestedObject(obj, replaceRules) {
|
|
1001
|
-
for (const key in obj) {
|
|
1002
|
-
if (typeof obj[key] === "string") {
|
|
1003
|
-
obj[key] = applyReplaceRules(obj[key], replaceRules);
|
|
1004
|
-
} else if (typeof obj[key] === "object") {
|
|
1005
|
-
obj[key] = applyReplaceRulesToNestedObject(obj[key], replaceRules);
|
|
681
|
+
const { config } = context;
|
|
682
|
+
let content = 'export const onSearch = () => {};';
|
|
683
|
+
let extname = '';
|
|
684
|
+
if ('object' == typeof config.search && 'string' == typeof config.search.searchHooks) {
|
|
685
|
+
content = `export * from '${config.search.searchHooks}'`;
|
|
686
|
+
extname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(config.search.searchHooks);
|
|
1006
687
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
_filepath: route.absolutePath,
|
|
1025
|
-
_relativePath: path7.relative(root, route.absolutePath)
|
|
1026
|
-
};
|
|
1027
|
-
if (!MDX_REGEXP2.test(route.absolutePath)) {
|
|
1028
|
-
return defaultIndexInfo;
|
|
1029
|
-
}
|
|
1030
|
-
let content = await fs6.readFile(route.absolutePath, "utf8");
|
|
1031
|
-
const { frontmatter, content: strippedFrontMatter } = loadFrontMatter(
|
|
1032
|
-
content,
|
|
1033
|
-
route.absolutePath,
|
|
1034
|
-
root
|
|
1035
|
-
);
|
|
1036
|
-
applyReplaceRulesToNestedObject(frontmatter, replaceRules);
|
|
1037
|
-
const { flattenContent } = await flattenMdxContent(
|
|
1038
|
-
applyReplaceRules(strippedFrontMatter, replaceRules),
|
|
1039
|
-
route.absolutePath,
|
|
1040
|
-
alias
|
|
1041
|
-
);
|
|
1042
|
-
content = flattenContent.replace(importStatementRegex, "");
|
|
1043
|
-
const {
|
|
1044
|
-
html,
|
|
1045
|
-
title,
|
|
1046
|
-
toc: rawToc,
|
|
1047
|
-
languages
|
|
1048
|
-
} = await compile({
|
|
1049
|
-
value: content,
|
|
1050
|
-
filepath: route.absolutePath,
|
|
1051
|
-
development: process.env.NODE_ENV !== "production",
|
|
1052
|
-
root
|
|
1053
|
-
});
|
|
1054
|
-
if (!title?.length && !frontmatter && !frontmatter.title?.length) {
|
|
1055
|
-
return null;
|
|
1056
|
-
}
|
|
1057
|
-
content = htmlToText(String(html), {
|
|
1058
|
-
wordwrap: 80,
|
|
1059
|
-
selectors: [
|
|
1060
|
-
{
|
|
1061
|
-
selector: "a",
|
|
1062
|
-
options: {
|
|
1063
|
-
ignoreHref: true
|
|
1064
|
-
}
|
|
1065
|
-
},
|
|
1066
|
-
{
|
|
1067
|
-
selector: "img",
|
|
1068
|
-
format: "skip"
|
|
1069
|
-
},
|
|
1070
|
-
{
|
|
1071
|
-
// Skip code blocks
|
|
1072
|
-
selector: "pre > code",
|
|
1073
|
-
format: searchCodeBlocks ? "block" : "skip"
|
|
1074
|
-
},
|
|
1075
|
-
...["h1", "h2", "h3", "h4", "h5", "h6"].map((tag) => ({
|
|
1076
|
-
selector: tag,
|
|
1077
|
-
options: {
|
|
1078
|
-
uppercase: false
|
|
1079
|
-
}
|
|
1080
|
-
}))
|
|
688
|
+
return {
|
|
689
|
+
[`${runtimeModule_RuntimeModuleID.SearchHooks}${extname}`]: content
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
function createHash(str) {
|
|
693
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__.createHash)('sha256').update(str).digest('hex').slice(0, 8);
|
|
694
|
+
}
|
|
695
|
+
let flattenMdxContent_resolver;
|
|
696
|
+
let startFlatten = false;
|
|
697
|
+
const processor = (0, __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__.createProcessor)();
|
|
698
|
+
const { CachedInputFileSystem, ResolverFactory } = __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__["default"];
|
|
699
|
+
async function resolveDepPath(importPath, importer, alias) {
|
|
700
|
+
if (!flattenMdxContent_resolver) flattenMdxContent_resolver = ResolverFactory.createResolver({
|
|
701
|
+
fileSystem: new CachedInputFileSystem(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"], 0),
|
|
702
|
+
extensions: [
|
|
703
|
+
'.mdx',
|
|
704
|
+
'.md'
|
|
1081
705
|
],
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
706
|
+
alias
|
|
707
|
+
});
|
|
708
|
+
const resolveResult = await new Promise((resolve, reject)=>{
|
|
709
|
+
flattenMdxContent_resolver.resolve({
|
|
710
|
+
importer
|
|
711
|
+
}, importer, importPath, {}, (err, filePath)=>{
|
|
712
|
+
if (err) return reject(err);
|
|
713
|
+
if (!filePath) return reject(new Error(`Empty result when resolving ${importPath} from ${importer}`));
|
|
714
|
+
return resolve(filePath);
|
|
715
|
+
});
|
|
716
|
+
});
|
|
717
|
+
return resolveResult;
|
|
718
|
+
}
|
|
719
|
+
async function flattenMdxContent(content, basePath, alias) {
|
|
720
|
+
const deps = [];
|
|
721
|
+
const regex = new RegExp(importStatementRegex);
|
|
722
|
+
if (!regex.test(content)) return {
|
|
723
|
+
flattenContent: content,
|
|
724
|
+
deps
|
|
725
|
+
};
|
|
726
|
+
if (!startFlatten) {
|
|
727
|
+
flattenMdxContent_resolver = ResolverFactory.createResolver({
|
|
728
|
+
fileSystem: new CachedInputFileSystem(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"], 0),
|
|
729
|
+
extensions: [
|
|
730
|
+
'.mdx',
|
|
731
|
+
'.md',
|
|
732
|
+
'.js'
|
|
733
|
+
],
|
|
734
|
+
alias
|
|
735
|
+
});
|
|
736
|
+
startFlatten = true;
|
|
737
|
+
}
|
|
738
|
+
let ast;
|
|
739
|
+
let result = content;
|
|
740
|
+
try {
|
|
741
|
+
ast = processor.parse(content);
|
|
742
|
+
} catch (e) {
|
|
743
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug('flattenMdxContent parse failed: \n', e);
|
|
1105
744
|
return {
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
${item.text}#
|
|
1109
|
-
|
|
1110
|
-
`, position + 1)
|
|
745
|
+
flattenContent: content,
|
|
746
|
+
deps
|
|
1111
747
|
};
|
|
1112
|
-
});
|
|
1113
|
-
return {
|
|
1114
|
-
...defaultIndexInfo,
|
|
1115
|
-
title: frontmatter.title || title,
|
|
1116
|
-
toc,
|
|
1117
|
-
// Stripped frontmatter content
|
|
1118
|
-
content,
|
|
1119
|
-
_html: html,
|
|
1120
|
-
frontmatter: {
|
|
1121
|
-
...frontmatter,
|
|
1122
|
-
__content: void 0
|
|
1123
|
-
}
|
|
1124
|
-
};
|
|
1125
|
-
})
|
|
1126
|
-
);
|
|
1127
|
-
return pageData.filter(Boolean);
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
// src/node/runtimeModule/siteData/highlightLanguages.ts
|
|
1131
|
-
import { DEFAULT_HIGHLIGHT_LANGUAGES } from "@rspress/shared";
|
|
1132
|
-
import chalk from "@rspress/shared/chalk";
|
|
1133
|
-
var supportedLanguages;
|
|
1134
|
-
function handleHighlightLanguages(highlightLanguages, defaultLanguages) {
|
|
1135
|
-
const aliases = {};
|
|
1136
|
-
if (highlightLanguages.size) {
|
|
1137
|
-
if (!supportedLanguages) {
|
|
1138
|
-
const langs = __require("react-syntax-highlighter/dist/cjs/languages/prism/supported-languages").default;
|
|
1139
|
-
supportedLanguages = new Set(langs);
|
|
1140
748
|
}
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
"
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
if (name && supportedLanguages.has(name)) {
|
|
1160
|
-
const temp = aliases[name] || (aliases[name] = []);
|
|
1161
|
-
if (!temp.includes(lang)) {
|
|
1162
|
-
temp.push(lang);
|
|
749
|
+
const importNodes = ast.children.filter((node)=>'mdxjsEsm' === node.type).flatMap((node)=>{
|
|
750
|
+
var _node_data_estree, _node_data;
|
|
751
|
+
return (null === (_node_data = node.data) || void 0 === _node_data ? void 0 : null === (_node_data_estree = _node_data.estree) || void 0 === _node_data_estree ? void 0 : _node_data_estree.body) || [];
|
|
752
|
+
}).filter((node)=>'ImportDeclaration' === node.type);
|
|
753
|
+
for (const importNode of importNodes){
|
|
754
|
+
const id = importNode.specifiers[0].local.name;
|
|
755
|
+
const importPath = importNode.source.value;
|
|
756
|
+
let absoluteImportPath;
|
|
757
|
+
try {
|
|
758
|
+
absoluteImportPath = await resolveDepPath(importPath, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(basePath), alias);
|
|
759
|
+
} catch (e) {
|
|
760
|
+
continue;
|
|
761
|
+
}
|
|
762
|
+
if (__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_REGEXP.test(absoluteImportPath)) {
|
|
763
|
+
const importedContent = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(absoluteImportPath, 'utf-8');
|
|
764
|
+
const { flattenContent: replacedValue, deps: subDeps } = await flattenMdxContent(importedContent, absoluteImportPath, alias);
|
|
765
|
+
result = result.replace(new RegExp(`import\\s+${id}\\s+from\\s+['"](${importPath})['"];?`), '').replace(new RegExp(`<${id}\\s*/>`, 'g'), ()=>replacedValue);
|
|
766
|
+
deps.push(...subDeps, absoluteImportPath);
|
|
1163
767
|
}
|
|
1164
|
-
highlightLanguages.delete(lang);
|
|
1165
|
-
highlightLanguages.add(name);
|
|
1166
|
-
return;
|
|
1167
|
-
}
|
|
1168
|
-
if (!supportedLanguages.has(lang)) {
|
|
1169
|
-
highlightLanguages.delete(lang);
|
|
1170
|
-
}
|
|
1171
|
-
});
|
|
1172
|
-
}
|
|
1173
|
-
return aliases;
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
// src/node/runtimeModule/siteData/normalizeThemeConfig.ts
|
|
1177
|
-
import {
|
|
1178
|
-
addLeadingSlash as addLeadingSlash2,
|
|
1179
|
-
isExternalUrl,
|
|
1180
|
-
slash as slash2,
|
|
1181
|
-
withBase as withBase2,
|
|
1182
|
-
withoutBase
|
|
1183
|
-
} from "@rspress/shared";
|
|
1184
|
-
function normalizeThemeConfig(docConfig, pages = []) {
|
|
1185
|
-
const {
|
|
1186
|
-
locales: siteLocales,
|
|
1187
|
-
base = "",
|
|
1188
|
-
lang,
|
|
1189
|
-
replaceRules = [],
|
|
1190
|
-
multiVersion
|
|
1191
|
-
} = docConfig;
|
|
1192
|
-
const { versions = [] } = multiVersion || {};
|
|
1193
|
-
const hasMultiVersion = versions.length > 0;
|
|
1194
|
-
docConfig.themeConfig = docConfig.themeConfig || {};
|
|
1195
|
-
const { themeConfig } = docConfig;
|
|
1196
|
-
const locales = siteLocales ?? (themeConfig?.locales || []);
|
|
1197
|
-
const i18nTextData = getI18nData(docConfig);
|
|
1198
|
-
const normalizeLinkPrefix = (link = "", currentLang = "") => {
|
|
1199
|
-
const normalizedLink = slash2(link);
|
|
1200
|
-
if (!currentLang || !link || withoutBase(normalizedLink, base).startsWith(`/${currentLang}`) || isExternalUrl(normalizedLink) || // In multi version case, we have got the complete link prefix in `plugin-auto-nav-sidebar` and does not need to add the lang prefix
|
|
1201
|
-
hasMultiVersion) {
|
|
1202
|
-
return normalizedLink;
|
|
1203
|
-
}
|
|
1204
|
-
return lang === currentLang ? normalizedLink : `/${currentLang}${addLeadingSlash2(normalizedLink)}`;
|
|
1205
|
-
};
|
|
1206
|
-
const getI18nText = (key = "", currentLang = "") => {
|
|
1207
|
-
const text = i18nTextData[key]?.[currentLang];
|
|
1208
|
-
return text || key;
|
|
1209
|
-
};
|
|
1210
|
-
const normalizeSidebar = (sidebar, currentLang = "") => {
|
|
1211
|
-
const normalizedSidebar = {};
|
|
1212
|
-
if (!sidebar) {
|
|
1213
|
-
return {};
|
|
1214
768
|
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
769
|
+
return {
|
|
770
|
+
flattenContent: result,
|
|
771
|
+
deps
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
function applyReplaceRules(code = '', replaceRules = []) {
|
|
775
|
+
let result = code;
|
|
776
|
+
for (const rule of replaceRules)result = result.replace(rule.search, rule.replace);
|
|
777
|
+
return result;
|
|
778
|
+
}
|
|
779
|
+
function applyReplaceRulesToNestedObject(obj, replaceRules) {
|
|
780
|
+
for(const key in obj)if ('string' == typeof obj[key]) obj[key] = applyReplaceRules(obj[key], replaceRules);
|
|
781
|
+
else if ('object' == typeof obj[key]) obj[key] = applyReplaceRulesToNestedObject(obj[key], replaceRules);
|
|
782
|
+
return obj;
|
|
783
|
+
}
|
|
784
|
+
async function extractPageData(replaceRules, alias, domain, root, routeService, highlighterLangs, searchCodeBlocks) {
|
|
785
|
+
const pageData = await Promise.all(routeService.getRoutes().map(async (route, index)=>{
|
|
786
|
+
var _frontmatter_title;
|
|
787
|
+
const defaultIndexInfo = {
|
|
788
|
+
id: index,
|
|
789
|
+
title: '',
|
|
790
|
+
content: '',
|
|
791
|
+
_html: '',
|
|
792
|
+
routePath: route.routePath,
|
|
793
|
+
lang: route.lang,
|
|
794
|
+
toc: [],
|
|
795
|
+
domain,
|
|
796
|
+
frontmatter: {},
|
|
797
|
+
version: route.version,
|
|
798
|
+
_filepath: route.absolutePath,
|
|
799
|
+
_relativePath: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, route.absolutePath).split(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].sep).join('/')
|
|
1240
800
|
};
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
const
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
);
|
|
801
|
+
if (!__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_REGEXP.test(route.absolutePath)) return defaultIndexInfo;
|
|
802
|
+
let content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, 'utf8');
|
|
803
|
+
const { frontmatter, content: strippedFrontMatter } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.loadFrontMatter)(content, route.absolutePath, root);
|
|
804
|
+
applyReplaceRulesToNestedObject(frontmatter, replaceRules);
|
|
805
|
+
const { flattenContent } = await flattenMdxContent(applyReplaceRules(strippedFrontMatter, replaceRules), route.absolutePath, alias);
|
|
806
|
+
content = flattenContent.replace(importStatementRegex, '');
|
|
807
|
+
const { html, title, toc: rawToc, languages } = await (0, __WEBPACK_EXTERNAL_MODULE__rspress_mdx_rs_d2f3021f__.compile)({
|
|
808
|
+
value: content,
|
|
809
|
+
filepath: route.absolutePath,
|
|
810
|
+
development: 'production' !== process.env.NODE_ENV,
|
|
811
|
+
root
|
|
812
|
+
});
|
|
813
|
+
if (!(null == title ? void 0 : title.length) && !frontmatter && !(null === (_frontmatter_title = frontmatter.title) || void 0 === _frontmatter_title ? void 0 : _frontmatter_title.length)) return null;
|
|
814
|
+
content = (0, __WEBPACK_EXTERNAL_MODULE_html_to_text_2c51ed38__.htmlToText)(String(html), {
|
|
815
|
+
wordwrap: 80,
|
|
816
|
+
selectors: [
|
|
817
|
+
{
|
|
818
|
+
selector: 'a',
|
|
819
|
+
options: {
|
|
820
|
+
ignoreHref: true
|
|
821
|
+
}
|
|
822
|
+
},
|
|
823
|
+
{
|
|
824
|
+
selector: 'img',
|
|
825
|
+
format: 'skip'
|
|
826
|
+
},
|
|
827
|
+
{
|
|
828
|
+
selector: 'pre > code',
|
|
829
|
+
format: searchCodeBlocks ? 'block' : 'skip'
|
|
830
|
+
},
|
|
831
|
+
...[
|
|
832
|
+
'h1',
|
|
833
|
+
'h2',
|
|
834
|
+
'h3',
|
|
835
|
+
'h4',
|
|
836
|
+
'h5',
|
|
837
|
+
'h6'
|
|
838
|
+
].map((tag)=>({
|
|
839
|
+
selector: tag,
|
|
840
|
+
options: {
|
|
841
|
+
uppercase: false
|
|
842
|
+
}
|
|
843
|
+
}))
|
|
844
|
+
],
|
|
845
|
+
tables: true,
|
|
846
|
+
longWordSplit: {
|
|
847
|
+
forceWrapOnLimit: true
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
if (content.startsWith(title)) content = content.slice(title.length);
|
|
851
|
+
languages.forEach((lang)=>highlighterLangs.add(lang));
|
|
852
|
+
const toc = rawToc.map((item)=>{
|
|
853
|
+
const match = item.id.match(/-(\d+)$/);
|
|
854
|
+
let position = -1;
|
|
855
|
+
if (match) for(let i = 0; i < Number(match[1]); i++){
|
|
856
|
+
position = content.indexOf(`\n${item.text}#\n\n`, position + 1);
|
|
857
|
+
if (-1 === position) break;
|
|
858
|
+
}
|
|
859
|
+
return {
|
|
860
|
+
...item,
|
|
861
|
+
charIndex: content.indexOf(`\n${item.text}#\n\n`, position + 1)
|
|
862
|
+
};
|
|
863
|
+
});
|
|
1247
864
|
return {
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
865
|
+
...defaultIndexInfo,
|
|
866
|
+
title: frontmatter.title || title,
|
|
867
|
+
toc,
|
|
868
|
+
content,
|
|
869
|
+
_html: html,
|
|
870
|
+
frontmatter: {
|
|
871
|
+
...frontmatter,
|
|
872
|
+
__content: void 0
|
|
873
|
+
}
|
|
1251
874
|
};
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
875
|
+
}));
|
|
876
|
+
return pageData.filter(Boolean);
|
|
877
|
+
}
|
|
878
|
+
const highlightLanguages_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url);
|
|
879
|
+
let highlightLanguages_supportedLanguages;
|
|
880
|
+
function handleHighlightLanguages(highlightLanguages, defaultLanguages) {
|
|
881
|
+
const aliases = {};
|
|
882
|
+
if (highlightLanguages.size) {
|
|
883
|
+
if (!highlightLanguages_supportedLanguages) {
|
|
884
|
+
const langs = highlightLanguages_require('react-syntax-highlighter/dist/cjs/languages/prism/supported-languages').default;
|
|
885
|
+
highlightLanguages_supportedLanguages = new Set(langs);
|
|
886
|
+
}
|
|
887
|
+
let useDeprecatedTypeWarning = true;
|
|
888
|
+
const names = {};
|
|
889
|
+
[
|
|
890
|
+
...__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.DEFAULT_HIGHLIGHT_LANGUAGES,
|
|
891
|
+
...defaultLanguages
|
|
892
|
+
].forEach((lang)=>{
|
|
893
|
+
if (Array.isArray(lang)) {
|
|
894
|
+
const [alias, name] = lang;
|
|
895
|
+
names[alias] = name;
|
|
896
|
+
} else if (useDeprecatedTypeWarning) {
|
|
897
|
+
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`);
|
|
898
|
+
useDeprecatedTypeWarning = false;
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
[
|
|
902
|
+
...highlightLanguages.values()
|
|
903
|
+
].forEach((lang)=>{
|
|
904
|
+
const name = names[lang];
|
|
905
|
+
if (name && highlightLanguages_supportedLanguages.has(name)) {
|
|
906
|
+
const temp = aliases[name] || (aliases[name] = []);
|
|
907
|
+
if (!temp.includes(lang)) temp.push(lang);
|
|
908
|
+
highlightLanguages.delete(lang);
|
|
909
|
+
highlightLanguages.add(name);
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
if (!highlightLanguages_supportedLanguages.has(lang)) highlightLanguages.delete(lang);
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
return aliases;
|
|
916
|
+
}
|
|
917
|
+
function normalizeThemeConfig(docConfig, pages = []) {
|
|
918
|
+
const { locales: siteLocales, base = '', lang, replaceRules = [], multiVersion } = docConfig;
|
|
919
|
+
const { versions = [] } = multiVersion || {};
|
|
920
|
+
const hasMultiVersion = versions.length > 0;
|
|
921
|
+
docConfig.themeConfig = docConfig.themeConfig || {};
|
|
922
|
+
const { themeConfig } = docConfig;
|
|
923
|
+
const locales = siteLocales ?? ((null == themeConfig ? void 0 : themeConfig.locales) || []);
|
|
924
|
+
const i18nTextData = getI18nData(docConfig);
|
|
925
|
+
const normalizeLinkPrefix = (link = '', currentLang = '')=>{
|
|
926
|
+
const normalizedLink = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(link);
|
|
927
|
+
if (!currentLang || !link || (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withoutBase)(normalizedLink, base).startsWith(`/${currentLang}`) || (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(normalizedLink) || hasMultiVersion) return normalizedLink;
|
|
928
|
+
return lang === currentLang ? normalizedLink : `/${currentLang}${(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)(normalizedLink)}`;
|
|
1262
929
|
};
|
|
1263
|
-
const
|
|
1264
|
-
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1267
|
-
});
|
|
930
|
+
const getI18nText = (key = '', currentLang = '')=>{
|
|
931
|
+
var _i18nTextData_key;
|
|
932
|
+
const text = null === (_i18nTextData_key = i18nTextData[key]) || void 0 === _i18nTextData_key ? void 0 : _i18nTextData_key[currentLang];
|
|
933
|
+
return text || key;
|
|
1268
934
|
};
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
935
|
+
const normalizeSidebar = (sidebar, currentLang = '')=>{
|
|
936
|
+
const normalizedSidebar = {};
|
|
937
|
+
if (!sidebar) return {};
|
|
938
|
+
const normalizeSidebarItem = (item)=>{
|
|
939
|
+
if ('object' == typeof item && 'dividerType' in item) return item;
|
|
940
|
+
if ('object' == typeof item && 'sectionHeaderText' in item) {
|
|
941
|
+
item.sectionHeaderText = applyReplaceRules(getI18nText(item.sectionHeaderText, currentLang), replaceRules);
|
|
942
|
+
return item;
|
|
943
|
+
}
|
|
944
|
+
if ('object' == typeof item && 'items' in item) return {
|
|
945
|
+
...item,
|
|
946
|
+
text: applyReplaceRules(getI18nText(item.text, currentLang), replaceRules),
|
|
947
|
+
link: normalizeLinkPrefix(item.link),
|
|
948
|
+
collapsed: item.collapsed ?? false,
|
|
949
|
+
collapsible: item.collapsible ?? true,
|
|
950
|
+
tag: item.tag,
|
|
951
|
+
items: item.items.map((subItem)=>normalizeSidebarItem(subItem))
|
|
952
|
+
};
|
|
953
|
+
if ('string' == typeof item) {
|
|
954
|
+
const normalizedItem = normalizeLinkPrefix(item, currentLang);
|
|
955
|
+
const page = pages.find((page)=>page.routePath === (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(normalizedItem, base));
|
|
956
|
+
return {
|
|
957
|
+
text: applyReplaceRules((null == page ? void 0 : page.title) || '', replaceRules),
|
|
958
|
+
link: normalizedItem,
|
|
959
|
+
_fileKey: page._relativePath.replace(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(page._relativePath), '')
|
|
960
|
+
};
|
|
961
|
+
}
|
|
1293
962
|
return {
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
),
|
|
1299
|
-
link: normalizeLinkPrefix(item.link, currentLang)
|
|
963
|
+
...item,
|
|
964
|
+
text: applyReplaceRules(getI18nText(item.text, currentLang), replaceRules),
|
|
965
|
+
link: normalizeLinkPrefix(item.link),
|
|
966
|
+
tag: item.tag
|
|
1300
967
|
};
|
|
1301
|
-
})
|
|
1302
968
|
};
|
|
1303
|
-
|
|
1304
|
-
|
|
969
|
+
const normalizeSidebar = (sidebar)=>{
|
|
970
|
+
Object.keys(sidebar).forEach((key)=>{
|
|
971
|
+
const value = sidebar[key];
|
|
972
|
+
normalizedSidebar[key] = value.map(normalizeSidebarItem);
|
|
973
|
+
});
|
|
974
|
+
};
|
|
975
|
+
normalizeSidebar(sidebar);
|
|
976
|
+
return normalizedSidebar;
|
|
1305
977
|
};
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
)
|
|
1327
|
-
nav
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
)
|
|
1331
|
-
|
|
978
|
+
const normalizeNav = (nav, currentLang)=>{
|
|
979
|
+
if (!nav) return [];
|
|
980
|
+
const transformNavItem = (navItem)=>{
|
|
981
|
+
const text = applyReplaceRules(getI18nText(navItem.text, currentLang), replaceRules);
|
|
982
|
+
if ('link' in navItem) return {
|
|
983
|
+
...navItem,
|
|
984
|
+
text,
|
|
985
|
+
link: normalizeLinkPrefix(navItem.link, currentLang)
|
|
986
|
+
};
|
|
987
|
+
if ('items' in navItem) return {
|
|
988
|
+
...navItem,
|
|
989
|
+
text,
|
|
990
|
+
items: navItem.items.map((item)=>({
|
|
991
|
+
...item,
|
|
992
|
+
text: applyReplaceRules(getI18nText(item.text, currentLang), replaceRules),
|
|
993
|
+
link: normalizeLinkPrefix(item.link, currentLang)
|
|
994
|
+
}))
|
|
995
|
+
};
|
|
996
|
+
return navItem;
|
|
997
|
+
};
|
|
998
|
+
if (Array.isArray(nav)) return nav.map(transformNavItem);
|
|
999
|
+
return Object.entries(nav).reduce((acc, [key, value])=>{
|
|
1000
|
+
acc[key] = value.map(transformNavItem);
|
|
1001
|
+
return acc;
|
|
1002
|
+
}, {});
|
|
1003
|
+
};
|
|
1004
|
+
if (locales.length) themeConfig.locales = locales.map(({ lang: currentLang, label })=>{
|
|
1005
|
+
var _themeConfig_locales;
|
|
1006
|
+
const localeInThemeConfig = null === (_themeConfig_locales = themeConfig.locales) || void 0 === _themeConfig_locales ? void 0 : _themeConfig_locales.find((locale)=>locale.lang === currentLang);
|
|
1007
|
+
return {
|
|
1008
|
+
lang: currentLang,
|
|
1009
|
+
label,
|
|
1010
|
+
...localeInThemeConfig || {},
|
|
1011
|
+
sidebar: normalizeSidebar((null == localeInThemeConfig ? void 0 : localeInThemeConfig.sidebar) ?? themeConfig.sidebar, currentLang),
|
|
1012
|
+
nav: normalizeNav((null == localeInThemeConfig ? void 0 : localeInThemeConfig.nav) ?? themeConfig.nav, currentLang)
|
|
1013
|
+
};
|
|
1332
1014
|
});
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
}
|
|
1337
|
-
return themeConfig;
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
// src/node/runtimeModule/siteData/index.ts
|
|
1341
|
-
function deletePrivateField(obj) {
|
|
1342
|
-
if (typeof obj !== "object" || obj === null) {
|
|
1343
|
-
return obj;
|
|
1344
|
-
}
|
|
1345
|
-
const newObj = { ...obj };
|
|
1346
|
-
Object.keys(newObj).forEach((key) => {
|
|
1347
|
-
if (key.startsWith("_")) {
|
|
1348
|
-
delete newObj[key];
|
|
1015
|
+
else {
|
|
1016
|
+
themeConfig.sidebar = normalizeSidebar(null == themeConfig ? void 0 : themeConfig.sidebar);
|
|
1017
|
+
themeConfig.nav = normalizeNav(null == themeConfig ? void 0 : themeConfig.nav);
|
|
1349
1018
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1019
|
+
return themeConfig;
|
|
1020
|
+
}
|
|
1021
|
+
function deletePrivateField(obj) {
|
|
1022
|
+
if ('object' != typeof obj || null === obj) return obj;
|
|
1023
|
+
const newObj = {
|
|
1024
|
+
...obj
|
|
1025
|
+
};
|
|
1026
|
+
Object.keys(newObj).forEach((key)=>{
|
|
1027
|
+
if (key.startsWith('_')) delete newObj[key];
|
|
1028
|
+
});
|
|
1029
|
+
return newObj;
|
|
1352
1030
|
}
|
|
1353
1031
|
async function siteDataVMPlugin(context) {
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
tempSearchObj.searchHooks = void 0;
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
markdown: {
|
|
1431
|
-
showLineNumbers: userConfig?.markdown?.showLineNumbers ?? false,
|
|
1432
|
-
defaultWrapCode: userConfig?.markdown?.defaultWrapCode ?? false,
|
|
1433
|
-
codeHighlighter: userConfig?.markdown?.codeHighlighter || "prism"
|
|
1434
|
-
}
|
|
1435
|
-
};
|
|
1436
|
-
const { highlightLanguages: defaultLanguages = [] } = config.markdown || {};
|
|
1437
|
-
if (siteData.pages[0]?.extraHighlightLanguages?.length) {
|
|
1438
|
-
siteData.pages[0].extraHighlightLanguages.forEach(
|
|
1439
|
-
(lang) => highlightLanguages.add(lang)
|
|
1440
|
-
);
|
|
1441
|
-
}
|
|
1442
|
-
const aliases = handleHighlightLanguages(
|
|
1443
|
-
highlightLanguages,
|
|
1444
|
-
defaultLanguages
|
|
1445
|
-
);
|
|
1446
|
-
const sortedAliases = Object.fromEntries(Object.entries(aliases).sort());
|
|
1447
|
-
const sortedHighlightLanguages = Array.from(highlightLanguages).sort();
|
|
1448
|
-
return {
|
|
1449
|
-
[`${"virtual-site-data" /* SiteData */}.mjs`]: `export default ${JSON.stringify(
|
|
1450
|
-
siteData,
|
|
1451
|
-
null,
|
|
1452
|
-
2
|
|
1453
|
-
)}`,
|
|
1454
|
-
["virtual-search-index-hash" /* SearchIndexHash */]: `export default ${JSON.stringify(
|
|
1455
|
-
indexHashByGroup,
|
|
1456
|
-
null,
|
|
1457
|
-
2
|
|
1458
|
-
)}`,
|
|
1459
|
-
["virtual-prism-languages" /* PrismLanguages */]: `export const aliases = ${JSON.stringify(
|
|
1460
|
-
sortedAliases,
|
|
1461
|
-
null,
|
|
1462
|
-
2
|
|
1463
|
-
)};
|
|
1032
|
+
var _userConfig_themeConfig, _userConfig_multiVersion, _userConfig_multiVersion1, _userConfig_markdown, _userConfig_markdown1, _userConfig_markdown2, _siteData_pages__extraHighlightLanguages, _siteData_pages_;
|
|
1033
|
+
const { config, alias, userDocRoot, routeService, pluginDriver } = context;
|
|
1034
|
+
const userConfig = config;
|
|
1035
|
+
const tempSearchObj = Object.assign({}, userConfig.search);
|
|
1036
|
+
if (tempSearchObj) tempSearchObj.searchHooks = void 0;
|
|
1037
|
+
const highlightLanguages = new Set();
|
|
1038
|
+
const replaceRules = (null == userConfig ? void 0 : userConfig.replaceRules) || [];
|
|
1039
|
+
const searchConfig = (null == userConfig ? void 0 : userConfig.search) || {};
|
|
1040
|
+
const domain = (null == searchConfig ? void 0 : searchConfig.mode) === 'remote' ? searchConfig.domain ?? '' : '';
|
|
1041
|
+
const searchCodeBlocks = 'codeBlocks' in searchConfig && searchConfig.codeBlocks;
|
|
1042
|
+
const pages = await extractPageData(replaceRules, alias, domain, userDocRoot, routeService, highlightLanguages, searchCodeBlocks);
|
|
1043
|
+
await pluginDriver.modifySearchIndexData(pages);
|
|
1044
|
+
const versioned = userConfig.search && 'remote' !== userConfig.search.mode && userConfig.search.versioned;
|
|
1045
|
+
const groupedPages = (0, __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__.groupBy)(pages, (page)=>{
|
|
1046
|
+
var _page_frontmatter;
|
|
1047
|
+
if ((null === (_page_frontmatter = page.frontmatter) || void 0 === _page_frontmatter ? void 0 : _page_frontmatter.pageType) === 'home') return 'noindex';
|
|
1048
|
+
const version = versioned ? page.version : '';
|
|
1049
|
+
const lang = page.lang || '';
|
|
1050
|
+
return `${version}###${lang}`;
|
|
1051
|
+
});
|
|
1052
|
+
delete groupedPages.noindex;
|
|
1053
|
+
const indexHashByGroup = {};
|
|
1054
|
+
await Promise.all(Object.keys(groupedPages).map(async (group)=>{
|
|
1055
|
+
const stringifiedIndex = JSON.stringify(groupedPages[group].map(deletePrivateField));
|
|
1056
|
+
const indexHash = createHash(stringifiedIndex);
|
|
1057
|
+
indexHashByGroup[group] = indexHash;
|
|
1058
|
+
const [version, lang] = group.split('###');
|
|
1059
|
+
const indexVersion = version ? `.${version.replace('.', '_')}` : '';
|
|
1060
|
+
const indexLang = lang ? `.${lang}` : '';
|
|
1061
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(TEMP_DIR, {
|
|
1062
|
+
recursive: true
|
|
1063
|
+
});
|
|
1064
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(TEMP_DIR, `${__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME}${indexVersion}${indexLang}.${indexHash}.json`), stringifiedIndex);
|
|
1065
|
+
}));
|
|
1066
|
+
await Promise.all(pages.map(async (pageData)=>pluginDriver.extendPageData(pageData)));
|
|
1067
|
+
const siteData = {
|
|
1068
|
+
title: (null == userConfig ? void 0 : userConfig.title) || '',
|
|
1069
|
+
description: (null == userConfig ? void 0 : userConfig.description) || '',
|
|
1070
|
+
icon: (null == userConfig ? void 0 : userConfig.icon) || '',
|
|
1071
|
+
route: null == userConfig ? void 0 : userConfig.route,
|
|
1072
|
+
themeConfig: normalizeThemeConfig(userConfig, pages),
|
|
1073
|
+
base: (null == userConfig ? void 0 : userConfig.base) || '/',
|
|
1074
|
+
lang: (null == userConfig ? void 0 : userConfig.lang) || '',
|
|
1075
|
+
locales: (null == userConfig ? void 0 : userConfig.locales) || (null === (_userConfig_themeConfig = userConfig.themeConfig) || void 0 === _userConfig_themeConfig ? void 0 : _userConfig_themeConfig.locales) || [],
|
|
1076
|
+
logo: (null == userConfig ? void 0 : userConfig.logo) || '',
|
|
1077
|
+
logoText: (null == userConfig ? void 0 : userConfig.logoText) || '',
|
|
1078
|
+
ssg: Boolean(null == userConfig ? void 0 : userConfig.ssg) ?? true,
|
|
1079
|
+
multiVersion: {
|
|
1080
|
+
default: (null == userConfig ? void 0 : null === (_userConfig_multiVersion = userConfig.multiVersion) || void 0 === _userConfig_multiVersion ? void 0 : _userConfig_multiVersion.default) || '',
|
|
1081
|
+
versions: (null == userConfig ? void 0 : null === (_userConfig_multiVersion1 = userConfig.multiVersion) || void 0 === _userConfig_multiVersion1 ? void 0 : _userConfig_multiVersion1.versions) || []
|
|
1082
|
+
},
|
|
1083
|
+
search: tempSearchObj ?? {
|
|
1084
|
+
mode: 'local'
|
|
1085
|
+
},
|
|
1086
|
+
pages: pages.map((page)=>{
|
|
1087
|
+
const { content, id, domain, _filepath, _html, ...rest } = page;
|
|
1088
|
+
return isProduction() ? rest : {
|
|
1089
|
+
...rest,
|
|
1090
|
+
_filepath
|
|
1091
|
+
};
|
|
1092
|
+
}),
|
|
1093
|
+
markdown: {
|
|
1094
|
+
showLineNumbers: (null == userConfig ? void 0 : null === (_userConfig_markdown = userConfig.markdown) || void 0 === _userConfig_markdown ? void 0 : _userConfig_markdown.showLineNumbers) ?? false,
|
|
1095
|
+
defaultWrapCode: (null == userConfig ? void 0 : null === (_userConfig_markdown1 = userConfig.markdown) || void 0 === _userConfig_markdown1 ? void 0 : _userConfig_markdown1.defaultWrapCode) ?? false,
|
|
1096
|
+
codeHighlighter: (null == userConfig ? void 0 : null === (_userConfig_markdown2 = userConfig.markdown) || void 0 === _userConfig_markdown2 ? void 0 : _userConfig_markdown2.codeHighlighter) || 'prism'
|
|
1097
|
+
}
|
|
1098
|
+
};
|
|
1099
|
+
const { highlightLanguages: defaultLanguages = [] } = config.markdown || {};
|
|
1100
|
+
if (null === (_siteData_pages_ = siteData.pages[0]) || void 0 === _siteData_pages_ ? void 0 : null === (_siteData_pages__extraHighlightLanguages = _siteData_pages_.extraHighlightLanguages) || void 0 === _siteData_pages__extraHighlightLanguages ? void 0 : _siteData_pages__extraHighlightLanguages.length) siteData.pages[0].extraHighlightLanguages.forEach((lang)=>highlightLanguages.add(lang));
|
|
1101
|
+
const aliases = handleHighlightLanguages(highlightLanguages, defaultLanguages);
|
|
1102
|
+
const sortedAliases = Object.fromEntries(Object.entries(aliases).sort());
|
|
1103
|
+
const sortedHighlightLanguages = Array.from(highlightLanguages).sort();
|
|
1104
|
+
return {
|
|
1105
|
+
[`${runtimeModule_RuntimeModuleID.SiteData}.mjs`]: `export default ${JSON.stringify(siteData, null, 2)}`,
|
|
1106
|
+
[runtimeModule_RuntimeModuleID.SearchIndexHash]: `export default ${JSON.stringify(indexHashByGroup, null, 2)}`,
|
|
1107
|
+
[runtimeModule_RuntimeModuleID.PrismLanguages]: `export const aliases = ${JSON.stringify(sortedAliases, null, 2)};
|
|
1464
1108
|
export const languages = {
|
|
1465
|
-
${sortedHighlightLanguages.map((lang)
|
|
1466
|
-
return `"${lang}": require(
|
|
1109
|
+
${sortedHighlightLanguages.map((lang)=>`"${lang}": require(
|
|
1467
1110
|
"react-syntax-highlighter/dist/cjs/languages/prism/${lang}"
|
|
1468
|
-
).default
|
|
1469
|
-
})}
|
|
1111
|
+
).default`)}
|
|
1470
1112
|
}`
|
|
1471
|
-
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
/**
|
|
1481
|
-
* Generate search index and site data for client runtime
|
|
1482
|
-
* Also responsible for automatically importing prism languages
|
|
1483
|
-
*/
|
|
1484
|
-
siteDataVMPlugin,
|
|
1485
|
-
/**
|
|
1486
|
-
* Generate global components from config and plugins
|
|
1487
|
-
*/
|
|
1488
|
-
globalUIComponentsVMPlugin,
|
|
1489
|
-
/**
|
|
1490
|
-
* Generate global styles from config and plugins
|
|
1491
|
-
*/
|
|
1492
|
-
globalStylesVMPlugin,
|
|
1493
|
-
/**
|
|
1494
|
-
* Generate i18n text for client runtime
|
|
1495
|
-
*/
|
|
1496
|
-
i18nVMPlugin,
|
|
1497
|
-
/**
|
|
1498
|
-
* Generate search hook module
|
|
1499
|
-
*/
|
|
1500
|
-
searchHookVMPlugin
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
const runtimeModuleFactory = [
|
|
1116
|
+
routeVMPlugin,
|
|
1117
|
+
siteDataVMPlugin,
|
|
1118
|
+
globalUIComponentsVMPlugin,
|
|
1119
|
+
globalStylesVMPlugin,
|
|
1120
|
+
i18nVMPlugin,
|
|
1121
|
+
searchHookVMPlugin
|
|
1501
1122
|
];
|
|
1502
1123
|
function rsbuildPluginDocVM(factoryContext) {
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1124
|
+
const { pluginDriver } = factoryContext;
|
|
1125
|
+
return {
|
|
1126
|
+
name: 'rsbuild-plugin-doc-vm',
|
|
1127
|
+
setup (api) {
|
|
1128
|
+
api.modifyBundlerChain(async (bundlerChain, { target })=>{
|
|
1129
|
+
const isServer = 'node' === target;
|
|
1130
|
+
const alias = bundlerChain.resolve.alias.entries();
|
|
1131
|
+
const runtimeModule = {};
|
|
1132
|
+
for (const factory of runtimeModuleFactory){
|
|
1133
|
+
const moduleResult = await factory({
|
|
1134
|
+
...factoryContext,
|
|
1135
|
+
isSSR: isServer,
|
|
1136
|
+
alias: alias
|
|
1137
|
+
});
|
|
1138
|
+
Object.assign(runtimeModule, moduleResult);
|
|
1139
|
+
}
|
|
1140
|
+
const modulesByPlugin = await pluginDriver.addRuntimeModules();
|
|
1141
|
+
Object.keys(modulesByPlugin).forEach((key)=>{
|
|
1142
|
+
if (runtimeModule[key]) throw new Error(`The runtime module ${key} is duplicated, please check your plugin`);
|
|
1143
|
+
runtimeModule[key] = modulesByPlugin[key];
|
|
1144
|
+
});
|
|
1145
|
+
bundlerChain.plugin('rspress-runtime-module').use(new __WEBPACK_EXTERNAL_MODULE_rspack_plugin_virtual_module_609978fd__.RspackVirtualModulePlugin(runtimeModule, factoryContext.runtimeTempDir));
|
|
1146
|
+
});
|
|
1518
1147
|
}
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
);
|
|
1534
|
-
});
|
|
1535
|
-
}
|
|
1536
|
-
};
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
// src/node/searchIndex.ts
|
|
1540
|
-
import { createReadStream } from "fs";
|
|
1541
|
-
import fs8 from "fs/promises";
|
|
1542
|
-
import path9, { join as join2 } from "path";
|
|
1543
|
-
import { SEARCH_INDEX_NAME as SEARCH_INDEX_NAME2, isSCM } from "@rspress/shared";
|
|
1544
|
-
import chalk2 from "@rspress/shared/chalk";
|
|
1545
|
-
import { logger as logger2 } from "@rspress/shared/logger";
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
var runtimeModule_RuntimeModuleID = /*#__PURE__*/ function(RuntimeModuleID) {
|
|
1151
|
+
RuntimeModuleID["GlobalStyles"] = "virtual-global-styles";
|
|
1152
|
+
RuntimeModuleID["GlobalComponents"] = "virtual-global-components";
|
|
1153
|
+
RuntimeModuleID["RouteForClient"] = "virtual-routes";
|
|
1154
|
+
RuntimeModuleID["RouteForSSR"] = "virtual-routes-ssr";
|
|
1155
|
+
RuntimeModuleID["SiteData"] = "virtual-site-data";
|
|
1156
|
+
RuntimeModuleID["SearchIndexHash"] = "virtual-search-index-hash";
|
|
1157
|
+
RuntimeModuleID["I18nText"] = "virtual-i18n-text";
|
|
1158
|
+
RuntimeModuleID["SearchHooks"] = "virtual-search-hooks";
|
|
1159
|
+
RuntimeModuleID["PrismLanguages"] = "virtual-prism-languages";
|
|
1160
|
+
return RuntimeModuleID;
|
|
1161
|
+
}({});
|
|
1546
1162
|
async function writeSearchIndex(config) {
|
|
1547
|
-
|
|
1548
|
-
return;
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1163
|
+
var _config_search;
|
|
1164
|
+
if ((null == config ? void 0 : config.search) === false) return;
|
|
1165
|
+
const cwd = process.cwd();
|
|
1166
|
+
const searchIndexFiles = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readdir(TEMP_DIR);
|
|
1167
|
+
const outDir = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, OUTPUT_DIR);
|
|
1168
|
+
const targetDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outDir, 'static');
|
|
1169
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(targetDir, {
|
|
1170
|
+
recursive: true
|
|
1171
|
+
});
|
|
1172
|
+
let searchIndexData = '[]';
|
|
1173
|
+
let scanning = false;
|
|
1174
|
+
for (const searchIndexFile of searchIndexFiles){
|
|
1175
|
+
if (!searchIndexFile.includes(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME) || !searchIndexFile.endsWith('.json')) continue;
|
|
1176
|
+
const source = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(TEMP_DIR, searchIndexFile);
|
|
1177
|
+
const target = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(targetDir, searchIndexFile);
|
|
1178
|
+
const searchIndex = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(TEMP_DIR, searchIndexFile), 'utf-8');
|
|
1179
|
+
searchIndexData = `${searchIndexData.slice(0, -1)}${scanning ? ',' : ''}${searchIndex.slice(1)}`;
|
|
1180
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].rename(source, target);
|
|
1181
|
+
scanning = true;
|
|
1560
1182
|
}
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
method: "PUT",
|
|
1576
|
-
body: searchIndexData,
|
|
1577
|
-
headers: { "Content-Type": "application/json" }
|
|
1578
|
-
});
|
|
1579
|
-
logger2.info(
|
|
1580
|
-
chalk2.green(
|
|
1581
|
-
`[doc-tools] Search index uploaded to ${apiUrl}, indexName: ${indexName}`
|
|
1582
|
-
)
|
|
1583
|
-
);
|
|
1584
|
-
} catch (e) {
|
|
1585
|
-
logger2.info(
|
|
1586
|
-
chalk2.red(
|
|
1587
|
-
`[doc-tools] Upload search index \`${indexName}\` failed:
|
|
1588
|
-
${e}`
|
|
1589
|
-
)
|
|
1590
|
-
);
|
|
1183
|
+
if (isProduction() && (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isSCM)() && (null == config ? void 0 : null === (_config_search = config.search) || void 0 === _config_search ? void 0 : _config_search.mode) === 'remote') {
|
|
1184
|
+
const { apiUrl, indexName } = config.search;
|
|
1185
|
+
try {
|
|
1186
|
+
await fetch(`${apiUrl}?index=${indexName}`, {
|
|
1187
|
+
method: 'PUT',
|
|
1188
|
+
body: searchIndexData,
|
|
1189
|
+
headers: {
|
|
1190
|
+
'Content-Type': 'application/json'
|
|
1191
|
+
}
|
|
1192
|
+
});
|
|
1193
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info(__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].green(`[doc-tools] Search index uploaded to ${apiUrl}, indexName: ${indexName}`));
|
|
1194
|
+
} catch (e) {
|
|
1195
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info(__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].red(`[doc-tools] Upload search index \`${indexName}\` failed:\n ${e}`));
|
|
1196
|
+
}
|
|
1591
1197
|
}
|
|
1592
|
-
}
|
|
1593
1198
|
}
|
|
1594
1199
|
function serveSearchIndexMiddleware(config) {
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
)
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1200
|
+
return (req, res, next)=>{
|
|
1201
|
+
var _req_url;
|
|
1202
|
+
const searchIndexRequestMatch = `/${__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME}.`;
|
|
1203
|
+
if (null === (_req_url = req.url) || void 0 === _req_url ? void 0 : _req_url.includes(searchIndexRequestMatch)) {
|
|
1204
|
+
var _req_url1;
|
|
1205
|
+
res.setHeader('Content-Type', 'application/json');
|
|
1206
|
+
const outDir = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), OUTPUT_DIR);
|
|
1207
|
+
const searchIndexFile = null === (_req_url1 = req.url) || void 0 === _req_url1 ? void 0 : _req_url1.split('/').pop();
|
|
1208
|
+
(0, __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.createReadStream)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outDir, 'static', searchIndexFile), 'utf-8').pipe(res, {
|
|
1209
|
+
end: true
|
|
1210
|
+
});
|
|
1211
|
+
} else null == next || next();
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
async function pathExists(path) {
|
|
1215
|
+
try {
|
|
1216
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].access(path);
|
|
1217
|
+
return true;
|
|
1218
|
+
} catch {
|
|
1219
|
+
return false;
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
async function readJson(path) {
|
|
1223
|
+
const raw = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(path, 'utf8');
|
|
1224
|
+
return JSON.parse(raw);
|
|
1225
|
+
}
|
|
1226
|
+
const { CachedInputFileSystem: detectReactVersion_CachedInputFileSystem, ResolverFactory: detectReactVersion_ResolverFactory } = __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__["default"];
|
|
1227
|
+
const DEFAULT_REACT_VERSION = 18;
|
|
1228
|
+
async function detectReactVersion() {
|
|
1229
|
+
const cwd = process.cwd();
|
|
1230
|
+
const reactPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(cwd, 'node_modules', 'react');
|
|
1231
|
+
if (await pathExists(reactPath)) {
|
|
1232
|
+
var _reactPkg_version;
|
|
1233
|
+
const reactPkg = await readJson(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(reactPath, 'package.json'));
|
|
1234
|
+
const version = Number(null === (_reactPkg_version = reactPkg.version) || void 0 === _reactPkg_version ? void 0 : _reactPkg_version.split('.')[0]);
|
|
1235
|
+
return version;
|
|
1611
1236
|
}
|
|
1612
|
-
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1237
|
+
return DEFAULT_REACT_VERSION;
|
|
1238
|
+
}
|
|
1239
|
+
async function resolveReactAlias(reactVersion, isSSR) {
|
|
1240
|
+
const basedir = reactVersion === DEFAULT_REACT_VERSION ? PACKAGE_ROOT : process.cwd();
|
|
1241
|
+
const libPaths = [
|
|
1242
|
+
'react',
|
|
1243
|
+
'react/jsx-runtime',
|
|
1244
|
+
'react/jsx-dev-runtime',
|
|
1245
|
+
'react-dom',
|
|
1246
|
+
'react-dom/server'
|
|
1247
|
+
];
|
|
1248
|
+
if (reactVersion >= DEFAULT_REACT_VERSION) libPaths.push('react-dom/client');
|
|
1249
|
+
const alias = {};
|
|
1250
|
+
const resolver = detectReactVersion_ResolverFactory.createResolver({
|
|
1251
|
+
fileSystem: new detectReactVersion_CachedInputFileSystem(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"], 0),
|
|
1252
|
+
extensions: [
|
|
1253
|
+
'.js'
|
|
1254
|
+
],
|
|
1255
|
+
alias,
|
|
1256
|
+
conditionNames: isSSR ? [
|
|
1257
|
+
'...'
|
|
1258
|
+
] : [
|
|
1259
|
+
'browser',
|
|
1260
|
+
'...'
|
|
1261
|
+
]
|
|
1262
|
+
});
|
|
1263
|
+
await Promise.all(libPaths.map(async (lib)=>{
|
|
1264
|
+
try {
|
|
1265
|
+
alias[lib] = await new Promise((resolve, reject)=>{
|
|
1266
|
+
resolver.resolve({
|
|
1267
|
+
importer: basedir
|
|
1268
|
+
}, basedir, lib, {}, (err, filePath)=>{
|
|
1269
|
+
if (err || false === filePath) return reject(err);
|
|
1270
|
+
return resolve(filePath);
|
|
1271
|
+
});
|
|
1272
|
+
});
|
|
1273
|
+
} catch (e) {
|
|
1274
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`${lib} not found: \n`, e);
|
|
1275
|
+
}
|
|
1276
|
+
}));
|
|
1277
|
+
return alias;
|
|
1278
|
+
}
|
|
1279
|
+
const detectCustomIcon = async (customThemeDir)=>{
|
|
1280
|
+
const assetsDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(customThemeDir, 'assets');
|
|
1281
|
+
const alias = {};
|
|
1282
|
+
if (!(0, __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.existsSync)(assetsDir)) return alias;
|
|
1283
|
+
const files = await (0, __WEBPACK_EXTERNAL_MODULE_tinyglobby__.glob)('*.svg', {
|
|
1284
|
+
cwd: assetsDir
|
|
1285
|
+
});
|
|
1286
|
+
files.forEach((file)=>{
|
|
1287
|
+
const name = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].basename(file, '.svg');
|
|
1288
|
+
alias[`@theme-assets/${name}`] = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(assetsDir, file);
|
|
1289
|
+
});
|
|
1623
1290
|
return alias;
|
|
1624
|
-
}
|
|
1625
|
-
const files = await glob2("*.svg", {
|
|
1626
|
-
cwd: assetsDir
|
|
1627
|
-
});
|
|
1628
|
-
files.forEach((file) => {
|
|
1629
|
-
const name = path10.basename(file, ".svg");
|
|
1630
|
-
alias[`@theme-assets/${name}`] = path10.join(assetsDir, file);
|
|
1631
|
-
});
|
|
1632
|
-
return alias;
|
|
1633
1291
|
};
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
bilibili: `<path fill="currentColor" d="M17.813 4.653h.854q2.266.08 3.773 1.574Q23.946 7.72 24 9.987v7.36q-.054 2.266-1.56 3.773c-1.506 1.507-2.262 1.524-3.773 1.56H5.333q-2.266-.054-3.773-1.56C.053 19.614.036 18.858 0 17.347v-7.36q.054-2.267 1.56-3.76t3.773-1.574h.774l-1.174-1.12a1.23 1.23 0 0 1-.373-.906q0-.534.373-.907l.027-.027q.4-.373.92-.373t.92.373L9.653 4.44q.107.106.187.213h4.267a.8.8 0 0 1 .16-.213l2.853-2.747q.4-.373.92-.373c.347 0 .662.151.929.4s.391.551.391.907q0 .532-.373.906zM5.333 7.24q-1.12.027-1.88.773q-.76.748-.786 1.894v7.52q.026 1.146.786 1.893t1.88.773h13.334q1.12-.026 1.88-.773t.786-1.893v-7.52q-.026-1.147-.786-1.894t-1.88-.773zM8 11.107q.56 0 .933.373q.375.374.4.96v1.173q-.025.586-.4.96q-.373.375-.933.374c-.56-.001-.684-.125-.933-.374q-.375-.373-.4-.96V12.44q0-.56.386-.947q.387-.386.947-.386m8 0q.56 0 .933.373q.375.374.4.96v1.173q-.025.586-.4.96q-.373.375-.933.374c-.56-.001-.684-.125-.933-.374q-.375-.373-.4-.96V12.44q.025-.586.4-.96q.373-.373.933-.373"/>`,
|
|
1651
|
-
lark: `<path d="M8.813 5.477c1.038.836 2.286 2.045 3.3 3.495.171.23.377.576.457.71l.034.056a8.803 8.803 0 0 0-.922 1.3l-.271-.494C9.655 7.53 6.3 5.477 6.137 5.377a.447.447 0 0 1-.006-.004l-.666-.393-.107-.086a.499.499 0 0 1 .306-.885L6.084 4h7.997c.159.006.318.037.47.092.174.064.317.174.458.308.134.143.272.296.403.448.622.675 1.324 1.688 1.324 1.688-.573.193-1.349.736-1.349.736a5.095 5.095 0 0 0-.348-.54 20.665 20.665 0 0 0-1.037-1.255H8.813Z" fill="currentColor"/>
|
|
1292
|
+
const presetIcons = {
|
|
1293
|
+
discord: '<path fill="currentColor" d="M20.317 4.37a19.8 19.8 0 0 0-4.885-1.515a.074.074 0 0 0-.079.037c-.21.375-.444.864-.608 1.25a18.3 18.3 0 0 0-5.487 0a13 13 0 0 0-.617-1.25a.08.08 0 0 0-.079-.037A19.7 19.7 0 0 0 3.677 4.37a.1.1 0 0 0-.032.027C.533 9.046-.32 13.58.099 18.057a.08.08 0 0 0 .031.057a19.9 19.9 0 0 0 5.993 3.03a.08.08 0 0 0 .084-.028a14 14 0 0 0 1.226-1.994a.076.076 0 0 0-.041-.106a13 13 0 0 1-1.872-.892a.077.077 0 0 1-.008-.128a10 10 0 0 0 .372-.292a.07.07 0 0 1 .077-.01c3.928 1.793 8.18 1.793 12.062 0a.07.07 0 0 1 .078.01q.181.149.373.292a.077.077 0 0 1-.006.127a12.3 12.3 0 0 1-1.873.892a.077.077 0 0 0-.041.107c.36.698.772 1.362 1.225 1.993a.08.08 0 0 0 .084.028a19.8 19.8 0 0 0 6.002-3.03a.08.08 0 0 0 .032-.054c.5-5.177-.838-9.674-3.549-13.66a.06.06 0 0 0-.031-.03M8.02 15.33c-1.182 0-2.157-1.085-2.157-2.419c0-1.333.956-2.419 2.157-2.419c1.21 0 2.176 1.096 2.157 2.42c0 1.333-.956 2.418-2.157 2.418m7.975 0c-1.183 0-2.157-1.085-2.157-2.419c0-1.333.955-2.419 2.157-2.419c1.21 0 2.176 1.096 2.157 2.42c0 1.333-.946 2.418-2.157 2.418"/>',
|
|
1294
|
+
facebook: '<path fill="currentColor" d="M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978c.401 0 .955.042 1.468.103a9 9 0 0 1 1.141.195v3.325a9 9 0 0 0-.653-.036a27 27 0 0 0-.733-.009c-.707 0-1.259.096-1.675.309a1.7 1.7 0 0 0-.679.622c-.258.42-.374.995-.374 1.752v1.297h3.919l-.386 2.103l-.287 1.564h-3.246v8.245C19.396 23.238 24 18.179 24 12.044c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.628 3.874 10.35 9.101 11.647"/>',
|
|
1295
|
+
github: '<path fill="currentColor" d="M12 .297c-6.63 0-12 5.373-12 12c0 5.303 3.438 9.8 8.205 11.385c.6.113.82-.258.82-.577c0-.285-.01-1.04-.015-2.04c-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729c1.205.084 1.838 1.236 1.838 1.236c1.07 1.835 2.809 1.305 3.495.998c.108-.776.417-1.305.76-1.605c-2.665-.3-5.466-1.332-5.466-5.93c0-1.31.465-2.38 1.235-3.22c-.135-.303-.54-1.523.105-3.176c0 0 1.005-.322 3.3 1.23c.96-.267 1.98-.399 3-.405c1.02.006 2.04.138 3 .405c2.28-1.552 3.285-1.23 3.285-1.23c.645 1.653.24 2.873.12 3.176c.765.84 1.23 1.91 1.23 3.22c0 4.61-2.805 5.625-5.475 5.92c.42.36.81 1.096.81 2.22c0 1.606-.015 2.896-.015 3.286c0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/>',
|
|
1296
|
+
gitlab: '<path fill="currentColor" d="m23.6 9.593l-.033-.086L20.3.98a.85.85 0 0 0-.336-.405a.875.875 0 0 0-1 .054a.9.9 0 0 0-.29.44L16.47 7.818H7.537L5.333 1.07a.86.86 0 0 0-.29-.441a.875.875 0 0 0-1-.054a.86.86 0 0 0-.336.405L.433 9.502l-.032.086a6.066 6.066 0 0 0 2.012 7.01l.01.009l.03.021l4.977 3.727l2.462 1.863l1.5 1.132a1.01 1.01 0 0 0 1.22 0l1.499-1.132l2.461-1.863l5.006-3.75l.013-.01a6.07 6.07 0 0 0 2.01-7.002"/>',
|
|
1297
|
+
instagram: '<path fill="currentColor" d="M7.03.084c-1.277.06-2.149.264-2.91.563a5.9 5.9 0 0 0-2.124 1.388a5.9 5.9 0 0 0-1.38 2.127C.321 4.926.12 5.8.064 7.076s-.069 1.688-.063 4.947s.021 3.667.083 4.947c.061 1.277.264 2.149.563 2.911c.308.789.72 1.457 1.388 2.123a5.9 5.9 0 0 0 2.129 1.38c.763.295 1.636.496 2.913.552c1.278.056 1.689.069 4.947.063s3.668-.021 4.947-.082c1.28-.06 2.147-.265 2.91-.563a5.9 5.9 0 0 0 2.123-1.388a5.9 5.9 0 0 0 1.38-2.129c.295-.763.496-1.636.551-2.912c.056-1.28.07-1.69.063-4.948c-.006-3.258-.02-3.667-.081-4.947c-.06-1.28-.264-2.148-.564-2.911a5.9 5.9 0 0 0-1.387-2.123a5.9 5.9 0 0 0-2.128-1.38c-.764-.294-1.636-.496-2.914-.55C15.647.009 15.236-.006 11.977 0S8.31.021 7.03.084m.14 21.693c-1.17-.05-1.805-.245-2.228-.408a3.7 3.7 0 0 1-1.382-.895a3.7 3.7 0 0 1-.9-1.378c-.165-.423-.363-1.058-.417-2.228c-.06-1.264-.072-1.644-.08-4.848c-.006-3.204.006-3.583.061-4.848c.05-1.169.246-1.805.408-2.228c.216-.561.477-.96.895-1.382a3.7 3.7 0 0 1 1.379-.9c.423-.165 1.057-.361 2.227-.417c1.265-.06 1.644-.072 4.848-.08c3.203-.006 3.583.006 4.85.062c1.168.05 1.804.244 2.227.408c.56.216.96.475 1.382.895s.681.817.9 1.378c.165.422.362 1.056.417 2.227c.06 1.265.074 1.645.08 4.848c.005 3.203-.006 3.583-.061 4.848c-.051 1.17-.245 1.805-.408 2.23c-.216.56-.477.96-.896 1.38a3.7 3.7 0 0 1-1.378.9c-.422.165-1.058.362-2.226.418c-1.266.06-1.645.072-4.85.079s-3.582-.006-4.848-.06m9.783-16.192a1.44 1.44 0 1 0 1.437-1.442a1.44 1.44 0 0 0-1.437 1.442M5.839 12.012a6.161 6.161 0 1 0 12.323-.024a6.162 6.162 0 0 0-12.323.024M8 12.008A4 4 0 1 1 12.008 16A4 4 0 0 1 8 12.008"/>',
|
|
1298
|
+
linkedin: '<path fill="currentColor" d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037c-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85c3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.06 2.06 0 0 1-2.063-2.065a2.064 2.064 0 1 1 2.063 2.065m1.782 13.019H3.555V9h3.564zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0z"/>',
|
|
1299
|
+
slack: '<path fill="currentColor" d="M5.042 15.165a2.53 2.53 0 0 1-2.52 2.523A2.53 2.53 0 0 1 0 15.165a2.527 2.527 0 0 1 2.522-2.52h2.52zm1.271 0a2.527 2.527 0 0 1 2.521-2.52a2.527 2.527 0 0 1 2.521 2.52v6.313A2.53 2.53 0 0 1 8.834 24a2.53 2.53 0 0 1-2.521-2.522zM8.834 5.042a2.53 2.53 0 0 1-2.521-2.52A2.53 2.53 0 0 1 8.834 0a2.53 2.53 0 0 1 2.521 2.522v2.52zm0 1.271a2.53 2.53 0 0 1 2.521 2.521a2.53 2.53 0 0 1-2.521 2.521H2.522A2.53 2.53 0 0 1 0 8.834a2.53 2.53 0 0 1 2.522-2.521zm10.122 2.521a2.53 2.53 0 0 1 2.522-2.521A2.53 2.53 0 0 1 24 8.834a2.53 2.53 0 0 1-2.522 2.521h-2.522zm-1.268 0a2.53 2.53 0 0 1-2.523 2.521a2.527 2.527 0 0 1-2.52-2.521V2.522A2.527 2.527 0 0 1 15.165 0a2.53 2.53 0 0 1 2.523 2.522zm-2.523 10.122a2.53 2.53 0 0 1 2.523 2.522A2.53 2.53 0 0 1 15.165 24a2.527 2.527 0 0 1-2.52-2.522v-2.522zm0-1.268a2.527 2.527 0 0 1-2.52-2.523a2.526 2.526 0 0 1 2.52-2.52h6.313A2.527 2.527 0 0 1 24 15.165a2.53 2.53 0 0 1-2.522 2.523z"/>',
|
|
1300
|
+
youtube: '<path fill="currentColor" d="M23.498 6.186a3.02 3.02 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.02 3.02 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.02 3.02 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.02 3.02 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814M9.545 15.568V8.432L15.818 12z"/>',
|
|
1301
|
+
juejin: '<path fill="currentColor" d="m12 14.316l7.454-5.88l-2.022-1.625L12 11.1l-.004.003l-5.432-4.288l-2.02 1.624l7.452 5.88Zm0-7.247l2.89-2.298L12 2.453l-.004-.005l-2.884 2.318l2.884 2.3Zm0 11.266l-.005.002l-9.975-7.87L0 12.088l.194.156l11.803 9.308l7.463-5.885L24 12.085l-2.023-1.624Z"/>',
|
|
1302
|
+
qq: '<path fill="currentColor" d="M21.395 15.035a40 40 0 0 0-.803-2.264l-1.079-2.695c.001-.032.014-.562.014-.836C19.526 4.632 17.351 0 12 0S4.474 4.632 4.474 9.241c0 .274.013.804.014.836l-1.08 2.695a39 39 0 0 0-.802 2.264c-1.021 3.283-.69 4.643-.438 4.673c.54.065 2.103-2.472 2.103-2.472c0 1.469.756 3.387 2.394 4.771c-.612.188-1.363.479-1.845.835c-.434.32-.379.646-.301.778c.343.578 5.883.369 7.482.189c1.6.18 7.14.389 7.483-.189c.078-.132.132-.458-.301-.778c-.483-.356-1.233-.646-1.846-.836c1.637-1.384 2.393-3.302 2.393-4.771c0 0 1.563 2.537 2.103 2.472c.251-.03.581-1.39-.438-4.673"/>',
|
|
1303
|
+
wechat: '<path fill="currentColor" d="M8.691 2.188C3.891 2.188 0 5.476 0 9.53c0 2.212 1.17 4.203 3.002 5.55a.59.59 0 0 1 .213.665l-.39 1.48c-.019.07-.048.141-.048.213c0 .163.13.295.29.295a.33.33 0 0 0 .167-.054l1.903-1.114a.86.86 0 0 1 .717-.098a10.2 10.2 0 0 0 2.837.403c.276 0 .543-.027.811-.05c-.857-2.578.157-4.972 1.932-6.446c1.703-1.415 3.882-1.98 5.853-1.838c-.576-3.583-4.196-6.348-8.596-6.348M5.785 5.991c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178A1.17 1.17 0 0 1 4.623 7.17c0-.651.52-1.18 1.162-1.18zm5.813 0c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178a1.17 1.17 0 0 1-1.162-1.178c0-.651.52-1.18 1.162-1.18m5.34 2.867c-1.797-.052-3.746.512-5.28 1.786c-1.72 1.428-2.687 3.72-1.78 6.22c.942 2.453 3.666 4.229 6.884 4.229c.826 0 1.622-.12 2.361-.336a.72.72 0 0 1 .598.082l1.584.926a.3.3 0 0 0 .14.047c.134 0 .24-.111.24-.247c0-.06-.023-.12-.038-.177l-.327-1.233a.6.6 0 0 1-.023-.156a.49.49 0 0 1 .201-.398C23.024 18.48 24 16.82 24 14.98c0-3.21-2.931-5.837-6.656-6.088V8.89c-.135-.01-.27-.027-.407-.03zm-2.53 3.274c.535 0 .969.44.969.982a.976.976 0 0 1-.969.983a.976.976 0 0 1-.969-.983c0-.542.434-.982.97-.982zm4.844 0c.535 0 .969.44.969.982a.976.976 0 0 1-.969.983a.976.976 0 0 1-.969-.983c0-.542.434-.982.969-.982"/>',
|
|
1304
|
+
weibo: '<path fill="currentColor" d="M17.525 11.378c1.263.392 2.669 1.336 2.669 3.004c0 2.763-3.98 6.239-9.964 6.239c-4.565 0-9.23-2.213-9.23-5.852c0-1.902 1.204-4.102 3.277-6.177c2.773-2.77 6.004-4.033 7.219-2.816c.537.537.588 1.464.244 2.572c-.178.557.525.25.525.25c2.24-.938 4.196-.994 4.909.027c.38.543.343 1.306-.008 2.19c-.163.407.048.471.36.563zm-7.282 7.939c3.641-.362 6.401-2.592 6.167-4.983c-.237-2.391-3.382-4.038-7.023-3.677c-3.64.36-6.403 2.59-6.167 4.98c.237 2.394 3.382 4.039 7.023 3.68zM6.16 14.438c.754-1.527 2.712-2.39 4.446-1.94c1.793.463 2.707 2.154 1.976 3.8c-.744 1.682-2.882 2.578-4.695 1.993c-1.752-.566-2.493-2.294-1.727-3.853zm1.446 2.587c.568.257 1.325.013 1.676-.55c.346-.568.163-1.217-.407-1.459c-.563-.237-1.291.008-1.64.553c-.354.547-.189 1.202.371 1.456zm2.206-1.808c.219.092.501-.012.628-.231c.123-.22.044-.466-.178-.548c-.216-.084-.486.018-.613.232c-.123.214-.054.458.163.547zM19.873 9.5a.725.725 0 1 1-1.378-.451a1.38 1.38 0 0 0-.288-1.357a1.395 1.395 0 0 0-1.321-.425a.723.723 0 1 1-.303-1.416a2.836 2.836 0 0 1 3.29 3.649zm-3.916-6.575A5.831 5.831 0 0 1 21.5 4.72a5.836 5.836 0 0 1 1.22 5.704a.838.838 0 0 1-1.06.54a.844.844 0 0 1-.542-1.062a4.143 4.143 0 0 0-4.807-5.327a.845.845 0 0 1-.354-1.65z"/>',
|
|
1305
|
+
zhihu: '<path fill="currentColor" d="M5.721 0C2.251 0 0 2.25 0 5.719V18.28C0 21.751 2.252 24 5.721 24h12.56C21.751 24 24 21.75 24 18.281V5.72C24 2.249 21.75 0 18.281 0zm1.964 4.078q-.408 1.096-.68 2.11h4.587c.545-.006.445 1.168.445 1.171H9.384a58 58 0 0 1-.112 3.797h2.712c.388.023.393 1.251.393 1.266H9.183a9.2 9.2 0 0 1-.408 2.102l.757-.604c.452.456 1.512 1.712 1.906 2.177c.473.681.063 2.081.063 2.081l-2.794-3.382c-.653 2.518-1.845 3.607-1.845 3.607c-.523.468-1.58.82-2.64.516c2.218-1.73 3.44-3.917 3.667-6.497H4.491c0-.015.197-1.243.806-1.266h2.71c.024-.32.086-3.254.086-3.797H6.598c-.136.406-.158.447-.268.753c-.594 1.095-1.603 1.122-1.907 1.155c.906-1.821 1.416-3.6 1.591-4.064c.425-1.124 1.671-1.125 1.671-1.125M13.078 6h6.377v11.33h-2.573l-2.184 1.373l-.401-1.373h-1.219zm1.313 1.219v8.86h.623l.263.937l1.455-.938h1.456v-8.86z"/>',
|
|
1306
|
+
bilibili: '<path fill="currentColor" d="M17.813 4.653h.854q2.266.08 3.773 1.574Q23.946 7.72 24 9.987v7.36q-.054 2.266-1.56 3.773c-1.506 1.507-2.262 1.524-3.773 1.56H5.333q-2.266-.054-3.773-1.56C.053 19.614.036 18.858 0 17.347v-7.36q.054-2.267 1.56-3.76t3.773-1.574h.774l-1.174-1.12a1.23 1.23 0 0 1-.373-.906q0-.534.373-.907l.027-.027q.4-.373.92-.373t.92.373L9.653 4.44q.107.106.187.213h4.267a.8.8 0 0 1 .16-.213l2.853-2.747q.4-.373.92-.373c.347 0 .662.151.929.4s.391.551.391.907q0 .532-.373.906zM5.333 7.24q-1.12.027-1.88.773q-.76.748-.786 1.894v7.52q.026 1.146.786 1.893t1.88.773h13.334q1.12-.026 1.88-.773t.786-1.893v-7.52q-.026-1.147-.786-1.894t-1.88-.773zM8 11.107q.56 0 .933.373q.375.374.4.96v1.173q-.025.586-.4.96q-.373.375-.933.374c-.56-.001-.684-.125-.933-.374q-.375-.373-.4-.96V12.44q0-.56.386-.947q.387-.386.947-.386m8 0q.56 0 .933.373q.375.374.4.96v1.173q-.025.586-.4.96q-.373.375-.933.374c-.56-.001-.684-.125-.933-.374q-.375-.373-.4-.96V12.44q.025-.586.4-.96q.373-.373.933-.373"/>',
|
|
1307
|
+
lark: `<path d="M8.813 5.477c1.038.836 2.286 2.045 3.3 3.495.171.23.377.576.457.71l.034.056a8.803 8.803 0 0 0-.922 1.3l-.271-.494C9.655 7.53 6.3 5.477 6.137 5.377a.447.447 0 0 1-.006-.004l-.666-.393-.107-.086a.499.499 0 0 1 .306-.885L6.084 4h7.997c.159.006.318.037.47.092.174.064.317.174.458.308.134.143.272.296.403.448.622.675 1.324 1.688 1.324 1.688-.573.193-1.349.736-1.349.736a5.095 5.095 0 0 0-.348-.54 20.665 20.665 0 0 0-1.037-1.255H8.813Z" fill="currentColor"/>
|
|
1652
1308
|
<path d="M18.482 7.507a5.42 5.42 0 0 1 4.04.717c.248.168.788.635.242 1.233-1.7 1.67-2.194 3.225-2.63 4.599-.278.873-.541 1.697-1.066 2.424-1.813 2.508-4.114 4-6.837 4.434-.561.089-1.132.131-1.7.131-3.958 0-7.498-2.035-8.75-2.844h.003l-.161-.107c-.534-.378-.61-.723-.623-.989V7.055a.486.486 0 0 1 .827-.317l.482.589c5.082 6.201 9.126 8.063 11.626 8.53 2.246.424 3.631-.165 4.022-.37.333-.51.534-1.143.764-1.865l.006-.021c.406-1.276.898-2.821 2.322-4.477a3.93 3.93 0 0 0-2.28-.168c-1.761.394-3.403 1.96-4.89 4.643a8.27 8.27 0 0 0-.341.671c-.724-.107-1.334-.65-1.334-.65.128-.269.22-.455.345-.672 1.718-3.125 3.714-4.962 5.933-5.441ZM2.477 16.889c1.145.744 5.341 3.232 9.532 2.563 1.56-.247 2.963-.915 4.196-1.99-2.771.254-7.557-.753-13.728-7.666v7.093Z" fill="currentColor"/>`,
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
};
|
|
1656
|
-
var formatIconName = (icon) => {
|
|
1657
|
-
return icon.toLowerCase();
|
|
1309
|
+
x: '<path fill="currentColor" d="M18.901 1.153h3.68l-8.04 9.19L24 22.846h-7.406l-5.8-7.584l-6.638 7.584H.474l8.6-9.83L0 1.154h7.594l5.243 6.932ZM17.61 20.644h2.039L6.486 3.24H4.298Z"/>',
|
|
1310
|
+
bluesky: '<path fill="currentColor" d="M12 10.8c-1.087-2.114-4.046-6.053-6.798-7.995C2.566.944 1.561 1.266.902 1.565C.139 1.908 0 3.08 0 3.768c0 .69.378 5.65.624 6.479c.815 2.736 3.713 3.66 6.383 3.364q.204-.03.415-.056q-.207.033-.415.056c-3.912.58-7.387 2.005-2.83 7.078c5.013 5.19 6.87-1.113 7.823-4.308c.953 3.195 2.05 9.271 7.733 4.308c4.267-4.308 1.172-6.498-2.74-7.078a9 9 0 0 1-.415-.056q.21.026.415.056c2.67.297 5.568-.628 6.383-3.364c.246-.828.624-5.79.624-6.478c0-.69-.139-1.861-.902-2.206c-.659-.298-1.664-.62-4.3 1.24C16.046 4.748 13.087 8.687 12 10.8"/>'
|
|
1658
1311
|
};
|
|
1312
|
+
const formatIconName = (icon)=>icon.toLowerCase();
|
|
1659
1313
|
function getSocialIcons(socialLinks = []) {
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
icons[link.icon] = `<svg xmlns="http://www.w3.org/2000/svg" width="100%" viewBox="0 0 24 24">${pathContent}</svg>`;
|
|
1314
|
+
const icons = {};
|
|
1315
|
+
for (const link of socialLinks)if ('string' == typeof link.icon) {
|
|
1316
|
+
const pathContent = presetIcons[formatIconName(link.icon)];
|
|
1317
|
+
icons[link.icon] = `<svg xmlns="http://www.w3.org/2000/svg" width="100%" viewBox="0 0 24 24">${pathContent}</svg>`;
|
|
1665
1318
|
}
|
|
1666
|
-
|
|
1667
|
-
return icons;
|
|
1319
|
+
return icons;
|
|
1668
1320
|
}
|
|
1669
|
-
|
|
1670
|
-
// src/node/initRsbuild.ts
|
|
1671
1321
|
function isPluginIncluded(config, pluginName) {
|
|
1672
|
-
|
|
1673
|
-
(plugin)
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
}
|
|
1721
|
-
},
|
|
1722
|
-
dev: {
|
|
1723
|
-
progressBar: false,
|
|
1724
|
-
// Serve static files
|
|
1725
|
-
setupMiddlewares: [
|
|
1726
|
-
(middlewares) => {
|
|
1727
|
-
middlewares.unshift(serveSearchIndexMiddleware(config));
|
|
1728
|
-
}
|
|
1729
|
-
],
|
|
1730
|
-
cliShortcuts: {
|
|
1731
|
-
// does not support restart server yet
|
|
1732
|
-
custom: (shortcuts) => shortcuts.filter(({ key }) => key !== "r")
|
|
1733
|
-
}
|
|
1734
|
-
},
|
|
1735
|
-
html: {
|
|
1736
|
-
title: config?.title ?? DEFAULT_TITLE,
|
|
1737
|
-
favicon: normalizeIcon(config?.icon),
|
|
1738
|
-
template: path11.join(PACKAGE_ROOT, "index.html"),
|
|
1739
|
-
tags: [
|
|
1740
|
-
config.themeConfig?.darkMode !== false && {
|
|
1741
|
-
tag: "script",
|
|
1742
|
-
children: inlineThemeScript,
|
|
1743
|
-
append: false
|
|
1744
|
-
}
|
|
1745
|
-
].filter(Boolean)
|
|
1746
|
-
},
|
|
1747
|
-
output: {
|
|
1748
|
-
assetPrefix,
|
|
1749
|
-
distPath: {
|
|
1750
|
-
// just for rsbuild preview
|
|
1751
|
-
root: csrOutDir
|
|
1752
|
-
}
|
|
1753
|
-
},
|
|
1754
|
-
resolve: {
|
|
1755
|
-
alias: {
|
|
1756
|
-
...detectCustomIconAlias,
|
|
1757
|
-
"@mdx-js/react": __require.resolve("@mdx-js/react"),
|
|
1758
|
-
"@theme": [CUSTOM_THEME_DIR, DEFAULT_THEME],
|
|
1759
|
-
"@/theme-default": DEFAULT_THEME,
|
|
1760
|
-
"@rspress/core": PACKAGE_ROOT,
|
|
1761
|
-
"react-lazy-with-preload": __require.resolve("react-lazy-with-preload"),
|
|
1762
|
-
"react-syntax-highlighter": path11.dirname(
|
|
1763
|
-
__require.resolve("react-syntax-highlighter/package.json")
|
|
1764
|
-
),
|
|
1765
|
-
"@theme-assets": path11.join(DEFAULT_THEME, "../assets")
|
|
1766
|
-
}
|
|
1767
|
-
},
|
|
1768
|
-
source: {
|
|
1769
|
-
include: [PACKAGE_ROOT, path11.join(cwd, "node_modules", RSPRESS_TEMP_DIR2)],
|
|
1770
|
-
define: {
|
|
1771
|
-
"process.env.__REACT_GTE_18__": JSON.stringify(reactVersion >= 18),
|
|
1772
|
-
"process.env.TEST": JSON.stringify(process.env.TEST),
|
|
1773
|
-
"process.env.RSPRESS_SOCIAL_ICONS": JSON.stringify(
|
|
1774
|
-
getSocialIcons(config.themeConfig.socialLinks)
|
|
1775
|
-
)
|
|
1776
|
-
}
|
|
1777
|
-
},
|
|
1778
|
-
performance: {
|
|
1779
|
-
chunkSplit: {
|
|
1780
|
-
override: {
|
|
1781
|
-
cacheGroups: {
|
|
1782
|
-
// extract all CSS into a single file
|
|
1783
|
-
// ensure CSS in async chunks can be loaded for SSG
|
|
1784
|
-
styles: {
|
|
1785
|
-
name: "styles",
|
|
1786
|
-
minSize: 0,
|
|
1787
|
-
chunks: "all",
|
|
1788
|
-
test: /\.(?:css|less|sass|scss)$/,
|
|
1789
|
-
priority: 99
|
|
1322
|
+
var _config_builderPlugins, _config_builderConfig_plugins, _config_builderConfig;
|
|
1323
|
+
return (null === (_config_builderPlugins = config.builderPlugins) || void 0 === _config_builderPlugins ? void 0 : _config_builderPlugins.some((plugin)=>plugin.name === pluginName)) || (null === (_config_builderConfig = config.builderConfig) || void 0 === _config_builderConfig ? void 0 : null === (_config_builderConfig_plugins = _config_builderConfig.plugins) || void 0 === _config_builderConfig_plugins ? void 0 : _config_builderConfig_plugins.some((plugin)=>plugin && plugin.name === pluginName));
|
|
1324
|
+
}
|
|
1325
|
+
async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver, runtimeTempDir) {
|
|
1326
|
+
var _config_builderConfig_output, _config_builderConfig, _config_themeConfig;
|
|
1327
|
+
const cwd = process.cwd();
|
|
1328
|
+
const CUSTOM_THEME_DIR = (null == config ? void 0 : config.themeDir) ?? __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'theme');
|
|
1329
|
+
const baseOutDir = (null == config ? void 0 : config.outDir) ?? OUTPUT_DIR;
|
|
1330
|
+
const csrOutDir = baseOutDir;
|
|
1331
|
+
const ssrOutDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(baseOutDir, 'ssr');
|
|
1332
|
+
const DEFAULT_THEME = require.resolve('@rspress/theme-default');
|
|
1333
|
+
const base = (null == config ? void 0 : config.base) ?? '';
|
|
1334
|
+
const assetPrefix = isProduction() ? (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeTrailingSlash)((null == config ? void 0 : null === (_config_builderConfig = config.builderConfig) || void 0 === _config_builderConfig ? void 0 : null === (_config_builderConfig_output = _config_builderConfig.output) || void 0 === _config_builderConfig_output ? void 0 : _config_builderConfig_output.assetPrefix) ?? base) : '';
|
|
1335
|
+
const reactVersion = await detectReactVersion();
|
|
1336
|
+
const normalizeIcon = (icon)=>{
|
|
1337
|
+
if (!icon) return;
|
|
1338
|
+
if (__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].isAbsolute(icon)) return __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(userDocRoot, PUBLIC_DIR, icon);
|
|
1339
|
+
return icon;
|
|
1340
|
+
};
|
|
1341
|
+
const [detectCustomIconAlias, reactCSRAlias, reactSSRAlias] = await Promise.all([
|
|
1342
|
+
detectCustomIcon(CUSTOM_THEME_DIR),
|
|
1343
|
+
resolveReactAlias(reactVersion, false),
|
|
1344
|
+
enableSSG ? resolveReactAlias(reactVersion, true) : Promise.resolve({})
|
|
1345
|
+
]);
|
|
1346
|
+
return {
|
|
1347
|
+
plugins: [
|
|
1348
|
+
...isPluginIncluded(config, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__.PLUGIN_REACT_NAME) ? [] : [
|
|
1349
|
+
(0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__.pluginReact)()
|
|
1350
|
+
],
|
|
1351
|
+
...isPluginIncluded(config, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_sass_b13a7d33__.PLUGIN_SASS_NAME) ? [] : [
|
|
1352
|
+
(0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_sass_b13a7d33__.pluginSass)()
|
|
1353
|
+
],
|
|
1354
|
+
...isPluginIncluded(config, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_less_4c557a99__.PLUGIN_LESS_NAME) ? [] : [
|
|
1355
|
+
(0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_less_4c557a99__.pluginLess)()
|
|
1356
|
+
],
|
|
1357
|
+
rsbuildPluginDocVM({
|
|
1358
|
+
userDocRoot,
|
|
1359
|
+
config,
|
|
1360
|
+
runtimeTempDir,
|
|
1361
|
+
routeService,
|
|
1362
|
+
pluginDriver
|
|
1363
|
+
})
|
|
1364
|
+
],
|
|
1365
|
+
server: {
|
|
1366
|
+
port: !isProduction() && process.env.PORT ? Number(process.env.PORT) : void 0,
|
|
1367
|
+
printUrls: ({ urls })=>urls.map((url)=>`${url}/${(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeLeadingSlash)(base)}`),
|
|
1368
|
+
publicDir: {
|
|
1369
|
+
name: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(userDocRoot, PUBLIC_DIR)
|
|
1790
1370
|
}
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
},
|
|
1795
|
-
tools: {
|
|
1796
|
-
bundlerChain(chain, { CHAIN_ID, target }) {
|
|
1797
|
-
const isServer = target === "node";
|
|
1798
|
-
const jsModuleRule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
1799
|
-
const swcLoaderOptions = jsModuleRule.use(CHAIN_ID.USE.SWC).get("options");
|
|
1800
|
-
const checkDeadLinks = (config?.markdown?.checkDeadLinks && !isServer) ?? false;
|
|
1801
|
-
chain.module.rule("MDX").type("javascript/auto").test(MDX_REGEXP3).resolve.merge({
|
|
1802
|
-
conditionNames: jsModuleRule.resolve.conditionNames.values(),
|
|
1803
|
-
mainFields: jsModuleRule.resolve.mainFields.values()
|
|
1804
|
-
}).end().oneOf("MDXCompile").use("builtin:swc-loader").loader("builtin:swc-loader").options(swcLoaderOptions).end().use("mdx-loader").loader(__require.resolve("./loader.js")).options({
|
|
1805
|
-
config,
|
|
1806
|
-
docDirectory: userDocRoot,
|
|
1807
|
-
checkDeadLinks,
|
|
1808
|
-
routeService: routeService2,
|
|
1809
|
-
pluginDriver
|
|
1810
|
-
}).end();
|
|
1811
|
-
if (chain.plugins.has(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH)) {
|
|
1812
|
-
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).tap((options) => {
|
|
1813
|
-
options[0] ?? (options[0] = {});
|
|
1814
|
-
options[0].include = [/\.([cm]js|[jt]sx?|flow)$/i, MDX_REGEXP3];
|
|
1815
|
-
return options;
|
|
1816
|
-
});
|
|
1817
|
-
}
|
|
1818
|
-
chain.resolve.extensions.prepend(".md").prepend(".mdx").prepend(".mjs");
|
|
1819
|
-
chain.module.rule("css-virtual-module").test(/\.rspress[\\/]runtime[\\/]virtual-global-styles/).merge({ sideEffects: true });
|
|
1820
|
-
if (isServer) {
|
|
1821
|
-
chain.output.filename("main.cjs");
|
|
1822
|
-
}
|
|
1823
|
-
const enableIncremental = !isProduction() && !process.env.DISABLE_RSPACK_INCREMENTAL;
|
|
1824
|
-
if (enableIncremental) {
|
|
1825
|
-
chain.merge({ experiments: { incremental: true } });
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
},
|
|
1829
|
-
environments: {
|
|
1830
|
-
web: {
|
|
1831
|
-
resolve: {
|
|
1832
|
-
alias: reactCSRAlias
|
|
1833
1371
|
},
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1372
|
+
dev: {
|
|
1373
|
+
progressBar: false,
|
|
1374
|
+
setupMiddlewares: [
|
|
1375
|
+
(middlewares)=>{
|
|
1376
|
+
middlewares.unshift(serveSearchIndexMiddleware(config));
|
|
1377
|
+
}
|
|
1378
|
+
],
|
|
1379
|
+
cliShortcuts: {
|
|
1380
|
+
custom: (shortcuts)=>shortcuts.filter(({ key })=>'r' !== key)
|
|
1381
|
+
}
|
|
1382
|
+
},
|
|
1383
|
+
html: {
|
|
1384
|
+
title: (null == config ? void 0 : config.title) ?? DEFAULT_TITLE,
|
|
1385
|
+
favicon: normalizeIcon(null == config ? void 0 : config.icon),
|
|
1386
|
+
template: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'index.html'),
|
|
1387
|
+
tags: [
|
|
1388
|
+
(null === (_config_themeConfig = config.themeConfig) || void 0 === _config_themeConfig ? void 0 : _config_themeConfig.darkMode) !== false && {
|
|
1389
|
+
tag: "script",
|
|
1390
|
+
children: inlineThemeScript,
|
|
1391
|
+
append: false
|
|
1392
|
+
}
|
|
1393
|
+
].filter(Boolean)
|
|
1841
1394
|
},
|
|
1842
1395
|
output: {
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1396
|
+
assetPrefix,
|
|
1397
|
+
distPath: {
|
|
1398
|
+
root: csrOutDir
|
|
1399
|
+
}
|
|
1400
|
+
},
|
|
1401
|
+
resolve: {
|
|
1402
|
+
alias: {
|
|
1403
|
+
...detectCustomIconAlias,
|
|
1404
|
+
'@mdx-js/react': require.resolve('@mdx-js/react'),
|
|
1405
|
+
'@theme': [
|
|
1406
|
+
CUSTOM_THEME_DIR,
|
|
1407
|
+
DEFAULT_THEME
|
|
1408
|
+
],
|
|
1409
|
+
'@/theme-default': DEFAULT_THEME,
|
|
1410
|
+
'@rspress/core': PACKAGE_ROOT,
|
|
1411
|
+
'react-lazy-with-preload': require.resolve('react-lazy-with-preload'),
|
|
1412
|
+
'react-syntax-highlighter': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(require.resolve('react-syntax-highlighter/package.json')),
|
|
1413
|
+
'@theme-assets': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(DEFAULT_THEME, '../assets')
|
|
1414
|
+
}
|
|
1415
|
+
},
|
|
1416
|
+
source: {
|
|
1417
|
+
include: [
|
|
1418
|
+
PACKAGE_ROOT,
|
|
1419
|
+
__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(cwd, 'node_modules', __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR)
|
|
1420
|
+
],
|
|
1858
1421
|
define: {
|
|
1859
|
-
|
|
1422
|
+
'process.env.__REACT_GTE_18__': JSON.stringify(reactVersion >= 18),
|
|
1423
|
+
'process.env.TEST': JSON.stringify(process.env.TEST),
|
|
1424
|
+
'process.env.RSPRESS_SOCIAL_ICONS': JSON.stringify(getSocialIcons(config.themeConfig.socialLinks))
|
|
1860
1425
|
}
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1426
|
+
},
|
|
1427
|
+
performance: {
|
|
1428
|
+
chunkSplit: {
|
|
1429
|
+
override: {
|
|
1430
|
+
cacheGroups: {
|
|
1431
|
+
styles: {
|
|
1432
|
+
name: 'styles',
|
|
1433
|
+
minSize: 0,
|
|
1434
|
+
chunks: 'all',
|
|
1435
|
+
test: /\.(?:css|less|sass|scss)$/,
|
|
1436
|
+
priority: 99
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
},
|
|
1442
|
+
tools: {
|
|
1443
|
+
bundlerChain (chain, { CHAIN_ID, target }) {
|
|
1444
|
+
var _config_markdown;
|
|
1445
|
+
const isServer = 'node' === target;
|
|
1446
|
+
const jsModuleRule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
1447
|
+
const swcLoaderOptions = jsModuleRule.use(CHAIN_ID.USE.SWC).get('options');
|
|
1448
|
+
const checkDeadLinks = ((null == config ? void 0 : null === (_config_markdown = config.markdown) || void 0 === _config_markdown ? void 0 : _config_markdown.checkDeadLinks) && !isServer) ?? false;
|
|
1449
|
+
chain.module.rule('MDX').type("javascript/auto").test(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_REGEXP).resolve.merge({
|
|
1450
|
+
conditionNames: jsModuleRule.resolve.conditionNames.values(),
|
|
1451
|
+
mainFields: jsModuleRule.resolve.mainFields.values()
|
|
1452
|
+
}).end().oneOf('MDXCompile').use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(require.resolve('./loader.js')).options({
|
|
1453
|
+
config,
|
|
1454
|
+
docDirectory: userDocRoot,
|
|
1455
|
+
checkDeadLinks,
|
|
1456
|
+
routeService,
|
|
1457
|
+
pluginDriver
|
|
1458
|
+
}).end();
|
|
1459
|
+
if (chain.plugins.has(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH)) chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).tap((options)=>{
|
|
1460
|
+
options[0] ??= {};
|
|
1461
|
+
options[0].include = [
|
|
1462
|
+
/\.([cm]js|[jt]sx?|flow)$/i,
|
|
1463
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_REGEXP
|
|
1464
|
+
];
|
|
1465
|
+
return options;
|
|
1466
|
+
});
|
|
1467
|
+
chain.resolve.extensions.prepend('.md').prepend('.mdx').prepend('.mjs');
|
|
1468
|
+
chain.module.rule('css-virtual-module').test(/\.rspress[\\/]runtime[\\/]virtual-global-styles/).merge({
|
|
1469
|
+
sideEffects: true
|
|
1470
|
+
});
|
|
1471
|
+
if (isServer) chain.output.filename('main.cjs');
|
|
1472
|
+
const enableIncremental = !isProduction() && !process.env.DISABLE_RSPACK_INCREMENTAL;
|
|
1473
|
+
if (enableIncremental) chain.merge({
|
|
1474
|
+
experiments: {
|
|
1475
|
+
incremental: true
|
|
1476
|
+
}
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
},
|
|
1480
|
+
environments: {
|
|
1481
|
+
web: {
|
|
1482
|
+
resolve: {
|
|
1483
|
+
alias: {
|
|
1484
|
+
...reactCSRAlias,
|
|
1485
|
+
__VIRTUAL_ROUTES__: 'virtual-routes'
|
|
1486
|
+
}
|
|
1487
|
+
},
|
|
1488
|
+
source: {
|
|
1489
|
+
entry: {
|
|
1490
|
+
index: CLIENT_ENTRY
|
|
1491
|
+
},
|
|
1492
|
+
define: {
|
|
1493
|
+
'process.env.__SSR__': JSON.stringify(false)
|
|
1494
|
+
}
|
|
1495
|
+
},
|
|
1496
|
+
output: {
|
|
1497
|
+
target: 'web',
|
|
1498
|
+
distPath: {
|
|
1499
|
+
root: csrOutDir
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1870
1502
|
},
|
|
1871
|
-
|
|
1872
|
-
|
|
1503
|
+
...enableSSG ? {
|
|
1504
|
+
node: {
|
|
1505
|
+
resolve: {
|
|
1506
|
+
alias: {
|
|
1507
|
+
...reactSSRAlias,
|
|
1508
|
+
__VIRTUAL_ROUTES__: 'virtual-routes-ssr'
|
|
1509
|
+
}
|
|
1510
|
+
},
|
|
1511
|
+
source: {
|
|
1512
|
+
entry: {
|
|
1513
|
+
index: SSR_ENTRY
|
|
1514
|
+
},
|
|
1515
|
+
define: {
|
|
1516
|
+
'process.env.__SSR__': JSON.stringify(true)
|
|
1517
|
+
}
|
|
1518
|
+
},
|
|
1519
|
+
performance: {
|
|
1520
|
+
printFileSize: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isDebugMode)()
|
|
1521
|
+
},
|
|
1522
|
+
output: {
|
|
1523
|
+
emitAssets: false,
|
|
1524
|
+
target: 'node',
|
|
1525
|
+
distPath: {
|
|
1526
|
+
root: ssrOutDir
|
|
1527
|
+
},
|
|
1528
|
+
minify: false
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
} : {}
|
|
1873
1532
|
}
|
|
1874
|
-
|
|
1875
|
-
}
|
|
1876
|
-
};
|
|
1533
|
+
};
|
|
1877
1534
|
}
|
|
1878
1535
|
async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuildConfig) {
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
enableSSG,
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
config?.builderConfig || {},
|
|
1905
|
-
extraRsbuildConfig || {}
|
|
1906
|
-
)
|
|
1907
|
-
});
|
|
1908
|
-
rsbuild.addPlugins(builderPlugins);
|
|
1909
|
-
return rsbuild;
|
|
1910
|
-
}
|
|
1911
|
-
|
|
1912
|
-
// src/node/utils/checkLanguageParity.ts
|
|
1913
|
-
import fs10 from "fs/promises";
|
|
1914
|
-
import path12 from "path";
|
|
1915
|
-
import { logger as logger3 } from "@rspress/shared/logger";
|
|
1916
|
-
function normalizePath2(filePath) {
|
|
1917
|
-
return filePath.split(path12.sep).join("/");
|
|
1536
|
+
var _pluginDriver_getPlugins;
|
|
1537
|
+
const cwd = process.cwd();
|
|
1538
|
+
const userDocRoot = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(rootDir || (null == config ? void 0 : config.root) || cwd);
|
|
1539
|
+
const builderPlugins = (null == config ? void 0 : config.builderPlugins) ?? [];
|
|
1540
|
+
const runtimeTempDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR, 'runtime');
|
|
1541
|
+
const runtimeAbsTempDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(cwd, 'node_modules', runtimeTempDir);
|
|
1542
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(runtimeAbsTempDir, {
|
|
1543
|
+
recursive: true
|
|
1544
|
+
});
|
|
1545
|
+
const routeService = await initRouteService({
|
|
1546
|
+
config,
|
|
1547
|
+
runtimeTempDir: runtimeAbsTempDir,
|
|
1548
|
+
scanDir: userDocRoot,
|
|
1549
|
+
pluginDriver
|
|
1550
|
+
});
|
|
1551
|
+
const { createRsbuild, mergeRsbuildConfig } = await import("@rsbuild/core");
|
|
1552
|
+
const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver, runtimeTempDir);
|
|
1553
|
+
const rsbuild = await createRsbuild({
|
|
1554
|
+
rsbuildConfig: mergeRsbuildConfig(internalRsbuildConfig, ...(null === (_pluginDriver_getPlugins = pluginDriver.getPlugins()) || void 0 === _pluginDriver_getPlugins ? void 0 : _pluginDriver_getPlugins.map((plugin)=>plugin.builderConfig ?? {})) || [], (null == config ? void 0 : config.builderConfig) || {}, extraRsbuildConfig || {})
|
|
1555
|
+
});
|
|
1556
|
+
rsbuild.addPlugins(builderPlugins);
|
|
1557
|
+
return rsbuild;
|
|
1558
|
+
}
|
|
1559
|
+
function checkLanguageParity_normalizePath(filePath) {
|
|
1560
|
+
return filePath.split(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].sep).join('/');
|
|
1918
1561
|
}
|
|
1919
1562
|
async function getAllMarkdownFilesFrom(dirPath) {
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
const
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1563
|
+
const files = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readdir(dirPath, {
|
|
1564
|
+
withFileTypes: true
|
|
1565
|
+
});
|
|
1566
|
+
const allFiles = [];
|
|
1567
|
+
for (const file of files){
|
|
1568
|
+
const fullPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(dirPath, file.name);
|
|
1569
|
+
if (file.isDirectory()) {
|
|
1570
|
+
const nestedFiles = await getAllMarkdownFilesFrom(fullPath);
|
|
1571
|
+
allFiles.push(...nestedFiles);
|
|
1572
|
+
} else if ([
|
|
1573
|
+
'.md',
|
|
1574
|
+
'.mdx'
|
|
1575
|
+
].includes(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(file.name))) allFiles.push(fullPath);
|
|
1929
1576
|
}
|
|
1930
|
-
|
|
1931
|
-
return allFiles;
|
|
1577
|
+
return allFiles;
|
|
1932
1578
|
}
|
|
1933
1579
|
async function collectModuleFiles(contentPath, lang, includedDir, excludedDirs, fileLangMap) {
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1580
|
+
const langDirPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(contentPath, lang);
|
|
1581
|
+
const langModuleDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(langDirPath, includedDir);
|
|
1582
|
+
try {
|
|
1583
|
+
const moduleDirStats = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].stat(langModuleDir);
|
|
1584
|
+
if (!moduleDirStats.isDirectory()) return fileLangMap;
|
|
1585
|
+
const files = await getAllMarkdownFilesFrom(langModuleDir);
|
|
1586
|
+
for (const file of files){
|
|
1587
|
+
const relativePath = checkLanguageParity_normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(langDirPath, file));
|
|
1588
|
+
if (excludedDirs.some((excludedDir)=>{
|
|
1589
|
+
const isFilePath = /\.(md|mdx)$/.test(excludedDir);
|
|
1590
|
+
return relativePath.includes(excludedDir + (isFilePath ? '' : '/'));
|
|
1591
|
+
})) continue;
|
|
1592
|
+
const baseName = relativePath;
|
|
1593
|
+
if (!fileLangMap[baseName]) fileLangMap[baseName] = new Set();
|
|
1594
|
+
fileLangMap[baseName].add(lang);
|
|
1595
|
+
}
|
|
1596
|
+
} catch (e) {
|
|
1597
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(e);
|
|
1598
|
+
throw new Error(`Failed to access directory: ${checkLanguageParity_normalizePath(langModuleDir)}`);
|
|
1952
1599
|
}
|
|
1953
|
-
|
|
1954
|
-
throw new Error(
|
|
1955
|
-
`Failed to access directory: ${normalizePath2(langModuleDir)}`
|
|
1956
|
-
);
|
|
1957
|
-
}
|
|
1958
|
-
return fileLangMap;
|
|
1600
|
+
return fileLangMap;
|
|
1959
1601
|
}
|
|
1960
1602
|
async function checkLanguageParity(config) {
|
|
1961
|
-
|
|
1962
|
-
return;
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
(
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
return;
|
|
1974
|
-
}
|
|
1975
|
-
const missingLanguagesFile = [];
|
|
1976
|
-
try {
|
|
1977
|
-
for (const includedDir of includedDirs) {
|
|
1978
|
-
if (excludedDirs.some((excludedDir) => excludedDir === includedDir))
|
|
1979
|
-
continue;
|
|
1980
|
-
const curFileLangMap = {};
|
|
1981
|
-
for (const lang of supportedLanguages2) {
|
|
1982
|
-
await collectModuleFiles(
|
|
1983
|
-
contentPath,
|
|
1984
|
-
lang,
|
|
1985
|
-
includedDir,
|
|
1986
|
-
excludedDirs,
|
|
1987
|
-
curFileLangMap
|
|
1988
|
-
);
|
|
1989
|
-
}
|
|
1990
|
-
for (const [baseName, langs] of Object.entries(curFileLangMap)) {
|
|
1991
|
-
const missingLangs = supportedLanguages2.filter(
|
|
1992
|
-
(lang) => !langs.has(lang)
|
|
1993
|
-
);
|
|
1994
|
-
missingLangs.forEach((lang) => {
|
|
1995
|
-
const missingPath = path12.join(lang, baseName);
|
|
1996
|
-
missingLanguagesFile.push(missingPath);
|
|
1997
|
-
});
|
|
1998
|
-
}
|
|
1603
|
+
var _config_languageParity_include, _this, _config_themeConfig;
|
|
1604
|
+
if (!(null == config ? void 0 : config.languageParity) || false === config.languageParity.enabled) return;
|
|
1605
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Checking language parity...');
|
|
1606
|
+
const contentPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(config.root);
|
|
1607
|
+
const includedDirs = (null === (_config_languageParity_include = config.languageParity.include) || void 0 === _config_languageParity_include ? void 0 : _config_languageParity_include.length) ? config.languageParity.include : [
|
|
1608
|
+
''
|
|
1609
|
+
];
|
|
1610
|
+
const excludedDirs = config.languageParity.exclude ?? [];
|
|
1611
|
+
const supportedLanguages = (null === (_this = config.locales ?? (null === (_config_themeConfig = config.themeConfig) || void 0 === _config_themeConfig ? void 0 : _config_themeConfig.locales)) || void 0 === _this ? void 0 : _this.map((locale)=>locale.lang)) || [];
|
|
1612
|
+
if (!supportedLanguages.length) {
|
|
1613
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error('No supported languages found in the configuration.');
|
|
1614
|
+
return;
|
|
1999
1615
|
}
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
1616
|
+
const missingLanguagesFile = [];
|
|
1617
|
+
try {
|
|
1618
|
+
for (const includedDir of includedDirs){
|
|
1619
|
+
if (excludedDirs.some((excludedDir)=>excludedDir === includedDir)) continue;
|
|
1620
|
+
const curFileLangMap = {};
|
|
1621
|
+
for (const lang of supportedLanguages)await collectModuleFiles(contentPath, lang, includedDir, excludedDirs, curFileLangMap);
|
|
1622
|
+
for (const [baseName, langs] of Object.entries(curFileLangMap)){
|
|
1623
|
+
const missingLangs = supportedLanguages.filter((lang)=>!langs.has(lang));
|
|
1624
|
+
missingLangs.forEach((lang)=>{
|
|
1625
|
+
const missingPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(lang, baseName);
|
|
1626
|
+
missingLanguagesFile.push(missingPath);
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
if (missingLanguagesFile.length > 0) throw new Error(`Check language parity failed! Missing content:\n${missingLanguagesFile.map((file)=>` - ${checkLanguageParity_normalizePath(file)}`).join('\n')}`);
|
|
1631
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.success('Language parity checked successfully.');
|
|
1632
|
+
} catch (err) {
|
|
1633
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error('Error during language parity check: \n', err);
|
|
1634
|
+
throw err;
|
|
2005
1635
|
}
|
|
2006
|
-
|
|
2007
|
-
} catch (err) {
|
|
2008
|
-
logger3.error(`Error during language parity check: ${err.message}`);
|
|
2009
|
-
throw err;
|
|
2010
|
-
}
|
|
2011
|
-
}
|
|
2012
|
-
|
|
2013
|
-
// src/node/dev.ts
|
|
1636
|
+
}
|
|
2014
1637
|
async function dev(options) {
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
});
|
|
2036
|
-
return server;
|
|
2037
|
-
} finally {
|
|
2038
|
-
await writeSearchIndex(modifiedConfig);
|
|
2039
|
-
await checkLanguageParity(modifiedConfig);
|
|
2040
|
-
}
|
|
2041
|
-
}
|
|
2042
|
-
|
|
2043
|
-
// src/node/build.ts
|
|
2044
|
-
import fs12 from "fs/promises";
|
|
2045
|
-
import { dirname as dirname2, join as join3 } from "path";
|
|
2046
|
-
import { pathToFileURL } from "url";
|
|
2047
|
-
import {
|
|
2048
|
-
isDebugMode as isDebugMode2,
|
|
2049
|
-
normalizeSlash,
|
|
2050
|
-
withBase as withBase3
|
|
2051
|
-
} from "@rspress/shared";
|
|
2052
|
-
import chalk3 from "@rspress/shared/chalk";
|
|
2053
|
-
import { logger as logger4 } from "@rspress/shared/logger";
|
|
2054
|
-
|
|
2055
|
-
// src/node/utils/renderHead.ts
|
|
2056
|
-
import fs11 from "fs/promises";
|
|
2057
|
-
import { loadFrontMatter as loadFrontMatter2 } from "@rspress/shared/node-utils";
|
|
1638
|
+
const { docDirectory, config, extraBuilderConfig } = options;
|
|
1639
|
+
const isProd = false;
|
|
1640
|
+
const pluginDriver = new PluginDriver(config, isProd);
|
|
1641
|
+
await pluginDriver.init();
|
|
1642
|
+
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1643
|
+
try {
|
|
1644
|
+
await pluginDriver.beforeBuild();
|
|
1645
|
+
const builder = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, false, extraBuilderConfig);
|
|
1646
|
+
builder.onDevCompileDone(async ()=>{
|
|
1647
|
+
await pluginDriver.afterBuild();
|
|
1648
|
+
});
|
|
1649
|
+
const { server } = await builder.startDevServer({
|
|
1650
|
+
getPortSilently: true
|
|
1651
|
+
});
|
|
1652
|
+
return server;
|
|
1653
|
+
} finally{
|
|
1654
|
+
await writeSearchIndex(modifiedConfig);
|
|
1655
|
+
await checkLanguageParity(modifiedConfig);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
2058
1658
|
async function renderFrontmatterHead(route) {
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
} = loadFrontMatter2(content, route.absolutePath, "", true);
|
|
2067
|
-
if (!head || head.length === 0)
|
|
2068
|
-
return "";
|
|
2069
|
-
return head.map(([tag, attrs]) => `<${tag} ${renderAttrs(attrs)}>`).join("");
|
|
1659
|
+
if (!isRouteMeta(route)) return '';
|
|
1660
|
+
const content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, {
|
|
1661
|
+
encoding: 'utf-8'
|
|
1662
|
+
});
|
|
1663
|
+
const { frontmatter: { head } } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.loadFrontMatter)(content, route.absolutePath, '', true);
|
|
1664
|
+
if (!head || 0 === head.length) return '';
|
|
1665
|
+
return head.map(([tag, attrs])=>`<${tag} ${renderAttrs(attrs)}>`).join('');
|
|
2070
1666
|
}
|
|
2071
1667
|
async function renderConfigHead(config, route) {
|
|
2072
|
-
|
|
2073
|
-
return
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
return
|
|
2083
|
-
|
|
2084
|
-
return resultHead;
|
|
2085
|
-
return `<${resultHead[0]} ${renderAttrs(resultHead[1])}>`;
|
|
2086
|
-
}
|
|
2087
|
-
return `<${head[0]} ${renderAttrs(head[1])}>`;
|
|
2088
|
-
}).join("");
|
|
1668
|
+
if (!isRouteMeta(route)) return '';
|
|
1669
|
+
if (!config.head || 0 === config.head.length) return '';
|
|
1670
|
+
return config.head.map((head)=>{
|
|
1671
|
+
if ('string' == typeof head) return head;
|
|
1672
|
+
if ('function' == typeof head) {
|
|
1673
|
+
const resultHead = head(route);
|
|
1674
|
+
if (!resultHead) return '';
|
|
1675
|
+
if ('string' == typeof resultHead) return resultHead;
|
|
1676
|
+
return `<${resultHead[0]} ${renderAttrs(resultHead[1])}>`;
|
|
1677
|
+
}
|
|
1678
|
+
return `<${head[0]} ${renderAttrs(head[1])}>`;
|
|
1679
|
+
}).join('');
|
|
2089
1680
|
}
|
|
2090
1681
|
function renderAttrs(attrs) {
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
throw new Error(
|
|
2097
|
-
`Invalid value for attribute ${key}:${JSON.stringify(value)}`
|
|
2098
|
-
);
|
|
2099
|
-
}).join("");
|
|
1682
|
+
return Object.entries(attrs).map(([key, value])=>{
|
|
1683
|
+
if ('boolean' == typeof value) return key;
|
|
1684
|
+
if ('string' == typeof value || 'number' == typeof value) return `${key}="${value}"`;
|
|
1685
|
+
throw new Error(`Invalid value for attribute ${key}:${JSON.stringify(value)}`);
|
|
1686
|
+
}).join('');
|
|
2100
1687
|
}
|
|
2101
1688
|
function isRouteMeta(route) {
|
|
2102
|
-
|
|
1689
|
+
return 'routePath' in route && 'absolutePath' in route;
|
|
2103
1690
|
}
|
|
2104
|
-
|
|
2105
|
-
// src/node/build.ts
|
|
2106
1691
|
async function bundle(docDirectory, config, pluginDriver, enableSSG) {
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
}
|
|
2120
|
-
function emptyDir(path13) {
|
|
2121
|
-
return fs12.rm(path13, { force: true, recursive: true });
|
|
1692
|
+
try {
|
|
1693
|
+
const rsbuild = await initRsbuild(docDirectory, config, pluginDriver, enableSSG);
|
|
1694
|
+
await rsbuild.build();
|
|
1695
|
+
} finally{
|
|
1696
|
+
await writeSearchIndex(config);
|
|
1697
|
+
await checkLanguageParity(config);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
function emptyDir(path) {
|
|
1701
|
+
return __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].rm(path, {
|
|
1702
|
+
force: true,
|
|
1703
|
+
recursive: true
|
|
1704
|
+
});
|
|
2122
1705
|
}
|
|
2123
1706
|
async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
`Failed to load SSG bundle: ${chalk3.yellow(ssrBundlePath)}.`
|
|
2139
|
-
);
|
|
2140
|
-
throw e;
|
|
2141
|
-
}
|
|
2142
|
-
logger4.error(e);
|
|
2143
|
-
logger4.warn(
|
|
2144
|
-
`Failed to load SSG bundle: ${chalk3.yellow(ssrBundlePath)}, fallback to CSR.`
|
|
2145
|
-
);
|
|
2146
|
-
}
|
|
2147
|
-
}
|
|
2148
|
-
const routes = routeService.getRoutes();
|
|
2149
|
-
const base = config?.base ?? "";
|
|
2150
|
-
const htmlTemplatePath = join3(outputPath, "index.html");
|
|
2151
|
-
const htmlTemplate = await fs12.readFile(htmlTemplatePath, "utf-8");
|
|
2152
|
-
const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route) => ({
|
|
2153
|
-
routePath: withBase3(route.path, base)
|
|
2154
|
-
}));
|
|
2155
|
-
const allRoutes = [...routes, ...additionalRoutes];
|
|
2156
|
-
const is404RouteInRoutes = allRoutes.some(
|
|
2157
|
-
(route) => route.routePath === "/404"
|
|
2158
|
-
);
|
|
2159
|
-
if (!is404RouteInRoutes) {
|
|
2160
|
-
allRoutes.push({
|
|
2161
|
-
routePath: "/404"
|
|
2162
|
-
});
|
|
2163
|
-
}
|
|
2164
|
-
await Promise.all(
|
|
2165
|
-
allRoutes.filter((route) => {
|
|
2166
|
-
return !route.routePath.includes(":");
|
|
2167
|
-
}).map(async (route) => {
|
|
2168
|
-
const helmetContext = {
|
|
2169
|
-
context: {}
|
|
2170
|
-
};
|
|
2171
|
-
const { routePath } = route;
|
|
2172
|
-
let appHtml = "";
|
|
2173
|
-
if (render) {
|
|
2174
|
-
try {
|
|
2175
|
-
({ appHtml } = await render(routePath, helmetContext.context));
|
|
2176
|
-
} catch (e) {
|
|
2177
|
-
if (typeof ssgConfig === "object" && ssgConfig.strict) {
|
|
2178
|
-
logger4.error(
|
|
2179
|
-
`Page "${chalk3.yellow(routePath)}" SSG rendering failed.`
|
|
2180
|
-
);
|
|
2181
|
-
throw e;
|
|
1707
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Rendering pages...');
|
|
1708
|
+
const startTime = Date.now();
|
|
1709
|
+
const outputPath = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(appDirectory, OUTPUT_DIR);
|
|
1710
|
+
const ssrBundlePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'ssr', 'main.cjs');
|
|
1711
|
+
try {
|
|
1712
|
+
const { version } = await __webpack_require__.e("193").then(__webpack_require__.t.bind(__webpack_require__, "./package.json", 19));
|
|
1713
|
+
let render = null;
|
|
1714
|
+
if (ssgConfig) try {
|
|
1715
|
+
const { default: ssrExports } = await import((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(ssrBundlePath).toString());
|
|
1716
|
+
({ render } = ssrExports);
|
|
1717
|
+
} catch (e) {
|
|
1718
|
+
if ('object' == typeof ssgConfig && ssgConfig.strict) {
|
|
1719
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}.`);
|
|
1720
|
+
throw e;
|
|
2182
1721
|
}
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
);
|
|
2186
|
-
}
|
|
2187
|
-
}
|
|
2188
|
-
const { helmet } = helmetContext.context;
|
|
2189
|
-
let html = htmlTemplate.replace(/<title>(.*?)<\/title>/gi, "").replace(APP_HTML_MARKER, () => appHtml).replace(
|
|
2190
|
-
META_GENERATOR,
|
|
2191
|
-
() => `<meta name="generator" content="Rspress v${version}">`
|
|
2192
|
-
).replace(
|
|
2193
|
-
HEAD_MARKER,
|
|
2194
|
-
[
|
|
2195
|
-
await renderConfigHead(config, route),
|
|
2196
|
-
helmet?.title?.toString(),
|
|
2197
|
-
helmet?.meta?.toString(),
|
|
2198
|
-
helmet?.link?.toString(),
|
|
2199
|
-
helmet?.style?.toString(),
|
|
2200
|
-
helmet?.script?.toString(),
|
|
2201
|
-
await renderFrontmatterHead(route)
|
|
2202
|
-
].join("")
|
|
2203
|
-
);
|
|
2204
|
-
if (helmet?.htmlAttributes) {
|
|
2205
|
-
html = html.replace(
|
|
2206
|
-
HTML_START_TAG,
|
|
2207
|
-
`${HTML_START_TAG} ${helmet?.htmlAttributes?.toString()}`
|
|
2208
|
-
);
|
|
1722
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(e);
|
|
1723
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}, fallback to CSR.`);
|
|
2209
1724
|
}
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
await fs12.mkdir(join3(outputPath, dirname2(fileName)), {
|
|
2225
|
-
recursive: true
|
|
1725
|
+
const routes = init_routeService.getRoutes();
|
|
1726
|
+
const base = (null == config ? void 0 : config.base) ?? '';
|
|
1727
|
+
const htmlTemplatePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'index.html');
|
|
1728
|
+
const htmlTemplate = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(htmlTemplatePath, 'utf-8');
|
|
1729
|
+
const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route)=>({
|
|
1730
|
+
routePath: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(route.path, base)
|
|
1731
|
+
}));
|
|
1732
|
+
const allRoutes = [
|
|
1733
|
+
...routes,
|
|
1734
|
+
...additionalRoutes
|
|
1735
|
+
];
|
|
1736
|
+
const is404RouteInRoutes = allRoutes.some((route)=>'/404' === route.routePath);
|
|
1737
|
+
if (!is404RouteInRoutes) allRoutes.push({
|
|
1738
|
+
routePath: '/404'
|
|
2226
1739
|
});
|
|
2227
|
-
await
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
1740
|
+
await Promise.all(allRoutes.filter((route)=>!route.routePath.includes(':')).map(async (route)=>{
|
|
1741
|
+
var _helmet_title, _helmet_meta, _helmet_link, _helmet_style, _helmet_script;
|
|
1742
|
+
const helmetContext = {
|
|
1743
|
+
context: {}
|
|
1744
|
+
};
|
|
1745
|
+
const { routePath } = route;
|
|
1746
|
+
let appHtml = '';
|
|
1747
|
+
if (render) try {
|
|
1748
|
+
({ appHtml } = await render(routePath, helmetContext.context));
|
|
1749
|
+
} catch (e) {
|
|
1750
|
+
if ('object' == typeof ssgConfig && ssgConfig.strict) {
|
|
1751
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering failed.`);
|
|
1752
|
+
throw e;
|
|
1753
|
+
}
|
|
1754
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering error, fallback to CSR.`, e);
|
|
1755
|
+
}
|
|
1756
|
+
const { helmet } = helmetContext.context;
|
|
1757
|
+
let html = htmlTemplate.replace(/<title>(.*?)<\/title>/gi, '').replace(APP_HTML_MARKER, ()=>appHtml).replace(META_GENERATOR, ()=>`<meta name="generator" content="Rspress v${version}">`).replace(HEAD_MARKER, [
|
|
1758
|
+
await renderConfigHead(config, route),
|
|
1759
|
+
null == helmet ? void 0 : null === (_helmet_title = helmet.title) || void 0 === _helmet_title ? void 0 : _helmet_title.toString(),
|
|
1760
|
+
null == helmet ? void 0 : null === (_helmet_meta = helmet.meta) || void 0 === _helmet_meta ? void 0 : _helmet_meta.toString(),
|
|
1761
|
+
null == helmet ? void 0 : null === (_helmet_link = helmet.link) || void 0 === _helmet_link ? void 0 : _helmet_link.toString(),
|
|
1762
|
+
null == helmet ? void 0 : null === (_helmet_style = helmet.style) || void 0 === _helmet_style ? void 0 : _helmet_style.toString(),
|
|
1763
|
+
null == helmet ? void 0 : null === (_helmet_script = helmet.script) || void 0 === _helmet_script ? void 0 : _helmet_script.toString(),
|
|
1764
|
+
await renderFrontmatterHead(route)
|
|
1765
|
+
].join(''));
|
|
1766
|
+
if (null == helmet ? void 0 : helmet.htmlAttributes) {
|
|
1767
|
+
var _helmet_htmlAttributes;
|
|
1768
|
+
html = html.replace(HTML_START_TAG, `${HTML_START_TAG} ${null == helmet ? void 0 : null === (_helmet_htmlAttributes = helmet.htmlAttributes) || void 0 === _helmet_htmlAttributes ? void 0 : _helmet_htmlAttributes.toString()}`);
|
|
1769
|
+
}
|
|
1770
|
+
if (null == helmet ? void 0 : helmet.bodyAttributes) {
|
|
1771
|
+
var _helmet_bodyAttributes;
|
|
1772
|
+
html = html.replace(BODY_START_TAG, `${BODY_START_TAG} ${null == helmet ? void 0 : null === (_helmet_bodyAttributes = helmet.bodyAttributes) || void 0 === _helmet_bodyAttributes ? void 0 : _helmet_bodyAttributes.toString()}`);
|
|
1773
|
+
}
|
|
1774
|
+
const normalizeHtmlFilePath = (path)=>{
|
|
1775
|
+
const normalizedBase = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeSlash)((null == config ? void 0 : config.base) || '/');
|
|
1776
|
+
if (path.endsWith('/')) return `${path}index.html`.replace(normalizedBase, '');
|
|
1777
|
+
return `${path}.html`.replace(normalizedBase, '');
|
|
1778
|
+
};
|
|
1779
|
+
const fileName = normalizeHtmlFilePath(routePath);
|
|
1780
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(fileName)), {
|
|
1781
|
+
recursive: true
|
|
1782
|
+
});
|
|
1783
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, fileName), html);
|
|
1784
|
+
}));
|
|
1785
|
+
if (!(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isDebugMode)()) await emptyDir((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'ssr'));
|
|
1786
|
+
await emptyDir((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'html'));
|
|
1787
|
+
const totalTime = Date.now() - startTime;
|
|
1788
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.success(`Pages rendered in ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(totalTime)} ms.`);
|
|
1789
|
+
} catch (e) {
|
|
1790
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Pages render error: ${e.stack}`);
|
|
1791
|
+
throw e;
|
|
2232
1792
|
}
|
|
2233
|
-
await emptyDir(join3(outputPath, "html"));
|
|
2234
|
-
const totalTime = Date.now() - startTime;
|
|
2235
|
-
logger4.success(`Pages rendered in ${chalk3.yellow(totalTime)} ms.`);
|
|
2236
|
-
} catch (e) {
|
|
2237
|
-
logger4.error(`Pages render error: ${e.stack}`);
|
|
2238
|
-
throw e;
|
|
2239
|
-
}
|
|
2240
1793
|
}
|
|
2241
1794
|
async function build(options) {
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
}
|
|
2253
|
-
|
|
2254
|
-
// src/node/serve.ts
|
|
2255
|
-
import { mergeRsbuildConfig } from "@rsbuild/core";
|
|
1795
|
+
const { docDirectory, appDirectory, config } = options;
|
|
1796
|
+
const pluginDriver = new PluginDriver(config, true);
|
|
1797
|
+
await pluginDriver.init();
|
|
1798
|
+
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1799
|
+
await pluginDriver.beforeBuild();
|
|
1800
|
+
const ssgConfig = modifiedConfig.ssg ?? true;
|
|
1801
|
+
await emptyDir(TEMP_DIR);
|
|
1802
|
+
await bundle(docDirectory, modifiedConfig, pluginDriver, Boolean(ssgConfig));
|
|
1803
|
+
await renderPages(appDirectory, modifiedConfig, pluginDriver, ssgConfig);
|
|
1804
|
+
await pluginDriver.afterBuild();
|
|
1805
|
+
}
|
|
2256
1806
|
async function serve(options) {
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
envPort || userPort || builderConfig
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
}
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
false
|
|
2279
|
-
);
|
|
2280
|
-
await builder.preview();
|
|
2281
|
-
}
|
|
2282
|
-
|
|
2283
|
-
// src/index.ts
|
|
2284
|
-
export * from "@rspress/shared";
|
|
2285
|
-
import { mergeDocConfig } from "@rspress/shared/node-utils";
|
|
2286
|
-
export {
|
|
2287
|
-
build,
|
|
2288
|
-
dev,
|
|
2289
|
-
mergeDocConfig,
|
|
2290
|
-
serve
|
|
2291
|
-
};
|
|
2292
|
-
|
|
2293
|
-
//# sourceMappingURL=index.js.map
|
|
1807
|
+
var _builderConfig_server, _builderConfig_server1;
|
|
1808
|
+
const { config, port: userPort, host: userHost } = options;
|
|
1809
|
+
const envPort = process.env.PORT;
|
|
1810
|
+
const envHost = process.env.HOST;
|
|
1811
|
+
const { builderConfig } = config;
|
|
1812
|
+
const port = Number(envPort || userPort || (null == builderConfig ? void 0 : null === (_builderConfig_server = builderConfig.server) || void 0 === _builderConfig_server ? void 0 : _builderConfig_server.port) || 4173);
|
|
1813
|
+
const host = envHost || userHost || (null == builderConfig ? void 0 : null === (_builderConfig_server1 = builderConfig.server) || void 0 === _builderConfig_server1 ? void 0 : _builderConfig_server1.host) || 'localhost';
|
|
1814
|
+
config.builderConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(builderConfig, {
|
|
1815
|
+
server: {
|
|
1816
|
+
port,
|
|
1817
|
+
host
|
|
1818
|
+
}
|
|
1819
|
+
});
|
|
1820
|
+
const pluginDriver = new PluginDriver(config, true);
|
|
1821
|
+
await pluginDriver.init();
|
|
1822
|
+
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1823
|
+
const builder = await initRsbuild(config.root, modifiedConfig, pluginDriver, false);
|
|
1824
|
+
await builder.preview();
|
|
1825
|
+
}
|
|
1826
|
+
var __webpack_exports__mergeDocConfig = __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.mergeDocConfig;
|
|
1827
|
+
export { build, dev, serve, __webpack_exports__mergeDocConfig as mergeDocConfig };
|