@rspress/core 1.41.1 → 1.41.2
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 +1702 -2166
- package/dist/loader.d.ts +78 -70
- package/dist/loader.js +549 -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,1829 @@
|
|
|
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
|
-
|
|
30
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
-
mod
|
|
36
|
-
));
|
|
37
|
-
var __publicField = (obj, key, value) => {
|
|
38
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
39
|
-
return value;
|
|
40
|
-
};
|
|
41
|
-
var __accessCheck = (obj, member, msg) => {
|
|
42
|
-
if (!member.has(obj))
|
|
43
|
-
throw TypeError("Cannot " + msg);
|
|
44
|
-
};
|
|
45
|
-
var __privateGet = (obj, member, getter) => {
|
|
46
|
-
__accessCheck(obj, member, "read from private field");
|
|
47
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
48
|
-
};
|
|
49
|
-
var __privateAdd = (obj, member, value) => {
|
|
50
|
-
if (member.has(obj))
|
|
51
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
52
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
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;
|
|
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_tinyglobby__ from "tinyglobby";
|
|
12
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
|
|
13
|
+
import * as __WEBPACK_EXTERNAL_MODULE_rspack_plugin_virtual_module_609978fd__ from "rspack-plugin-virtual-module";
|
|
14
|
+
import * as __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__ from "lodash-es";
|
|
15
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__ from "node:crypto";
|
|
16
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_mdx_rs_d2f3021f__ from "@rspress/mdx-rs";
|
|
17
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__ from "@rspress/shared/node-utils";
|
|
18
|
+
import * as __WEBPACK_EXTERNAL_MODULE_html_to_text_2c51ed38__ from "html-to-text";
|
|
19
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
20
|
+
import * as __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__ from "@mdx-js/mdx";
|
|
21
|
+
import * as __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__ from "enhanced-resolve";
|
|
22
|
+
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
23
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__ from "@rspress/shared/logger";
|
|
24
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
25
|
+
export * from "@rspress/shared";
|
|
26
|
+
var __webpack_modules__ = {
|
|
27
|
+
"react-syntax-highlighter/dist/cjs/languages/prism/supported-languages": function(module) {
|
|
28
|
+
module.exports = require("react-syntax-highlighter/dist/cjs/languages/prism/supported-languages");
|
|
29
|
+
}
|
|
62
30
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var
|
|
66
|
-
|
|
67
|
-
module
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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"
|
|
31
|
+
var __webpack_module_cache__ = {};
|
|
32
|
+
function __webpack_require__(moduleId) {
|
|
33
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
34
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
35
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
36
|
+
exports: {}
|
|
37
|
+
};
|
|
38
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
39
|
+
return module.exports;
|
|
40
|
+
}
|
|
41
|
+
__webpack_require__.m = __webpack_modules__;
|
|
42
|
+
(()=>{
|
|
43
|
+
var getProto = Object.getPrototypeOf ? function(obj) {
|
|
44
|
+
return Object.getPrototypeOf(obj);
|
|
45
|
+
} : function(obj) {
|
|
46
|
+
return obj.__proto__;
|
|
47
|
+
};
|
|
48
|
+
var leafPrototypes;
|
|
49
|
+
__webpack_require__.t = function(value, mode) {
|
|
50
|
+
if (1 & mode) value = this(value);
|
|
51
|
+
if (8 & mode) return value;
|
|
52
|
+
if ('object' == typeof value && value) {
|
|
53
|
+
if (4 & mode && value.__esModule) return value;
|
|
54
|
+
if (16 & mode && 'function' == typeof value.then) return value;
|
|
101
55
|
}
|
|
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"
|
|
56
|
+
var ns = Object.create(null);
|
|
57
|
+
__webpack_require__.r(ns);
|
|
58
|
+
var def = {};
|
|
59
|
+
leafPrototypes = leafPrototypes || [
|
|
60
|
+
null,
|
|
61
|
+
getProto({}),
|
|
62
|
+
getProto([]),
|
|
63
|
+
getProto(getProto)
|
|
64
|
+
];
|
|
65
|
+
for(var current = 2 & mode && value; 'object' == typeof current && !~leafPrototypes.indexOf(current); current = getProto(current))Object.getOwnPropertyNames(current).forEach(function(key) {
|
|
66
|
+
def[key] = function() {
|
|
67
|
+
return value[key];
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
def['default'] = function() {
|
|
71
|
+
return value;
|
|
72
|
+
};
|
|
73
|
+
__webpack_require__.d(ns, def);
|
|
74
|
+
return ns;
|
|
189
75
|
};
|
|
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
|
-
|
|
76
|
+
})();
|
|
77
|
+
(()=>{
|
|
78
|
+
__webpack_require__.d = function(exports, definition) {
|
|
79
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: definition[key]
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
})();
|
|
85
|
+
(()=>{
|
|
86
|
+
__webpack_require__.f = {};
|
|
87
|
+
__webpack_require__.e = function(chunkId) {
|
|
88
|
+
return Promise.all(Object.keys(__webpack_require__.f).reduce(function(promises, key) {
|
|
89
|
+
__webpack_require__.f[key](chunkId, promises);
|
|
90
|
+
return promises;
|
|
91
|
+
}, []));
|
|
92
|
+
};
|
|
93
|
+
})();
|
|
94
|
+
(()=>{
|
|
95
|
+
__webpack_require__.u = function(chunkId) {
|
|
96
|
+
return "" + chunkId + ".js";
|
|
97
|
+
};
|
|
98
|
+
})();
|
|
99
|
+
(()=>{
|
|
100
|
+
__webpack_require__.o = function(obj, prop) {
|
|
101
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
102
|
+
};
|
|
103
|
+
})();
|
|
104
|
+
(()=>{
|
|
105
|
+
__webpack_require__.r = function(exports) {
|
|
106
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, {
|
|
107
|
+
value: 'Module'
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, '__esModule', {
|
|
110
|
+
value: true
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
})();
|
|
114
|
+
(()=>{
|
|
115
|
+
var installedChunks = {
|
|
116
|
+
980: 0
|
|
117
|
+
};
|
|
118
|
+
var installChunk = function(data) {
|
|
119
|
+
var ids = data.ids;
|
|
120
|
+
var modules = data.modules;
|
|
121
|
+
var runtime = data.runtime;
|
|
122
|
+
var moduleId, chunkId, i = 0;
|
|
123
|
+
for(moduleId in modules)if (__webpack_require__.o(modules, moduleId)) __webpack_require__.m[moduleId] = modules[moduleId];
|
|
124
|
+
if (runtime) runtime(__webpack_require__);
|
|
125
|
+
for(; i < ids.length; i++){
|
|
126
|
+
chunkId = ids[i];
|
|
127
|
+
if (__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) installedChunks[chunkId][0]();
|
|
128
|
+
installedChunks[ids[i]] = 0;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
__webpack_require__.f.j = function(chunkId, promises) {
|
|
132
|
+
var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : void 0;
|
|
133
|
+
if (0 !== installedChunkData) {
|
|
134
|
+
if (installedChunkData) promises.push(installedChunkData[1]);
|
|
135
|
+
else {
|
|
136
|
+
var promise = import("./" + __webpack_require__.u(chunkId)).then(installChunk, function(e) {
|
|
137
|
+
if (0 !== installedChunks[chunkId]) installedChunks[chunkId] = void 0;
|
|
138
|
+
throw e;
|
|
139
|
+
});
|
|
140
|
+
var promise = Promise.race([
|
|
141
|
+
promise,
|
|
142
|
+
new Promise(function(resolve) {
|
|
143
|
+
installedChunkData = installedChunks[chunkId] = [
|
|
144
|
+
resolve
|
|
145
|
+
];
|
|
146
|
+
})
|
|
147
|
+
]);
|
|
148
|
+
promises.push(installedChunkData[1] = promise);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
})();
|
|
153
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
154
|
+
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
155
|
+
}
|
|
156
|
+
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
157
|
+
if (descriptor.get) return descriptor.get.call(receiver);
|
|
158
|
+
return descriptor.value;
|
|
159
|
+
}
|
|
160
|
+
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
161
|
+
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
162
|
+
else {
|
|
163
|
+
if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
|
|
164
|
+
descriptor.value = value;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
168
|
+
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
169
|
+
return privateMap.get(receiver);
|
|
170
|
+
}
|
|
171
|
+
function _class_private_field_get(receiver, privateMap) {
|
|
172
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
173
|
+
return _class_apply_descriptor_get(receiver, descriptor);
|
|
174
|
+
}
|
|
175
|
+
function _class_private_field_init(obj, privateMap, value) {
|
|
176
|
+
_check_private_redeclaration(obj, privateMap);
|
|
177
|
+
privateMap.set(obj, value);
|
|
178
|
+
}
|
|
179
|
+
function _class_private_field_set(receiver, privateMap, value) {
|
|
180
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
181
|
+
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
var _config = /*#__PURE__*/ new WeakMap(), _plugins = /*#__PURE__*/ new WeakMap(), _isProd = /*#__PURE__*/ new WeakMap();
|
|
185
|
+
class PluginDriver {
|
|
186
|
+
async init() {
|
|
187
|
+
var _themeConfig_locales, _themeConfig_locales_, _themeConfig_locales1, _themeConfig_locales_1, _themeConfig_locales2;
|
|
188
|
+
this.clearPlugins();
|
|
189
|
+
const config = _class_private_field_get(this, _config);
|
|
190
|
+
const themeConfig = (null == config ? void 0 : config.themeConfig) || {};
|
|
191
|
+
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));
|
|
192
|
+
const mediumZoomConfig = (null == config ? void 0 : config.mediumZoom) ?? true;
|
|
193
|
+
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);
|
|
194
|
+
if (enableLastUpdated) {
|
|
195
|
+
const { pluginLastUpdated } = await import("@rspress/plugin-last-updated");
|
|
196
|
+
this.addPlugin(pluginLastUpdated());
|
|
197
|
+
}
|
|
198
|
+
if (mediumZoomConfig) {
|
|
199
|
+
const { pluginMediumZoom } = await import("@rspress/plugin-medium-zoom");
|
|
200
|
+
this.addPlugin(pluginMediumZoom('object' == typeof mediumZoomConfig ? mediumZoomConfig : void 0));
|
|
201
|
+
}
|
|
202
|
+
this.addPlugin((0, __WEBPACK_EXTERNAL_MODULE__rspress_plugin_container_syntax_12d3c700__.pluginContainerSyntax)());
|
|
203
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isDevDebugMode)()) {
|
|
204
|
+
const SourceBuildPlugin = await import("@rspress/theme-default/node/source-build-plugin.js").then((r)=>r.SourceBuildPlugin, ()=>null);
|
|
205
|
+
if (SourceBuildPlugin) this.addPlugin(SourceBuildPlugin());
|
|
206
|
+
}
|
|
207
|
+
(config.plugins || []).forEach((plugin)=>{
|
|
208
|
+
this.addPlugin(plugin);
|
|
209
|
+
});
|
|
210
|
+
if (!haveNavSidebarConfig) {
|
|
211
|
+
const { pluginAutoNavSidebar } = await import("@rspress/plugin-auto-nav-sidebar");
|
|
212
|
+
this.addPlugin(pluginAutoNavSidebar());
|
|
213
|
+
}
|
|
217
214
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
typeof mediumZoomConfig === "object" ? mediumZoomConfig : void 0
|
|
223
|
-
)
|
|
224
|
-
);
|
|
215
|
+
addPlugin(plugin) {
|
|
216
|
+
const existedIndex = _class_private_field_get(this, _plugins).findIndex((item)=>item.name === plugin.name);
|
|
217
|
+
if (-1 !== existedIndex) throw new Error(`The plugin "${plugin.name}" has been registered`);
|
|
218
|
+
_class_private_field_get(this, _plugins).push(plugin);
|
|
225
219
|
}
|
|
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
|
-
}
|
|
220
|
+
getPlugins() {
|
|
221
|
+
return _class_private_field_get(this, _plugins);
|
|
235
222
|
}
|
|
236
|
-
(
|
|
237
|
-
|
|
238
|
-
});
|
|
239
|
-
if (!haveNavSidebarConfig) {
|
|
240
|
-
const { pluginAutoNavSidebar } = await import("@rspress/plugin-auto-nav-sidebar");
|
|
241
|
-
this.addPlugin(pluginAutoNavSidebar());
|
|
223
|
+
clearPlugins() {
|
|
224
|
+
_class_private_field_set(this, _plugins, []);
|
|
242
225
|
}
|
|
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`);
|
|
226
|
+
removePlugin(pluginName) {
|
|
227
|
+
const index = _class_private_field_get(this, _plugins).findIndex((item)=>item.name === pluginName);
|
|
228
|
+
if (-1 !== index) _class_private_field_get(this, _plugins).splice(index, 1);
|
|
250
229
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
230
|
+
async modifyConfig() {
|
|
231
|
+
let config = _class_private_field_get(this, _config);
|
|
232
|
+
for(let i = 0; i < _class_private_field_get(this, _plugins).length; i++){
|
|
233
|
+
const plugin = _class_private_field_get(this, _plugins)[i];
|
|
234
|
+
if ('function' == typeof plugin.config) config = await plugin.config(config || {}, {
|
|
235
|
+
addPlugin: this.addPlugin.bind(this),
|
|
236
|
+
removePlugin: (pluginName)=>{
|
|
237
|
+
const index = _class_private_field_get(this, _plugins).findIndex((item)=>item.name === pluginName);
|
|
238
|
+
this.removePlugin(pluginName);
|
|
239
|
+
if (index <= i && index > 0) i--;
|
|
240
|
+
}
|
|
241
|
+
}, _class_private_field_get(this, _isProd));
|
|
242
|
+
}
|
|
243
|
+
_class_private_field_set(this, _config, config);
|
|
244
|
+
return _class_private_field_get(this, _config);
|
|
245
|
+
}
|
|
246
|
+
async beforeBuild() {
|
|
247
|
+
return this._runParallelAsyncHook('beforeBuild', _class_private_field_get(this, _config) || {}, _class_private_field_get(this, _isProd));
|
|
248
|
+
}
|
|
249
|
+
async afterBuild() {
|
|
250
|
+
return this._runParallelAsyncHook('afterBuild', _class_private_field_get(this, _config) || {}, _class_private_field_get(this, _isProd));
|
|
251
|
+
}
|
|
252
|
+
async modifySearchIndexData(pages) {
|
|
253
|
+
return this._runParallelAsyncHook('modifySearchIndexData', pages, _class_private_field_get(this, _isProd));
|
|
254
|
+
}
|
|
255
|
+
async extendPageData(pageData) {
|
|
256
|
+
return this._runParallelAsyncHook('extendPageData', pageData, _class_private_field_get(this, _isProd));
|
|
257
|
+
}
|
|
258
|
+
async addPages() {
|
|
259
|
+
const result = await this._runParallelAsyncHook('addPages', _class_private_field_get(this, _config) || {}, _class_private_field_get(this, _isProd));
|
|
260
|
+
return result.flat();
|
|
261
|
+
}
|
|
262
|
+
async routeGenerated(routes) {
|
|
263
|
+
return this._runParallelAsyncHook('routeGenerated', routes);
|
|
264
|
+
}
|
|
265
|
+
async addRuntimeModules() {
|
|
266
|
+
const result = await this._runParallelAsyncHook('addRuntimeModules', _class_private_field_get(this, _config) || {}, _class_private_field_get(this, _isProd));
|
|
267
|
+
return result.reduce((prev, current)=>({
|
|
268
|
+
...prev,
|
|
269
|
+
...current
|
|
270
|
+
}), {});
|
|
271
|
+
}
|
|
272
|
+
async addSSGRoutes() {
|
|
273
|
+
const result = await this._runParallelAsyncHook('addSSGRoutes', _class_private_field_get(this, _config) || {}, _class_private_field_get(this, _isProd));
|
|
274
|
+
return result.flat();
|
|
275
|
+
}
|
|
276
|
+
globalUIComponents() {
|
|
277
|
+
const result = _class_private_field_get(this, _plugins).map((plugin)=>plugin.globalUIComponents || []);
|
|
278
|
+
return result.flat();
|
|
279
|
+
}
|
|
280
|
+
globalStyles() {
|
|
281
|
+
return _class_private_field_get(this, _plugins).filter((plugin)=>'string' == typeof plugin.globalStyles).map((plugin)=>plugin.globalStyles);
|
|
282
|
+
}
|
|
283
|
+
_runParallelAsyncHook(hookName, ...args) {
|
|
284
|
+
return Promise.all(_class_private_field_get(this, _plugins).filter((plugin)=>'function' == typeof plugin[hookName]).map((plugin)=>plugin[hookName](...args)));
|
|
263
285
|
}
|
|
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
|
-
}
|
|
286
|
+
_runSerialAsyncHook(hookName, ...args) {
|
|
287
|
+
return _class_private_field_get(this, _plugins).reduce(async (prev, plugin)=>{
|
|
288
|
+
if ('function' == typeof plugin[hookName]) {
|
|
289
|
+
await prev;
|
|
290
|
+
return plugin[hookName](...args);
|
|
282
291
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
);
|
|
286
|
-
}
|
|
292
|
+
return prev;
|
|
293
|
+
}, Promise.resolve());
|
|
287
294
|
}
|
|
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}')
|
|
295
|
+
constructor(config, isProd){
|
|
296
|
+
_class_private_field_init(this, _config, {
|
|
297
|
+
writable: true,
|
|
298
|
+
value: void 0
|
|
299
|
+
});
|
|
300
|
+
_class_private_field_init(this, _plugins, {
|
|
301
|
+
writable: true,
|
|
302
|
+
value: void 0
|
|
303
|
+
});
|
|
304
|
+
_class_private_field_init(this, _isProd, {
|
|
305
|
+
writable: true,
|
|
306
|
+
value: void 0
|
|
307
|
+
});
|
|
308
|
+
_class_private_field_set(this, _config, config);
|
|
309
|
+
_class_private_field_set(this, _isProd, isProd);
|
|
310
|
+
_class_private_field_set(this, _plugins, []);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
314
|
+
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
315
|
+
const inlineThemeScript = `{
|
|
316
|
+
const saved = localStorage.getItem('${__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.APPEARANCE_KEY}')
|
|
401
317
|
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
402
318
|
const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
|
|
403
319
|
document.documentElement.classList.toggle('dark', isDark)
|
|
404
320
|
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";
|
|
321
|
+
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
322
|
+
const dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(new URL(import.meta.url)));
|
|
323
|
+
const PACKAGE_ROOT = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(dirname, '..');
|
|
324
|
+
const CLIENT_ENTRY = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'clientEntry.js');
|
|
325
|
+
const SSR_ENTRY = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrEntry.js');
|
|
326
|
+
const OUTPUT_DIR = 'doc_build';
|
|
327
|
+
const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
328
|
+
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
329
|
+
const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
|
|
330
|
+
const HTML_START_TAG = '<html';
|
|
331
|
+
const BODY_START_TAG = '<body';
|
|
332
|
+
const DEFAULT_TITLE = 'Rspress';
|
|
333
|
+
const PUBLIC_DIR = 'public';
|
|
334
|
+
const TEMP_DIR = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'node_modules', __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR);
|
|
335
|
+
const isWindows = 'win32' === __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__["default"].platform();
|
|
448
336
|
function slash(p) {
|
|
449
|
-
|
|
337
|
+
return p.replace(/\\/g, '/');
|
|
450
338
|
}
|
|
451
339
|
function normalizePath(id) {
|
|
452
|
-
|
|
340
|
+
return __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].posix.normalize(isWindows ? slash(id) : id);
|
|
453
341
|
}
|
|
454
|
-
|
|
455
|
-
// src/node/utils/getPageKey.ts
|
|
456
|
-
import { removeLeadingSlash } from "@rspress/shared";
|
|
457
342
|
function getPageKey(route) {
|
|
458
|
-
|
|
459
|
-
|
|
343
|
+
const cleanRoute = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeLeadingSlash)(route);
|
|
344
|
+
return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
|
|
460
345
|
}
|
|
461
|
-
|
|
462
|
-
|
|
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;
|
|
346
|
+
function RouteService_check_private_redeclaration(obj, privateCollection) {
|
|
347
|
+
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
503
348
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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);
|
|
349
|
+
function RouteService_class_apply_descriptor_get(receiver, descriptor) {
|
|
350
|
+
if (descriptor.get) return descriptor.get.call(receiver);
|
|
351
|
+
return descriptor.value;
|
|
352
|
+
}
|
|
353
|
+
function RouteService_class_apply_descriptor_set(receiver, descriptor, value) {
|
|
354
|
+
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
355
|
+
else {
|
|
356
|
+
if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
|
|
357
|
+
descriptor.value = value;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
function RouteService_class_extract_field_descriptor(receiver, privateMap, action) {
|
|
361
|
+
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
362
|
+
return privateMap.get(receiver);
|
|
363
|
+
}
|
|
364
|
+
function RouteService_class_private_field_get(receiver, privateMap) {
|
|
365
|
+
var descriptor = RouteService_class_extract_field_descriptor(receiver, privateMap, "get");
|
|
366
|
+
return RouteService_class_apply_descriptor_get(receiver, descriptor);
|
|
367
|
+
}
|
|
368
|
+
function RouteService_class_private_field_init(obj, privateMap, value) {
|
|
369
|
+
RouteService_check_private_redeclaration(obj, privateMap);
|
|
370
|
+
privateMap.set(obj, value);
|
|
371
|
+
}
|
|
372
|
+
function RouteService_class_private_field_set(receiver, privateMap, value) {
|
|
373
|
+
var descriptor = RouteService_class_extract_field_descriptor(receiver, privateMap, "set");
|
|
374
|
+
RouteService_class_apply_descriptor_set(receiver, descriptor, value);
|
|
375
|
+
return value;
|
|
376
|
+
}
|
|
377
|
+
function _class_private_method_get(receiver, privateSet, fn) {
|
|
378
|
+
if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
|
|
379
|
+
return fn;
|
|
380
|
+
}
|
|
381
|
+
function _class_private_method_init(obj, privateSet) {
|
|
382
|
+
RouteService_check_private_redeclaration(obj, privateSet);
|
|
383
|
+
privateSet.add(obj);
|
|
384
|
+
}
|
|
385
|
+
const DEFAULT_PAGE_EXTENSIONS = [
|
|
386
|
+
'js',
|
|
387
|
+
'jsx',
|
|
388
|
+
'ts',
|
|
389
|
+
'tsx',
|
|
390
|
+
'md',
|
|
391
|
+
'mdx'
|
|
392
|
+
];
|
|
393
|
+
const normalizeRoutePath = (routePath, base, lang, version, langs, versions, extensions = DEFAULT_PAGE_EXTENSIONS)=>{
|
|
394
|
+
const hasTrailSlash = routePath.endsWith('/');
|
|
395
|
+
let versionPart = '';
|
|
396
|
+
let langPart = '';
|
|
397
|
+
let purePathPart = '';
|
|
398
|
+
const parts = routePath.split('/').filter(Boolean);
|
|
399
|
+
if (version) {
|
|
400
|
+
const versionToMatch = parts[0];
|
|
401
|
+
if (versions.includes(versionToMatch)) {
|
|
402
|
+
if (versionToMatch !== version) versionPart = versionToMatch;
|
|
403
|
+
parts.shift();
|
|
578
404
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
)
|
|
584
|
-
|
|
405
|
+
}
|
|
406
|
+
if (lang) {
|
|
407
|
+
const langToMatch = parts[0];
|
|
408
|
+
if (langs.includes(langToMatch)) {
|
|
409
|
+
if (langToMatch !== lang) langPart = langToMatch;
|
|
410
|
+
parts.shift();
|
|
585
411
|
}
|
|
586
|
-
return resolve(filePath);
|
|
587
|
-
}
|
|
588
|
-
);
|
|
589
|
-
});
|
|
590
|
-
return resolveResult;
|
|
591
|
-
}
|
|
592
|
-
async function flattenMdxContent(content, basePath, alias) {
|
|
593
|
-
const deps = [];
|
|
594
|
-
const regex = new RegExp(importStatementRegex);
|
|
595
|
-
if (!regex.test(content)) {
|
|
596
|
-
return { flattenContent: content, deps };
|
|
597
|
-
}
|
|
598
|
-
if (!startFlatten) {
|
|
599
|
-
resolver = ResolverFactory2.createResolver({
|
|
600
|
-
fileSystem: new CachedInputFileSystem2(fs3, 0),
|
|
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;
|
|
626
412
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
413
|
+
purePathPart = parts.join('/');
|
|
414
|
+
let normalizedRoutePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)([
|
|
415
|
+
versionPart,
|
|
416
|
+
langPart,
|
|
417
|
+
purePathPart
|
|
418
|
+
].filter(Boolean).join('/')).replace(new RegExp(`\\.(${extensions.join('|')})$`), '').replace(/\.html$/, '').replace(/\/index$/, '/');
|
|
419
|
+
if (hasTrailSlash) normalizedRoutePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addTrailingSlash)(normalizedRoutePath);
|
|
420
|
+
return {
|
|
421
|
+
routePath: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(normalizedRoutePath, base),
|
|
422
|
+
lang: langPart || lang,
|
|
423
|
+
version: versionPart || version
|
|
424
|
+
};
|
|
425
|
+
};
|
|
426
|
+
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();
|
|
427
|
+
class RouteService {
|
|
428
|
+
async init() {
|
|
429
|
+
const files = (await (0, __WEBPACK_EXTERNAL_MODULE_tinyglobby__.glob)([
|
|
430
|
+
`**/*.{${RouteService_class_private_field_get(this, _extensions).join(',')}}`,
|
|
431
|
+
...RouteService_class_private_field_get(this, _include)
|
|
432
|
+
], {
|
|
433
|
+
cwd: RouteService_class_private_field_get(this, _scanDir),
|
|
434
|
+
absolute: true,
|
|
435
|
+
ignore: [
|
|
436
|
+
...RouteService_class_private_field_get(this, _exclude),
|
|
437
|
+
'**/node_modules/**',
|
|
438
|
+
'**/.eslintrc.js',
|
|
439
|
+
'**/.nx/**',
|
|
440
|
+
`./${PUBLIC_DIR}/**`
|
|
441
|
+
]
|
|
442
|
+
})).sort();
|
|
443
|
+
files.forEach((filePath)=>{
|
|
444
|
+
const fileRelativePath = normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(RouteService_class_private_field_get(this, _scanDir), filePath));
|
|
445
|
+
const { routePath, lang, version } = this.normalizeRoutePath(fileRelativePath);
|
|
446
|
+
const absolutePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(RouteService_class_private_field_get(this, _scanDir), fileRelativePath);
|
|
447
|
+
const routeInfo = {
|
|
448
|
+
routePath,
|
|
449
|
+
absolutePath: normalizePath(absolutePath),
|
|
450
|
+
relativePath: fileRelativePath,
|
|
451
|
+
pageName: getPageKey(fileRelativePath),
|
|
452
|
+
lang,
|
|
453
|
+
version
|
|
454
|
+
};
|
|
455
|
+
this.addRoute(routeInfo);
|
|
456
|
+
});
|
|
457
|
+
const externalPages = await RouteService_class_private_field_get(this, _pluginDriver).addPages();
|
|
458
|
+
await Promise.all(externalPages.map(async (route, index)=>{
|
|
459
|
+
const { routePath, content, filepath } = route;
|
|
460
|
+
if (filepath) {
|
|
461
|
+
const routeInfo = _class_private_method_get(this, _generateRouteInfo, generateRouteInfo).call(this, routePath, filepath);
|
|
462
|
+
this.addRoute(routeInfo);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
if (content) {
|
|
466
|
+
const filepath = await _class_private_method_get(this, _writeTempFile, writeTempFile).call(this, index, content);
|
|
467
|
+
const routeInfo = _class_private_method_get(this, _generateRouteInfo, generateRouteInfo).call(this, routePath, filepath);
|
|
468
|
+
this.addRoute(routeInfo);
|
|
469
|
+
}
|
|
470
|
+
}));
|
|
471
|
+
await RouteService_class_private_field_get(this, _pluginDriver).routeGenerated(this.getRoutes());
|
|
472
|
+
}
|
|
473
|
+
addRoute(routeInfo) {
|
|
474
|
+
const { routePath, absolutePath } = routeInfo;
|
|
475
|
+
if (this.routeData.has(routePath)) {
|
|
476
|
+
const preRouteExtIndex = RouteService_class_private_field_get(this, _extensions).indexOf(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(this.routeData.get(routePath).absolutePath).slice(1));
|
|
477
|
+
const currRouteExtIndex = RouteService_class_private_field_get(this, _extensions).indexOf(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(absolutePath).slice(1));
|
|
478
|
+
if (-1 !== currRouteExtIndex && (currRouteExtIndex < preRouteExtIndex || -1 === preRouteExtIndex)) this.routeData.set(routePath, routeInfo);
|
|
479
|
+
} else this.routeData.set(routePath, routeInfo);
|
|
635
480
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
// src/node/utils/applyReplaceRules.ts
|
|
641
|
-
function applyReplaceRules(code = "", replaceRules = []) {
|
|
642
|
-
let result = code;
|
|
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();
|
|
481
|
+
removeRoute(filePath) {
|
|
482
|
+
const fileRelativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(RouteService_class_private_field_get(this, _scanDir), filePath);
|
|
483
|
+
const { routePath } = this.normalizeRoutePath(fileRelativePath);
|
|
484
|
+
this.routeData.delete(routePath);
|
|
664
485
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
const langToMatch = parts[0];
|
|
668
|
-
if (langs.includes(langToMatch)) {
|
|
669
|
-
if (langToMatch !== lang) {
|
|
670
|
-
langPart = langToMatch;
|
|
671
|
-
}
|
|
672
|
-
parts.shift();
|
|
486
|
+
getRoutes() {
|
|
487
|
+
return Array.from(this.routeData.values());
|
|
673
488
|
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
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 || []);
|
|
489
|
+
isExistRoute(routePath) {
|
|
490
|
+
const { routePath: normalizedRoute } = this.normalizeRoutePath(routePath);
|
|
491
|
+
return this.routeData.get(normalizedRoute);
|
|
718
492
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
ignore: [
|
|
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);
|
|
493
|
+
isEmpty() {
|
|
494
|
+
return 0 === this.routeData.size;
|
|
495
|
+
}
|
|
496
|
+
generateRoutesCode(isStaticImport = false) {
|
|
497
|
+
return this.generateRoutesCodeByRouteMeta(this.getRoutes(), isStaticImport);
|
|
780
498
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
const fileRelativePath = path5.relative(__privateGet(this, _scanDir), filePath);
|
|
784
|
-
const { routePath } = this.normalizeRoutePath(fileRelativePath);
|
|
785
|
-
this.routeData.delete(routePath);
|
|
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 `
|
|
499
|
+
generateRoutesCodeByRouteMeta(routeMeta, isStaticImport) {
|
|
500
|
+
return `
|
|
802
501
|
import React from 'react';
|
|
803
502
|
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")}
|
|
503
|
+
${routeMeta.map((route, index)=>isStaticImport ? `import * as Route${index} from '${route.absolutePath}';` : `const Route${index} = lazyWithPreload(() => import('${route.absolutePath}'))`).join('\n')}
|
|
807
504
|
export const routes = [
|
|
808
|
-
${routeMeta.map((route, index)
|
|
809
|
-
|
|
505
|
+
${routeMeta.map((route, index)=>{
|
|
506
|
+
const preload = isStaticImport ? `() => Route${index}` : `async () => {
|
|
810
507
|
await Route${index}.preload();
|
|
811
508
|
return import("${route.absolutePath}");
|
|
812
509
|
}`;
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
510
|
+
const component = isStaticImport ? `Route${index}.default` : `Route${index}`;
|
|
511
|
+
return `{ path: '${route.routePath}', element: React.createElement(${component}), filePath: '${route.relativePath}', preload: ${preload}, lang: '${route.lang}', version: '${route.version}' }`;
|
|
512
|
+
}).join(',\n')}
|
|
816
513
|
];
|
|
817
514
|
`;
|
|
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
|
-
|
|
515
|
+
}
|
|
516
|
+
normalizeRoutePath(routePath) {
|
|
517
|
+
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));
|
|
518
|
+
}
|
|
519
|
+
constructor(scanDir, userConfig, tempDir, pluginDriver){
|
|
520
|
+
var _userConfig_themeConfig;
|
|
521
|
+
_class_private_method_init(this, _writeTempFile);
|
|
522
|
+
_class_private_method_init(this, _generateRouteInfo);
|
|
523
|
+
RouteService_class_private_field_init(this, _scanDir, {
|
|
524
|
+
writable: true,
|
|
525
|
+
value: void 0
|
|
526
|
+
});
|
|
527
|
+
RouteService_class_private_field_init(this, _defaultLang, {
|
|
528
|
+
writable: true,
|
|
529
|
+
value: void 0
|
|
530
|
+
});
|
|
531
|
+
RouteService_class_private_field_init(this, _defaultVersion, {
|
|
532
|
+
writable: true,
|
|
533
|
+
value: void 0
|
|
534
|
+
});
|
|
535
|
+
RouteService_class_private_field_init(this, _extensions, {
|
|
536
|
+
writable: true,
|
|
537
|
+
value: void 0
|
|
538
|
+
});
|
|
539
|
+
RouteService_class_private_field_init(this, _langs, {
|
|
540
|
+
writable: true,
|
|
541
|
+
value: void 0
|
|
542
|
+
});
|
|
543
|
+
RouteService_class_private_field_init(this, _versions, {
|
|
544
|
+
writable: true,
|
|
545
|
+
value: void 0
|
|
546
|
+
});
|
|
547
|
+
RouteService_class_private_field_init(this, _include, {
|
|
548
|
+
writable: true,
|
|
549
|
+
value: void 0
|
|
550
|
+
});
|
|
551
|
+
RouteService_class_private_field_init(this, _exclude, {
|
|
552
|
+
writable: true,
|
|
553
|
+
value: void 0
|
|
554
|
+
});
|
|
555
|
+
RouteService_class_private_field_init(this, _base, {
|
|
556
|
+
writable: true,
|
|
557
|
+
value: void 0
|
|
558
|
+
});
|
|
559
|
+
RouteService_class_private_field_init(this, _tempDir, {
|
|
560
|
+
writable: true,
|
|
561
|
+
value: void 0
|
|
562
|
+
});
|
|
563
|
+
RouteService_class_private_field_init(this, _pluginDriver, {
|
|
564
|
+
writable: true,
|
|
565
|
+
value: void 0
|
|
566
|
+
});
|
|
567
|
+
this.routeData = new Map();
|
|
568
|
+
RouteService_class_private_field_set(this, _defaultVersion, '');
|
|
569
|
+
RouteService_class_private_field_set(this, _extensions, []);
|
|
570
|
+
RouteService_class_private_field_set(this, _langs, []);
|
|
571
|
+
RouteService_class_private_field_set(this, _versions, []);
|
|
572
|
+
RouteService_class_private_field_set(this, _include, []);
|
|
573
|
+
RouteService_class_private_field_set(this, _exclude, []);
|
|
574
|
+
RouteService_class_private_field_set(this, _base, '');
|
|
575
|
+
RouteService_class_private_field_set(this, _tempDir, '');
|
|
576
|
+
const routeOptions = (null == userConfig ? void 0 : userConfig.route) || {};
|
|
577
|
+
RouteService_class_private_field_set(this, _scanDir, scanDir);
|
|
578
|
+
RouteService_class_private_field_set(this, _extensions, routeOptions.extensions || DEFAULT_PAGE_EXTENSIONS);
|
|
579
|
+
RouteService_class_private_field_set(this, _include, routeOptions.include || []);
|
|
580
|
+
RouteService_class_private_field_set(this, _exclude, routeOptions.exclude || []);
|
|
581
|
+
RouteService_class_private_field_set(this, _defaultLang, (null == userConfig ? void 0 : userConfig.lang) || '');
|
|
582
|
+
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));
|
|
583
|
+
RouteService_class_private_field_set(this, _base, (null == userConfig ? void 0 : userConfig.base) || '');
|
|
584
|
+
RouteService_class_private_field_set(this, _tempDir, tempDir);
|
|
585
|
+
RouteService_class_private_field_set(this, _pluginDriver, pluginDriver);
|
|
586
|
+
if (userConfig.multiVersion) {
|
|
587
|
+
RouteService_class_private_field_set(this, _defaultVersion, userConfig.multiVersion.default || '');
|
|
588
|
+
RouteService_class_private_field_set(this, _versions, userConfig.multiVersion.versions || []);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
async function writeTempFile(index, content) {
|
|
593
|
+
const tempFilePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(RouteService_class_private_field_get(this, _tempDir), `temp-${index}.mdx`);
|
|
594
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(tempFilePath, content);
|
|
595
|
+
return tempFilePath;
|
|
596
|
+
}
|
|
597
|
+
function generateRouteInfo(routePath, filepath) {
|
|
598
|
+
const { routePath: normalizedPath, lang, version } = this.normalizeRoutePath(routePath);
|
|
599
|
+
return {
|
|
600
|
+
routePath: normalizedPath,
|
|
601
|
+
absolutePath: normalizePath(filepath),
|
|
602
|
+
relativePath: normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(RouteService_class_private_field_get(this, _scanDir), filepath)),
|
|
603
|
+
pageName: getPageKey(routePath),
|
|
604
|
+
lang,
|
|
605
|
+
version
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
let init_routeService = null;
|
|
867
609
|
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";
|
|
610
|
+
const { scanDir, config, runtimeTempDir, pluginDriver } = options;
|
|
611
|
+
init_routeService = new RouteService(scanDir, config, runtimeTempDir, pluginDriver);
|
|
612
|
+
await init_routeService.init();
|
|
613
|
+
return init_routeService;
|
|
614
|
+
}
|
|
884
615
|
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
|
-
`;
|
|
616
|
+
const { config, pluginDriver } = context;
|
|
617
|
+
const globalStylesByPlugins = pluginDriver.globalStyles();
|
|
618
|
+
if (config.globalStyles) {
|
|
619
|
+
const source = config.globalStyles;
|
|
620
|
+
const styleContent = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(source, 'utf-8');
|
|
621
|
+
const patchedStyleContent = styleContent.replace(/--modern-/g, '--rp-').replace(/\.modern-doc/g, '.rspress').replace(/\.modern-/g, '.rspress-');
|
|
622
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(source, patchedStyleContent, 'utf-8');
|
|
918
623
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
624
|
+
const moduleContent = (await Promise.all([
|
|
625
|
+
(null == config ? void 0 : config.globalStyles) || '',
|
|
626
|
+
...globalStylesByPlugins
|
|
627
|
+
].filter((source)=>source.length > 0).map(async (source)=>`import ${JSON.stringify(source)};`))).join('');
|
|
628
|
+
return {
|
|
629
|
+
[runtimeModule_RuntimeModuleID.GlobalStyles]: moduleContent
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
async function globalUIComponentsVMPlugin(context) {
|
|
633
|
+
const { config, pluginDriver } = context;
|
|
634
|
+
let index = 0;
|
|
635
|
+
const globalUIComponentsByPlugins = pluginDriver.globalUIComponents();
|
|
636
|
+
const globalComponents = [
|
|
637
|
+
...(null == config ? void 0 : config.globalUIComponents) || [],
|
|
638
|
+
...globalUIComponentsByPlugins
|
|
639
|
+
];
|
|
640
|
+
const moduleContent = globalComponents.map((source)=>{
|
|
641
|
+
const name = `Comp_${index}`;
|
|
642
|
+
if (Array.isArray(source)) return `import ${name} from ${JSON.stringify(source[0])};
|
|
643
|
+
const Props_${index++} = ${JSON.stringify(source[1])};\n`;
|
|
644
|
+
index++;
|
|
645
|
+
return `import ${name} from ${JSON.stringify(source)};\n`;
|
|
646
|
+
}).concat(`export default [${Array.from({
|
|
647
|
+
length: index
|
|
648
|
+
}, (_, i)=>{
|
|
649
|
+
if (Array.isArray(globalComponents[i])) return `[Comp_${i}, Props_${i}]`;
|
|
650
|
+
return `Comp_${i}`;
|
|
651
|
+
}).join(', ')}];`).join('');
|
|
652
|
+
return {
|
|
653
|
+
[runtimeModule_RuntimeModuleID.GlobalComponents]: moduleContent
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
const DEFAULT_I18N_SOURCE = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), 'i18n.json');
|
|
938
657
|
function getI18nData(docConfig) {
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
658
|
+
const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
|
|
659
|
+
try {
|
|
660
|
+
delete require.cache[i18nSourcePath];
|
|
661
|
+
const i18nSource = require(i18nSourcePath);
|
|
662
|
+
return i18nSource;
|
|
663
|
+
} catch (e) {
|
|
664
|
+
return {};
|
|
665
|
+
}
|
|
947
666
|
}
|
|
948
667
|
function i18nVMPlugin(context) {
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
// src/node/runtimeModule/routeData.ts
|
|
668
|
+
const { config } = context;
|
|
669
|
+
const i18nData = getI18nData(config);
|
|
670
|
+
return {
|
|
671
|
+
[runtimeModule_RuntimeModuleID.I18nText]: `export default ${JSON.stringify(i18nData, null, 2)}`
|
|
672
|
+
};
|
|
673
|
+
}
|
|
957
674
|
async function routeVMPlugin(context) {
|
|
958
|
-
|
|
959
|
-
|
|
675
|
+
const { routeService, isSSR } = context;
|
|
676
|
+
if (!isSSR) return {
|
|
677
|
+
[runtimeModule_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
|
|
678
|
+
[runtimeModule_RuntimeModuleID.RouteForSSR]: ''
|
|
679
|
+
};
|
|
960
680
|
return {
|
|
961
|
-
|
|
681
|
+
[runtimeModule_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
|
|
682
|
+
[runtimeModule_RuntimeModuleID.RouteForSSR]: routeService.generateRoutesCode(true)
|
|
962
683
|
};
|
|
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";
|
|
684
|
+
}
|
|
972
685
|
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);
|
|
686
|
+
const { config } = context;
|
|
687
|
+
let content = 'export const onSearch = () => {};';
|
|
688
|
+
let extname = '';
|
|
689
|
+
if ('object' == typeof config.search && 'string' == typeof config.search.searchHooks) {
|
|
690
|
+
content = `export * from '${config.search.searchHooks}'`;
|
|
691
|
+
extname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(config.search.searchHooks);
|
|
1006
692
|
}
|
|
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
|
-
}))
|
|
693
|
+
return {
|
|
694
|
+
[`${runtimeModule_RuntimeModuleID.SearchHooks}${extname}`]: content
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
function createHash(str) {
|
|
698
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__.createHash)('sha256').update(str).digest('hex').slice(0, 8);
|
|
699
|
+
}
|
|
700
|
+
let flattenMdxContent_resolver;
|
|
701
|
+
let startFlatten = false;
|
|
702
|
+
const processor = (0, __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__.createProcessor)();
|
|
703
|
+
const { CachedInputFileSystem, ResolverFactory } = __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__["default"];
|
|
704
|
+
async function resolveDepPath(importPath, importer, alias) {
|
|
705
|
+
if (!flattenMdxContent_resolver) flattenMdxContent_resolver = ResolverFactory.createResolver({
|
|
706
|
+
fileSystem: new CachedInputFileSystem(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"], 0),
|
|
707
|
+
extensions: [
|
|
708
|
+
'.mdx',
|
|
709
|
+
'.md'
|
|
1081
710
|
],
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
711
|
+
alias
|
|
712
|
+
});
|
|
713
|
+
const resolveResult = await new Promise((resolve, reject)=>{
|
|
714
|
+
flattenMdxContent_resolver.resolve({
|
|
715
|
+
importer
|
|
716
|
+
}, importer, importPath, {}, (err, filePath)=>{
|
|
717
|
+
if (err) return reject(err);
|
|
718
|
+
if (!filePath) return reject(new Error(`Empty result when resolving ${importPath} from ${importer}`));
|
|
719
|
+
return resolve(filePath);
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
return resolveResult;
|
|
723
|
+
}
|
|
724
|
+
async function flattenMdxContent(content, basePath, alias) {
|
|
725
|
+
const deps = [];
|
|
726
|
+
const regex = new RegExp(importStatementRegex);
|
|
727
|
+
if (!regex.test(content)) return {
|
|
728
|
+
flattenContent: content,
|
|
729
|
+
deps
|
|
730
|
+
};
|
|
731
|
+
if (!startFlatten) {
|
|
732
|
+
flattenMdxContent_resolver = ResolverFactory.createResolver({
|
|
733
|
+
fileSystem: new CachedInputFileSystem(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"], 0),
|
|
734
|
+
extensions: [
|
|
735
|
+
'.mdx',
|
|
736
|
+
'.md',
|
|
737
|
+
'.js'
|
|
738
|
+
],
|
|
739
|
+
alias
|
|
740
|
+
});
|
|
741
|
+
startFlatten = true;
|
|
742
|
+
}
|
|
743
|
+
let ast;
|
|
744
|
+
let result = content;
|
|
745
|
+
try {
|
|
746
|
+
ast = processor.parse(content);
|
|
747
|
+
} catch (e) {
|
|
1105
748
|
return {
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
${item.text}#
|
|
1109
|
-
|
|
1110
|
-
`, position + 1)
|
|
749
|
+
flattenContent: content,
|
|
750
|
+
deps
|
|
1111
751
|
};
|
|
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
752
|
}
|
|
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);
|
|
753
|
+
const importNodes = ast.children.filter((node)=>'mdxjsEsm' === node.type).flatMap((node)=>{
|
|
754
|
+
var _node_data_estree, _node_data;
|
|
755
|
+
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) || [];
|
|
756
|
+
}).filter((node)=>'ImportDeclaration' === node.type);
|
|
757
|
+
for (const importNode of importNodes){
|
|
758
|
+
const id = importNode.specifiers[0].local.name;
|
|
759
|
+
const importPath = importNode.source.value;
|
|
760
|
+
let absoluteImportPath;
|
|
761
|
+
try {
|
|
762
|
+
absoluteImportPath = await resolveDepPath(importPath, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(basePath), alias);
|
|
763
|
+
} catch (e) {
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
if (__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_REGEXP.test(absoluteImportPath)) {
|
|
767
|
+
const importedContent = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(absoluteImportPath, 'utf-8');
|
|
768
|
+
const { flattenContent: replacedValue, deps: subDeps } = await flattenMdxContent(importedContent, absoluteImportPath, alias);
|
|
769
|
+
result = result.replace(new RegExp(`import\\s+${id}\\s+from\\s+['"](${importPath})['"];?`), '').replace(new RegExp(`<${id}\\s*/>`, 'g'), ()=>replacedValue);
|
|
770
|
+
deps.push(...subDeps, absoluteImportPath);
|
|
1163
771
|
}
|
|
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
772
|
}
|
|
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
|
-
|
|
773
|
+
return {
|
|
774
|
+
flattenContent: result,
|
|
775
|
+
deps
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
function applyReplaceRules(code = '', replaceRules = []) {
|
|
779
|
+
let result = code;
|
|
780
|
+
for (const rule of replaceRules)result = result.replace(rule.search, rule.replace);
|
|
781
|
+
return result;
|
|
782
|
+
}
|
|
783
|
+
function applyReplaceRulesToNestedObject(obj, replaceRules) {
|
|
784
|
+
for(const key in obj)if ('string' == typeof obj[key]) obj[key] = applyReplaceRules(obj[key], replaceRules);
|
|
785
|
+
else if ('object' == typeof obj[key]) obj[key] = applyReplaceRulesToNestedObject(obj[key], replaceRules);
|
|
786
|
+
return obj;
|
|
787
|
+
}
|
|
788
|
+
async function extractPageData(replaceRules, alias, domain, root, routeService, highlighterLangs, searchCodeBlocks) {
|
|
789
|
+
const pageData = await Promise.all(routeService.getRoutes().map(async (route, index)=>{
|
|
790
|
+
var _frontmatter_title;
|
|
791
|
+
const defaultIndexInfo = {
|
|
792
|
+
id: index,
|
|
793
|
+
title: '',
|
|
794
|
+
content: '',
|
|
795
|
+
_html: '',
|
|
796
|
+
routePath: route.routePath,
|
|
797
|
+
lang: route.lang,
|
|
798
|
+
toc: [],
|
|
799
|
+
domain,
|
|
800
|
+
frontmatter: {},
|
|
801
|
+
version: route.version,
|
|
802
|
+
_filepath: route.absolutePath,
|
|
803
|
+
_relativePath: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, route.absolutePath)
|
|
1240
804
|
};
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
const
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
);
|
|
805
|
+
if (!__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_REGEXP.test(route.absolutePath)) return defaultIndexInfo;
|
|
806
|
+
let content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, 'utf8');
|
|
807
|
+
const { frontmatter, content: strippedFrontMatter } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.loadFrontMatter)(content, route.absolutePath, root);
|
|
808
|
+
applyReplaceRulesToNestedObject(frontmatter, replaceRules);
|
|
809
|
+
const { flattenContent } = await flattenMdxContent(applyReplaceRules(strippedFrontMatter, replaceRules), route.absolutePath, alias);
|
|
810
|
+
content = flattenContent.replace(importStatementRegex, '');
|
|
811
|
+
const { html, title, toc: rawToc, languages } = await (0, __WEBPACK_EXTERNAL_MODULE__rspress_mdx_rs_d2f3021f__.compile)({
|
|
812
|
+
value: content,
|
|
813
|
+
filepath: route.absolutePath,
|
|
814
|
+
development: 'production' !== process.env.NODE_ENV,
|
|
815
|
+
root
|
|
816
|
+
});
|
|
817
|
+
if (!(null == title ? void 0 : title.length) && !frontmatter && !(null === (_frontmatter_title = frontmatter.title) || void 0 === _frontmatter_title ? void 0 : _frontmatter_title.length)) return null;
|
|
818
|
+
content = (0, __WEBPACK_EXTERNAL_MODULE_html_to_text_2c51ed38__.htmlToText)(String(html), {
|
|
819
|
+
wordwrap: 80,
|
|
820
|
+
selectors: [
|
|
821
|
+
{
|
|
822
|
+
selector: 'a',
|
|
823
|
+
options: {
|
|
824
|
+
ignoreHref: true
|
|
825
|
+
}
|
|
826
|
+
},
|
|
827
|
+
{
|
|
828
|
+
selector: 'img',
|
|
829
|
+
format: 'skip'
|
|
830
|
+
},
|
|
831
|
+
{
|
|
832
|
+
selector: 'pre > code',
|
|
833
|
+
format: searchCodeBlocks ? 'block' : 'skip'
|
|
834
|
+
},
|
|
835
|
+
...[
|
|
836
|
+
'h1',
|
|
837
|
+
'h2',
|
|
838
|
+
'h3',
|
|
839
|
+
'h4',
|
|
840
|
+
'h5',
|
|
841
|
+
'h6'
|
|
842
|
+
].map((tag)=>({
|
|
843
|
+
selector: tag,
|
|
844
|
+
options: {
|
|
845
|
+
uppercase: false
|
|
846
|
+
}
|
|
847
|
+
}))
|
|
848
|
+
],
|
|
849
|
+
tables: true,
|
|
850
|
+
longWordSplit: {
|
|
851
|
+
forceWrapOnLimit: true
|
|
852
|
+
}
|
|
853
|
+
});
|
|
854
|
+
if (content.startsWith(title)) content = content.slice(title.length);
|
|
855
|
+
languages.forEach((lang)=>highlighterLangs.add(lang));
|
|
856
|
+
const toc = rawToc.map((item)=>{
|
|
857
|
+
const match = item.id.match(/-(\d+)$/);
|
|
858
|
+
let position = -1;
|
|
859
|
+
if (match) for(let i = 0; i < Number(match[1]); i++){
|
|
860
|
+
position = content.indexOf(`\n${item.text}#\n\n`, position + 1);
|
|
861
|
+
if (-1 === position) break;
|
|
862
|
+
}
|
|
863
|
+
return {
|
|
864
|
+
...item,
|
|
865
|
+
charIndex: content.indexOf(`\n${item.text}#\n\n`, position + 1)
|
|
866
|
+
};
|
|
867
|
+
});
|
|
1247
868
|
return {
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
869
|
+
...defaultIndexInfo,
|
|
870
|
+
title: frontmatter.title || title,
|
|
871
|
+
toc,
|
|
872
|
+
content,
|
|
873
|
+
_html: html,
|
|
874
|
+
frontmatter: {
|
|
875
|
+
...frontmatter,
|
|
876
|
+
__content: void 0
|
|
877
|
+
}
|
|
1251
878
|
};
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
879
|
+
}));
|
|
880
|
+
return pageData.filter(Boolean);
|
|
881
|
+
}
|
|
882
|
+
let highlightLanguages_supportedLanguages;
|
|
883
|
+
function handleHighlightLanguages(highlightLanguages, defaultLanguages) {
|
|
884
|
+
const aliases = {};
|
|
885
|
+
if (highlightLanguages.size) {
|
|
886
|
+
if (!highlightLanguages_supportedLanguages) {
|
|
887
|
+
const langs = __webpack_require__("react-syntax-highlighter/dist/cjs/languages/prism/supported-languages")["default"];
|
|
888
|
+
highlightLanguages_supportedLanguages = new Set(langs);
|
|
889
|
+
}
|
|
890
|
+
let useDeprecatedTypeWarning = true;
|
|
891
|
+
const names = {};
|
|
892
|
+
[
|
|
893
|
+
...__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.DEFAULT_HIGHLIGHT_LANGUAGES,
|
|
894
|
+
...defaultLanguages
|
|
895
|
+
].forEach((lang)=>{
|
|
896
|
+
if (Array.isArray(lang)) {
|
|
897
|
+
const [alias, name] = lang;
|
|
898
|
+
names[alias] = name;
|
|
899
|
+
} else if (useDeprecatedTypeWarning) {
|
|
900
|
+
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`);
|
|
901
|
+
useDeprecatedTypeWarning = false;
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
[
|
|
905
|
+
...highlightLanguages.values()
|
|
906
|
+
].forEach((lang)=>{
|
|
907
|
+
const name = names[lang];
|
|
908
|
+
if (name && highlightLanguages_supportedLanguages.has(name)) {
|
|
909
|
+
const temp = aliases[name] || (aliases[name] = []);
|
|
910
|
+
if (!temp.includes(lang)) temp.push(lang);
|
|
911
|
+
highlightLanguages.delete(lang);
|
|
912
|
+
highlightLanguages.add(name);
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
if (!highlightLanguages_supportedLanguages.has(lang)) highlightLanguages.delete(lang);
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
return aliases;
|
|
919
|
+
}
|
|
920
|
+
function normalizeThemeConfig(docConfig, pages = []) {
|
|
921
|
+
const { locales: siteLocales, base = '', lang, replaceRules = [], multiVersion } = docConfig;
|
|
922
|
+
const { versions = [] } = multiVersion || {};
|
|
923
|
+
const hasMultiVersion = versions.length > 0;
|
|
924
|
+
docConfig.themeConfig = docConfig.themeConfig || {};
|
|
925
|
+
const { themeConfig } = docConfig;
|
|
926
|
+
const locales = siteLocales ?? ((null == themeConfig ? void 0 : themeConfig.locales) || []);
|
|
927
|
+
const i18nTextData = getI18nData(docConfig);
|
|
928
|
+
const normalizeLinkPrefix = (link = '', currentLang = '')=>{
|
|
929
|
+
const normalizedLink = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(link);
|
|
930
|
+
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;
|
|
931
|
+
return lang === currentLang ? normalizedLink : `/${currentLang}${(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)(normalizedLink)}`;
|
|
1262
932
|
};
|
|
1263
|
-
const
|
|
1264
|
-
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1267
|
-
});
|
|
933
|
+
const getI18nText = (key = '', currentLang = '')=>{
|
|
934
|
+
var _i18nTextData_key;
|
|
935
|
+
const text = null === (_i18nTextData_key = i18nTextData[key]) || void 0 === _i18nTextData_key ? void 0 : _i18nTextData_key[currentLang];
|
|
936
|
+
return text || key;
|
|
1268
937
|
};
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
938
|
+
const normalizeSidebar = (sidebar, currentLang = '')=>{
|
|
939
|
+
const normalizedSidebar = {};
|
|
940
|
+
if (!sidebar) return {};
|
|
941
|
+
const normalizeSidebarItem = (item)=>{
|
|
942
|
+
if ('object' == typeof item && 'dividerType' in item) return item;
|
|
943
|
+
if ('object' == typeof item && 'sectionHeaderText' in item) {
|
|
944
|
+
item.sectionHeaderText = applyReplaceRules(getI18nText(item.sectionHeaderText, currentLang), replaceRules);
|
|
945
|
+
return item;
|
|
946
|
+
}
|
|
947
|
+
if ('object' == typeof item && 'items' in item) return {
|
|
948
|
+
...item,
|
|
949
|
+
text: applyReplaceRules(getI18nText(item.text, currentLang), replaceRules),
|
|
950
|
+
link: normalizeLinkPrefix(item.link),
|
|
951
|
+
collapsed: item.collapsed ?? false,
|
|
952
|
+
collapsible: item.collapsible ?? true,
|
|
953
|
+
tag: item.tag,
|
|
954
|
+
items: item.items.map((subItem)=>normalizeSidebarItem(subItem))
|
|
955
|
+
};
|
|
956
|
+
if ('string' == typeof item) {
|
|
957
|
+
const normalizedItem = normalizeLinkPrefix(item, currentLang);
|
|
958
|
+
const page = pages.find((page)=>page.routePath === (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(normalizedItem, base));
|
|
959
|
+
return {
|
|
960
|
+
text: applyReplaceRules((null == page ? void 0 : page.title) || '', replaceRules),
|
|
961
|
+
link: normalizedItem,
|
|
962
|
+
_fileKey: page._relativePath.replace(/\.mdx?$/, '')
|
|
963
|
+
};
|
|
964
|
+
}
|
|
1293
965
|
return {
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
),
|
|
1299
|
-
link: normalizeLinkPrefix(item.link, currentLang)
|
|
966
|
+
...item,
|
|
967
|
+
text: applyReplaceRules(getI18nText(item.text, currentLang), replaceRules),
|
|
968
|
+
link: normalizeLinkPrefix(item.link),
|
|
969
|
+
tag: item.tag
|
|
1300
970
|
};
|
|
1301
|
-
})
|
|
1302
971
|
};
|
|
1303
|
-
|
|
1304
|
-
|
|
972
|
+
const normalizeSidebar = (sidebar)=>{
|
|
973
|
+
Object.keys(sidebar).forEach((key)=>{
|
|
974
|
+
const value = sidebar[key];
|
|
975
|
+
normalizedSidebar[key] = value.map(normalizeSidebarItem);
|
|
976
|
+
});
|
|
977
|
+
};
|
|
978
|
+
normalizeSidebar(sidebar);
|
|
979
|
+
return normalizedSidebar;
|
|
1305
980
|
};
|
|
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
|
-
|
|
981
|
+
const normalizeNav = (nav, currentLang)=>{
|
|
982
|
+
if (!nav) return [];
|
|
983
|
+
const transformNavItem = (navItem)=>{
|
|
984
|
+
const text = applyReplaceRules(getI18nText(navItem.text, currentLang), replaceRules);
|
|
985
|
+
if ('link' in navItem) return {
|
|
986
|
+
...navItem,
|
|
987
|
+
text,
|
|
988
|
+
link: normalizeLinkPrefix(navItem.link, currentLang)
|
|
989
|
+
};
|
|
990
|
+
if ('items' in navItem) return {
|
|
991
|
+
...navItem,
|
|
992
|
+
text,
|
|
993
|
+
items: navItem.items.map((item)=>({
|
|
994
|
+
...item,
|
|
995
|
+
text: applyReplaceRules(getI18nText(item.text, currentLang), replaceRules),
|
|
996
|
+
link: normalizeLinkPrefix(item.link, currentLang)
|
|
997
|
+
}))
|
|
998
|
+
};
|
|
999
|
+
return navItem;
|
|
1000
|
+
};
|
|
1001
|
+
if (Array.isArray(nav)) return nav.map(transformNavItem);
|
|
1002
|
+
return Object.entries(nav).reduce((acc, [key, value])=>{
|
|
1003
|
+
acc[key] = value.map(transformNavItem);
|
|
1004
|
+
return acc;
|
|
1005
|
+
}, {});
|
|
1006
|
+
};
|
|
1007
|
+
if (locales.length) themeConfig.locales = locales.map(({ lang: currentLang, label })=>{
|
|
1008
|
+
var _themeConfig_locales;
|
|
1009
|
+
const localeInThemeConfig = null === (_themeConfig_locales = themeConfig.locales) || void 0 === _themeConfig_locales ? void 0 : _themeConfig_locales.find((locale)=>locale.lang === currentLang);
|
|
1010
|
+
return {
|
|
1011
|
+
lang: currentLang,
|
|
1012
|
+
label,
|
|
1013
|
+
...localeInThemeConfig || {},
|
|
1014
|
+
sidebar: normalizeSidebar((null == localeInThemeConfig ? void 0 : localeInThemeConfig.sidebar) ?? themeConfig.sidebar, currentLang),
|
|
1015
|
+
nav: normalizeNav((null == localeInThemeConfig ? void 0 : localeInThemeConfig.nav) ?? themeConfig.nav, currentLang)
|
|
1016
|
+
};
|
|
1332
1017
|
});
|
|
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];
|
|
1018
|
+
else {
|
|
1019
|
+
themeConfig.sidebar = normalizeSidebar(null == themeConfig ? void 0 : themeConfig.sidebar);
|
|
1020
|
+
themeConfig.nav = normalizeNav(null == themeConfig ? void 0 : themeConfig.nav);
|
|
1349
1021
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1022
|
+
return themeConfig;
|
|
1023
|
+
}
|
|
1024
|
+
function deletePrivateField(obj) {
|
|
1025
|
+
if ('object' != typeof obj || null === obj) return obj;
|
|
1026
|
+
const newObj = {
|
|
1027
|
+
...obj
|
|
1028
|
+
};
|
|
1029
|
+
Object.keys(newObj).forEach((key)=>{
|
|
1030
|
+
if (key.startsWith('_')) delete newObj[key];
|
|
1031
|
+
});
|
|
1032
|
+
return newObj;
|
|
1352
1033
|
}
|
|
1353
1034
|
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
|
-
)};
|
|
1035
|
+
var _userConfig_themeConfig, _userConfig_multiVersion, _userConfig_multiVersion1, _userConfig_markdown, _userConfig_markdown1, _userConfig_markdown2, _siteData_pages__extraHighlightLanguages, _siteData_pages_;
|
|
1036
|
+
const { config, alias, userDocRoot, routeService, pluginDriver } = context;
|
|
1037
|
+
const userConfig = config;
|
|
1038
|
+
const tempSearchObj = Object.assign({}, userConfig.search);
|
|
1039
|
+
if (tempSearchObj) tempSearchObj.searchHooks = void 0;
|
|
1040
|
+
const highlightLanguages = new Set();
|
|
1041
|
+
const replaceRules = (null == userConfig ? void 0 : userConfig.replaceRules) || [];
|
|
1042
|
+
const searchConfig = (null == userConfig ? void 0 : userConfig.search) || {};
|
|
1043
|
+
const domain = (null == searchConfig ? void 0 : searchConfig.mode) === 'remote' ? searchConfig.domain ?? '' : '';
|
|
1044
|
+
const searchCodeBlocks = 'codeBlocks' in searchConfig && searchConfig.codeBlocks;
|
|
1045
|
+
const pages = await extractPageData(replaceRules, alias, domain, userDocRoot, routeService, highlightLanguages, searchCodeBlocks);
|
|
1046
|
+
await pluginDriver.modifySearchIndexData(pages);
|
|
1047
|
+
const versioned = userConfig.search && 'remote' !== userConfig.search.mode && userConfig.search.versioned;
|
|
1048
|
+
const groupedPages = (0, __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__.groupBy)(pages, (page)=>{
|
|
1049
|
+
var _page_frontmatter;
|
|
1050
|
+
if ((null === (_page_frontmatter = page.frontmatter) || void 0 === _page_frontmatter ? void 0 : _page_frontmatter.pageType) === 'home') return 'noindex';
|
|
1051
|
+
const version = versioned ? page.version : '';
|
|
1052
|
+
const lang = page.lang || '';
|
|
1053
|
+
return `${version}###${lang}`;
|
|
1054
|
+
});
|
|
1055
|
+
delete groupedPages.noindex;
|
|
1056
|
+
const indexHashByGroup = {};
|
|
1057
|
+
await Promise.all(Object.keys(groupedPages).map(async (group)=>{
|
|
1058
|
+
const stringifiedIndex = JSON.stringify(groupedPages[group].map(deletePrivateField));
|
|
1059
|
+
const indexHash = createHash(stringifiedIndex);
|
|
1060
|
+
indexHashByGroup[group] = indexHash;
|
|
1061
|
+
const [version, lang] = group.split('###');
|
|
1062
|
+
const indexVersion = version ? `.${version.replace('.', '_')}` : '';
|
|
1063
|
+
const indexLang = lang ? `.${lang}` : '';
|
|
1064
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(TEMP_DIR, {
|
|
1065
|
+
recursive: true
|
|
1066
|
+
});
|
|
1067
|
+
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);
|
|
1068
|
+
}));
|
|
1069
|
+
await Promise.all(pages.map(async (pageData)=>pluginDriver.extendPageData(pageData)));
|
|
1070
|
+
const siteData = {
|
|
1071
|
+
title: (null == userConfig ? void 0 : userConfig.title) || '',
|
|
1072
|
+
description: (null == userConfig ? void 0 : userConfig.description) || '',
|
|
1073
|
+
icon: (null == userConfig ? void 0 : userConfig.icon) || '',
|
|
1074
|
+
route: null == userConfig ? void 0 : userConfig.route,
|
|
1075
|
+
themeConfig: normalizeThemeConfig(userConfig, pages),
|
|
1076
|
+
base: (null == userConfig ? void 0 : userConfig.base) || '/',
|
|
1077
|
+
lang: (null == userConfig ? void 0 : userConfig.lang) || '',
|
|
1078
|
+
locales: (null == userConfig ? void 0 : userConfig.locales) || (null === (_userConfig_themeConfig = userConfig.themeConfig) || void 0 === _userConfig_themeConfig ? void 0 : _userConfig_themeConfig.locales) || [],
|
|
1079
|
+
logo: (null == userConfig ? void 0 : userConfig.logo) || '',
|
|
1080
|
+
logoText: (null == userConfig ? void 0 : userConfig.logoText) || '',
|
|
1081
|
+
ssg: Boolean(null == userConfig ? void 0 : userConfig.ssg) ?? true,
|
|
1082
|
+
multiVersion: {
|
|
1083
|
+
default: (null == userConfig ? void 0 : null === (_userConfig_multiVersion = userConfig.multiVersion) || void 0 === _userConfig_multiVersion ? void 0 : _userConfig_multiVersion.default) || '',
|
|
1084
|
+
versions: (null == userConfig ? void 0 : null === (_userConfig_multiVersion1 = userConfig.multiVersion) || void 0 === _userConfig_multiVersion1 ? void 0 : _userConfig_multiVersion1.versions) || []
|
|
1085
|
+
},
|
|
1086
|
+
search: tempSearchObj ?? {
|
|
1087
|
+
mode: 'local'
|
|
1088
|
+
},
|
|
1089
|
+
pages: pages.map((page)=>{
|
|
1090
|
+
const { content, id, domain, _filepath, _html, ...rest } = page;
|
|
1091
|
+
return isProduction() ? rest : {
|
|
1092
|
+
...rest,
|
|
1093
|
+
_filepath
|
|
1094
|
+
};
|
|
1095
|
+
}),
|
|
1096
|
+
markdown: {
|
|
1097
|
+
showLineNumbers: (null == userConfig ? void 0 : null === (_userConfig_markdown = userConfig.markdown) || void 0 === _userConfig_markdown ? void 0 : _userConfig_markdown.showLineNumbers) ?? false,
|
|
1098
|
+
defaultWrapCode: (null == userConfig ? void 0 : null === (_userConfig_markdown1 = userConfig.markdown) || void 0 === _userConfig_markdown1 ? void 0 : _userConfig_markdown1.defaultWrapCode) ?? false,
|
|
1099
|
+
codeHighlighter: (null == userConfig ? void 0 : null === (_userConfig_markdown2 = userConfig.markdown) || void 0 === _userConfig_markdown2 ? void 0 : _userConfig_markdown2.codeHighlighter) || 'prism'
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
const { highlightLanguages: defaultLanguages = [] } = config.markdown || {};
|
|
1103
|
+
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));
|
|
1104
|
+
const aliases = handleHighlightLanguages(highlightLanguages, defaultLanguages);
|
|
1105
|
+
const sortedAliases = Object.fromEntries(Object.entries(aliases).sort());
|
|
1106
|
+
const sortedHighlightLanguages = Array.from(highlightLanguages).sort();
|
|
1107
|
+
return {
|
|
1108
|
+
[`${runtimeModule_RuntimeModuleID.SiteData}.mjs`]: `export default ${JSON.stringify(siteData, null, 2)}`,
|
|
1109
|
+
[runtimeModule_RuntimeModuleID.SearchIndexHash]: `export default ${JSON.stringify(indexHashByGroup, null, 2)}`,
|
|
1110
|
+
[runtimeModule_RuntimeModuleID.PrismLanguages]: `export const aliases = ${JSON.stringify(sortedAliases, null, 2)};
|
|
1464
1111
|
export const languages = {
|
|
1465
|
-
${sortedHighlightLanguages.map((lang)
|
|
1466
|
-
return `"${lang}": require(
|
|
1112
|
+
${sortedHighlightLanguages.map((lang)=>`"${lang}": require(
|
|
1467
1113
|
"react-syntax-highlighter/dist/cjs/languages/prism/${lang}"
|
|
1468
|
-
).default
|
|
1469
|
-
})}
|
|
1114
|
+
).default`)}
|
|
1470
1115
|
}`
|
|
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
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
const runtimeModuleFactory = [
|
|
1119
|
+
routeVMPlugin,
|
|
1120
|
+
siteDataVMPlugin,
|
|
1121
|
+
globalUIComponentsVMPlugin,
|
|
1122
|
+
globalStylesVMPlugin,
|
|
1123
|
+
i18nVMPlugin,
|
|
1124
|
+
searchHookVMPlugin
|
|
1501
1125
|
];
|
|
1502
1126
|
function rsbuildPluginDocVM(factoryContext) {
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1127
|
+
const { pluginDriver } = factoryContext;
|
|
1128
|
+
return {
|
|
1129
|
+
name: 'rsbuild-plugin-doc-vm',
|
|
1130
|
+
setup (api) {
|
|
1131
|
+
api.modifyBundlerChain(async (bundlerChain, { target })=>{
|
|
1132
|
+
const isServer = 'node' === target;
|
|
1133
|
+
const alias = bundlerChain.resolve.alias.entries();
|
|
1134
|
+
const runtimeModule = {};
|
|
1135
|
+
for (const factory of runtimeModuleFactory){
|
|
1136
|
+
const moduleResult = await factory({
|
|
1137
|
+
...factoryContext,
|
|
1138
|
+
isSSR: isServer,
|
|
1139
|
+
alias: alias
|
|
1140
|
+
});
|
|
1141
|
+
Object.assign(runtimeModule, moduleResult);
|
|
1142
|
+
}
|
|
1143
|
+
const modulesByPlugin = await pluginDriver.addRuntimeModules();
|
|
1144
|
+
Object.keys(modulesByPlugin).forEach((key)=>{
|
|
1145
|
+
if (runtimeModule[key]) throw new Error(`The runtime module ${key} is duplicated, please check your plugin`);
|
|
1146
|
+
runtimeModule[key] = modulesByPlugin[key];
|
|
1147
|
+
});
|
|
1148
|
+
bundlerChain.plugin('rspress-runtime-module').use(new __WEBPACK_EXTERNAL_MODULE_rspack_plugin_virtual_module_609978fd__.RspackVirtualModulePlugin(runtimeModule, factoryContext.runtimeTempDir));
|
|
1149
|
+
});
|
|
1518
1150
|
}
|
|
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";
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
var runtimeModule_RuntimeModuleID = /*#__PURE__*/ function(RuntimeModuleID) {
|
|
1154
|
+
RuntimeModuleID["GlobalStyles"] = "virtual-global-styles";
|
|
1155
|
+
RuntimeModuleID["GlobalComponents"] = "virtual-global-components";
|
|
1156
|
+
RuntimeModuleID["RouteForClient"] = "virtual-routes";
|
|
1157
|
+
RuntimeModuleID["RouteForSSR"] = "virtual-routes-ssr";
|
|
1158
|
+
RuntimeModuleID["SiteData"] = "virtual-site-data";
|
|
1159
|
+
RuntimeModuleID["SearchIndexHash"] = "virtual-search-index-hash";
|
|
1160
|
+
RuntimeModuleID["I18nText"] = "virtual-i18n-text";
|
|
1161
|
+
RuntimeModuleID["SearchHooks"] = "virtual-search-hooks";
|
|
1162
|
+
RuntimeModuleID["PrismLanguages"] = "virtual-prism-languages";
|
|
1163
|
+
return RuntimeModuleID;
|
|
1164
|
+
}({});
|
|
1546
1165
|
async function writeSearchIndex(config) {
|
|
1547
|
-
|
|
1548
|
-
return;
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1166
|
+
var _config_search;
|
|
1167
|
+
if ((null == config ? void 0 : config.search) === false) return;
|
|
1168
|
+
const cwd = process.cwd();
|
|
1169
|
+
const searchIndexFiles = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readdir(TEMP_DIR);
|
|
1170
|
+
const outDir = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, OUTPUT_DIR);
|
|
1171
|
+
const targetDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outDir, 'static');
|
|
1172
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(targetDir, {
|
|
1173
|
+
recursive: true
|
|
1174
|
+
});
|
|
1175
|
+
let searchIndexData = '[]';
|
|
1176
|
+
let scanning = false;
|
|
1177
|
+
for (const searchIndexFile of searchIndexFiles){
|
|
1178
|
+
if (!searchIndexFile.includes(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME) || !searchIndexFile.endsWith('.json')) continue;
|
|
1179
|
+
const source = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(TEMP_DIR, searchIndexFile);
|
|
1180
|
+
const target = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(targetDir, searchIndexFile);
|
|
1181
|
+
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');
|
|
1182
|
+
searchIndexData = `${searchIndexData.slice(0, -1)}${scanning ? ',' : ''}${searchIndex.slice(1)}`;
|
|
1183
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].rename(source, target);
|
|
1184
|
+
scanning = true;
|
|
1560
1185
|
}
|
|
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
|
-
);
|
|
1186
|
+
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') {
|
|
1187
|
+
const { apiUrl, indexName } = config.search;
|
|
1188
|
+
try {
|
|
1189
|
+
await fetch(`${apiUrl}?index=${indexName}`, {
|
|
1190
|
+
method: 'PUT',
|
|
1191
|
+
body: searchIndexData,
|
|
1192
|
+
headers: {
|
|
1193
|
+
'Content-Type': 'application/json'
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info(__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].green(`[doc-tools] Search index uploaded to ${apiUrl}, indexName: ${indexName}`));
|
|
1197
|
+
} catch (e) {
|
|
1198
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info(__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].red(`[doc-tools] Upload search index \`${indexName}\` failed:\n ${e}`));
|
|
1199
|
+
}
|
|
1591
1200
|
}
|
|
1592
|
-
}
|
|
1593
1201
|
}
|
|
1594
1202
|
function serveSearchIndexMiddleware(config) {
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1203
|
+
return (req, res, next)=>{
|
|
1204
|
+
var _req_url;
|
|
1205
|
+
const searchIndexRequestMatch = `/${__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME}.`;
|
|
1206
|
+
if (null === (_req_url = req.url) || void 0 === _req_url ? void 0 : _req_url.includes(searchIndexRequestMatch)) {
|
|
1207
|
+
var _req_url1;
|
|
1208
|
+
res.setHeader('Content-Type', 'application/json');
|
|
1209
|
+
const searchIndexFile = null === (_req_url1 = req.url) || void 0 === _req_url1 ? void 0 : _req_url1.split('/').pop();
|
|
1210
|
+
(0, __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.createReadStream)(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), (null == config ? void 0 : config.outDir) || OUTPUT_DIR, 'static', searchIndexFile), 'utf-8').pipe(res, {
|
|
1211
|
+
end: true
|
|
1212
|
+
});
|
|
1213
|
+
} else null == next || next();
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
async function pathExists(path) {
|
|
1217
|
+
try {
|
|
1218
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].access(path);
|
|
1219
|
+
return true;
|
|
1220
|
+
} catch {
|
|
1221
|
+
return false;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
async function readJson(path) {
|
|
1225
|
+
const raw = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(path, 'utf8');
|
|
1226
|
+
return JSON.parse(raw);
|
|
1227
|
+
}
|
|
1228
|
+
const { CachedInputFileSystem: detectReactVersion_CachedInputFileSystem, ResolverFactory: detectReactVersion_ResolverFactory } = __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__["default"];
|
|
1229
|
+
const DEFAULT_REACT_VERSION = 18;
|
|
1230
|
+
async function detectReactVersion() {
|
|
1231
|
+
const cwd = process.cwd();
|
|
1232
|
+
const reactPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(cwd, 'node_modules', 'react');
|
|
1233
|
+
if (await pathExists(reactPath)) {
|
|
1234
|
+
var _reactPkg_version;
|
|
1235
|
+
const reactPkg = await readJson(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(reactPath, 'package.json'));
|
|
1236
|
+
const version = Number(null === (_reactPkg_version = reactPkg.version) || void 0 === _reactPkg_version ? void 0 : _reactPkg_version.split('.')[0]);
|
|
1237
|
+
return version;
|
|
1611
1238
|
}
|
|
1612
|
-
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1239
|
+
return DEFAULT_REACT_VERSION;
|
|
1240
|
+
}
|
|
1241
|
+
async function resolveReactAlias(reactVersion, isSSR) {
|
|
1242
|
+
const basedir = reactVersion === DEFAULT_REACT_VERSION ? PACKAGE_ROOT : process.cwd();
|
|
1243
|
+
const libPaths = [
|
|
1244
|
+
'react',
|
|
1245
|
+
'react/jsx-runtime',
|
|
1246
|
+
'react/jsx-dev-runtime',
|
|
1247
|
+
'react-dom',
|
|
1248
|
+
'react-dom/server'
|
|
1249
|
+
];
|
|
1250
|
+
if (reactVersion >= DEFAULT_REACT_VERSION) libPaths.push('react-dom/client');
|
|
1251
|
+
const alias = {};
|
|
1252
|
+
const resolver = detectReactVersion_ResolverFactory.createResolver({
|
|
1253
|
+
fileSystem: new detectReactVersion_CachedInputFileSystem(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"], 0),
|
|
1254
|
+
extensions: [
|
|
1255
|
+
'.js'
|
|
1256
|
+
],
|
|
1257
|
+
alias,
|
|
1258
|
+
conditionNames: isSSR ? [
|
|
1259
|
+
'...'
|
|
1260
|
+
] : [
|
|
1261
|
+
'browser',
|
|
1262
|
+
'...'
|
|
1263
|
+
]
|
|
1264
|
+
});
|
|
1265
|
+
await Promise.all(libPaths.map(async (lib)=>{
|
|
1266
|
+
try {
|
|
1267
|
+
alias[lib] = await new Promise((resolve, reject)=>{
|
|
1268
|
+
resolver.resolve({
|
|
1269
|
+
importer: basedir
|
|
1270
|
+
}, basedir, lib, {}, (err, filePath)=>{
|
|
1271
|
+
if (err || false === filePath) return reject(err);
|
|
1272
|
+
return resolve(filePath);
|
|
1273
|
+
});
|
|
1274
|
+
});
|
|
1275
|
+
} catch (e) {
|
|
1276
|
+
console.log(e);
|
|
1277
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`${lib} not found`);
|
|
1278
|
+
}
|
|
1279
|
+
}));
|
|
1280
|
+
return alias;
|
|
1281
|
+
}
|
|
1282
|
+
const detectCustomIcon = async (customThemeDir)=>{
|
|
1283
|
+
const assetsDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(customThemeDir, 'assets');
|
|
1284
|
+
const alias = {};
|
|
1285
|
+
if (!(0, __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.existsSync)(assetsDir)) return alias;
|
|
1286
|
+
const files = await (0, __WEBPACK_EXTERNAL_MODULE_tinyglobby__.glob)('*.svg', {
|
|
1287
|
+
cwd: assetsDir
|
|
1288
|
+
});
|
|
1289
|
+
files.forEach((file)=>{
|
|
1290
|
+
const name = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].basename(file, '.svg');
|
|
1291
|
+
alias[`@theme-assets/${name}`] = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(assetsDir, file);
|
|
1292
|
+
});
|
|
1623
1293
|
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
1294
|
};
|
|
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"/>
|
|
1295
|
+
const presetIcons = {
|
|
1296
|
+
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"/>',
|
|
1297
|
+
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"/>',
|
|
1298
|
+
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"/>',
|
|
1299
|
+
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"/>',
|
|
1300
|
+
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"/>',
|
|
1301
|
+
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"/>',
|
|
1302
|
+
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"/>',
|
|
1303
|
+
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"/>',
|
|
1304
|
+
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"/>',
|
|
1305
|
+
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"/>',
|
|
1306
|
+
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"/>',
|
|
1307
|
+
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"/>',
|
|
1308
|
+
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"/>',
|
|
1309
|
+
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"/>',
|
|
1310
|
+
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
1311
|
<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();
|
|
1312
|
+
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"/>',
|
|
1313
|
+
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
1314
|
};
|
|
1315
|
+
const formatIconName = (icon)=>icon.toLowerCase();
|
|
1659
1316
|
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>`;
|
|
1317
|
+
const icons = {};
|
|
1318
|
+
for (const link of socialLinks)if ('string' == typeof link.icon) {
|
|
1319
|
+
const pathContent = presetIcons[formatIconName(link.icon)];
|
|
1320
|
+
icons[link.icon] = `<svg xmlns="http://www.w3.org/2000/svg" width="100%" viewBox="0 0 24 24">${pathContent}</svg>`;
|
|
1665
1321
|
}
|
|
1666
|
-
|
|
1667
|
-
return icons;
|
|
1322
|
+
return icons;
|
|
1668
1323
|
}
|
|
1669
|
-
|
|
1670
|
-
// src/node/initRsbuild.ts
|
|
1671
1324
|
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
|
|
1325
|
+
var _config_builderPlugins, _config_builderConfig_plugins, _config_builderConfig;
|
|
1326
|
+
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));
|
|
1327
|
+
}
|
|
1328
|
+
async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver, runtimeTempDir) {
|
|
1329
|
+
var _config_builderConfig_output, _config_builderConfig, _config_themeConfig;
|
|
1330
|
+
const cwd = process.cwd();
|
|
1331
|
+
const CUSTOM_THEME_DIR = (null == config ? void 0 : config.themeDir) ?? __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'theme');
|
|
1332
|
+
const baseOutDir = (null == config ? void 0 : config.outDir) ?? OUTPUT_DIR;
|
|
1333
|
+
const csrOutDir = baseOutDir;
|
|
1334
|
+
const ssrOutDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(baseOutDir, 'ssr');
|
|
1335
|
+
const DEFAULT_THEME = require.resolve('@rspress/theme-default');
|
|
1336
|
+
const base = (null == config ? void 0 : config.base) ?? '';
|
|
1337
|
+
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) : '';
|
|
1338
|
+
const reactVersion = await detectReactVersion();
|
|
1339
|
+
const normalizeIcon = (icon)=>{
|
|
1340
|
+
if (!icon) return;
|
|
1341
|
+
if (__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].isAbsolute(icon)) return __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(userDocRoot, PUBLIC_DIR, icon);
|
|
1342
|
+
return icon;
|
|
1343
|
+
};
|
|
1344
|
+
const [detectCustomIconAlias, reactCSRAlias, reactSSRAlias] = await Promise.all([
|
|
1345
|
+
detectCustomIcon(CUSTOM_THEME_DIR),
|
|
1346
|
+
resolveReactAlias(reactVersion, false),
|
|
1347
|
+
enableSSG ? resolveReactAlias(reactVersion, true) : Promise.resolve({})
|
|
1348
|
+
]);
|
|
1349
|
+
return {
|
|
1350
|
+
plugins: [
|
|
1351
|
+
...isPluginIncluded(config, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__.PLUGIN_REACT_NAME) ? [] : [
|
|
1352
|
+
(0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__.pluginReact)()
|
|
1353
|
+
],
|
|
1354
|
+
...isPluginIncluded(config, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_sass_b13a7d33__.PLUGIN_SASS_NAME) ? [] : [
|
|
1355
|
+
(0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_sass_b13a7d33__.pluginSass)()
|
|
1356
|
+
],
|
|
1357
|
+
...isPluginIncluded(config, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_less_4c557a99__.PLUGIN_LESS_NAME) ? [] : [
|
|
1358
|
+
(0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_less_4c557a99__.pluginLess)()
|
|
1359
|
+
],
|
|
1360
|
+
rsbuildPluginDocVM({
|
|
1361
|
+
userDocRoot,
|
|
1362
|
+
config,
|
|
1363
|
+
runtimeTempDir,
|
|
1364
|
+
routeService,
|
|
1365
|
+
pluginDriver
|
|
1366
|
+
})
|
|
1367
|
+
],
|
|
1368
|
+
server: {
|
|
1369
|
+
port: !isProduction() && process.env.PORT ? Number(process.env.PORT) : void 0,
|
|
1370
|
+
printUrls: ({ urls })=>urls.map((url)=>`${url}/${(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeLeadingSlash)(base)}`),
|
|
1371
|
+
publicDir: {
|
|
1372
|
+
name: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(userDocRoot, PUBLIC_DIR)
|
|
1790
1373
|
}
|
|
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
1374
|
},
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1375
|
+
dev: {
|
|
1376
|
+
progressBar: false,
|
|
1377
|
+
setupMiddlewares: [
|
|
1378
|
+
(middlewares)=>{
|
|
1379
|
+
middlewares.unshift(serveSearchIndexMiddleware(config));
|
|
1380
|
+
}
|
|
1381
|
+
],
|
|
1382
|
+
cliShortcuts: {
|
|
1383
|
+
custom: (shortcuts)=>shortcuts.filter(({ key })=>'r' !== key)
|
|
1384
|
+
}
|
|
1385
|
+
},
|
|
1386
|
+
html: {
|
|
1387
|
+
title: (null == config ? void 0 : config.title) ?? DEFAULT_TITLE,
|
|
1388
|
+
favicon: normalizeIcon(null == config ? void 0 : config.icon),
|
|
1389
|
+
template: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'index.html'),
|
|
1390
|
+
tags: [
|
|
1391
|
+
(null === (_config_themeConfig = config.themeConfig) || void 0 === _config_themeConfig ? void 0 : _config_themeConfig.darkMode) !== false && {
|
|
1392
|
+
tag: "script",
|
|
1393
|
+
children: inlineThemeScript,
|
|
1394
|
+
append: false
|
|
1395
|
+
}
|
|
1396
|
+
].filter(Boolean)
|
|
1841
1397
|
},
|
|
1842
1398
|
output: {
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1399
|
+
assetPrefix,
|
|
1400
|
+
distPath: {
|
|
1401
|
+
root: csrOutDir
|
|
1402
|
+
}
|
|
1403
|
+
},
|
|
1404
|
+
resolve: {
|
|
1405
|
+
alias: {
|
|
1406
|
+
...detectCustomIconAlias,
|
|
1407
|
+
'@mdx-js/react': require.resolve('@mdx-js/react'),
|
|
1408
|
+
'@theme': [
|
|
1409
|
+
CUSTOM_THEME_DIR,
|
|
1410
|
+
DEFAULT_THEME
|
|
1411
|
+
],
|
|
1412
|
+
'@/theme-default': DEFAULT_THEME,
|
|
1413
|
+
'@rspress/core': PACKAGE_ROOT,
|
|
1414
|
+
'react-lazy-with-preload': require.resolve('react-lazy-with-preload'),
|
|
1415
|
+
'react-syntax-highlighter': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(require.resolve('react-syntax-highlighter/package.json')),
|
|
1416
|
+
'@theme-assets': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(DEFAULT_THEME, '../assets')
|
|
1417
|
+
}
|
|
1418
|
+
},
|
|
1419
|
+
source: {
|
|
1420
|
+
include: [
|
|
1421
|
+
PACKAGE_ROOT,
|
|
1422
|
+
__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(cwd, 'node_modules', __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR)
|
|
1423
|
+
],
|
|
1858
1424
|
define: {
|
|
1859
|
-
|
|
1425
|
+
'process.env.__REACT_GTE_18__': JSON.stringify(reactVersion >= 18),
|
|
1426
|
+
'process.env.TEST': JSON.stringify(process.env.TEST),
|
|
1427
|
+
'process.env.RSPRESS_SOCIAL_ICONS': JSON.stringify(getSocialIcons(config.themeConfig.socialLinks))
|
|
1860
1428
|
}
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1429
|
+
},
|
|
1430
|
+
performance: {
|
|
1431
|
+
chunkSplit: {
|
|
1432
|
+
override: {
|
|
1433
|
+
cacheGroups: {
|
|
1434
|
+
styles: {
|
|
1435
|
+
name: 'styles',
|
|
1436
|
+
minSize: 0,
|
|
1437
|
+
chunks: 'all',
|
|
1438
|
+
test: /\.(?:css|less|sass|scss)$/,
|
|
1439
|
+
priority: 99
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
},
|
|
1445
|
+
tools: {
|
|
1446
|
+
bundlerChain (chain, { CHAIN_ID, target }) {
|
|
1447
|
+
var _config_markdown;
|
|
1448
|
+
const isServer = 'node' === target;
|
|
1449
|
+
const jsModuleRule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
1450
|
+
const swcLoaderOptions = jsModuleRule.use(CHAIN_ID.USE.SWC).get('options');
|
|
1451
|
+
const checkDeadLinks = ((null == config ? void 0 : null === (_config_markdown = config.markdown) || void 0 === _config_markdown ? void 0 : _config_markdown.checkDeadLinks) && !isServer) ?? false;
|
|
1452
|
+
chain.module.rule('MDX').type("javascript/auto").test(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_REGEXP).resolve.merge({
|
|
1453
|
+
conditionNames: jsModuleRule.resolve.conditionNames.values(),
|
|
1454
|
+
mainFields: jsModuleRule.resolve.mainFields.values()
|
|
1455
|
+
}).end().oneOf('MDXCompile').use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(require.resolve('./loader.js')).options({
|
|
1456
|
+
config,
|
|
1457
|
+
docDirectory: userDocRoot,
|
|
1458
|
+
checkDeadLinks,
|
|
1459
|
+
routeService,
|
|
1460
|
+
pluginDriver
|
|
1461
|
+
}).end();
|
|
1462
|
+
if (chain.plugins.has(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH)) chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).tap((options)=>{
|
|
1463
|
+
options[0] ??= {};
|
|
1464
|
+
options[0].include = [
|
|
1465
|
+
/\.([cm]js|[jt]sx?|flow)$/i,
|
|
1466
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_REGEXP
|
|
1467
|
+
];
|
|
1468
|
+
return options;
|
|
1469
|
+
});
|
|
1470
|
+
chain.resolve.extensions.prepend('.md').prepend('.mdx').prepend('.mjs');
|
|
1471
|
+
chain.module.rule('css-virtual-module').test(/\.rspress[\\/]runtime[\\/]virtual-global-styles/).merge({
|
|
1472
|
+
sideEffects: true
|
|
1473
|
+
});
|
|
1474
|
+
if (isServer) chain.output.filename('main.cjs');
|
|
1475
|
+
const enableIncremental = !isProduction() && !process.env.DISABLE_RSPACK_INCREMENTAL;
|
|
1476
|
+
if (enableIncremental) chain.merge({
|
|
1477
|
+
experiments: {
|
|
1478
|
+
incremental: true
|
|
1479
|
+
}
|
|
1480
|
+
});
|
|
1481
|
+
}
|
|
1482
|
+
},
|
|
1483
|
+
environments: {
|
|
1484
|
+
web: {
|
|
1485
|
+
resolve: {
|
|
1486
|
+
alias: {
|
|
1487
|
+
...reactCSRAlias,
|
|
1488
|
+
__VIRTUAL_ROUTES__: 'virtual-routes'
|
|
1489
|
+
}
|
|
1490
|
+
},
|
|
1491
|
+
source: {
|
|
1492
|
+
entry: {
|
|
1493
|
+
index: CLIENT_ENTRY
|
|
1494
|
+
},
|
|
1495
|
+
define: {
|
|
1496
|
+
'process.env.__SSR__': JSON.stringify(false)
|
|
1497
|
+
}
|
|
1498
|
+
},
|
|
1499
|
+
output: {
|
|
1500
|
+
target: 'web',
|
|
1501
|
+
distPath: {
|
|
1502
|
+
root: csrOutDir
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1870
1505
|
},
|
|
1871
|
-
|
|
1872
|
-
|
|
1506
|
+
...enableSSG ? {
|
|
1507
|
+
node: {
|
|
1508
|
+
resolve: {
|
|
1509
|
+
alias: {
|
|
1510
|
+
...reactSSRAlias,
|
|
1511
|
+
__VIRTUAL_ROUTES__: 'virtual-routes-ssr'
|
|
1512
|
+
}
|
|
1513
|
+
},
|
|
1514
|
+
source: {
|
|
1515
|
+
entry: {
|
|
1516
|
+
index: SSR_ENTRY
|
|
1517
|
+
},
|
|
1518
|
+
define: {
|
|
1519
|
+
'process.env.__SSR__': JSON.stringify(true)
|
|
1520
|
+
}
|
|
1521
|
+
},
|
|
1522
|
+
performance: {
|
|
1523
|
+
printFileSize: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isDebugMode)()
|
|
1524
|
+
},
|
|
1525
|
+
output: {
|
|
1526
|
+
emitAssets: false,
|
|
1527
|
+
target: 'node',
|
|
1528
|
+
distPath: {
|
|
1529
|
+
root: ssrOutDir
|
|
1530
|
+
},
|
|
1531
|
+
minify: false
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
} : {}
|
|
1873
1535
|
}
|
|
1874
|
-
|
|
1875
|
-
}
|
|
1876
|
-
};
|
|
1536
|
+
};
|
|
1877
1537
|
}
|
|
1878
1538
|
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("/");
|
|
1539
|
+
var _pluginDriver_getPlugins;
|
|
1540
|
+
const cwd = process.cwd();
|
|
1541
|
+
const userDocRoot = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(rootDir || (null == config ? void 0 : config.root) || cwd);
|
|
1542
|
+
const builderPlugins = (null == config ? void 0 : config.builderPlugins) ?? [];
|
|
1543
|
+
const runtimeTempDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR, 'runtime');
|
|
1544
|
+
const runtimeAbsTempDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(cwd, 'node_modules', runtimeTempDir);
|
|
1545
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(runtimeAbsTempDir, {
|
|
1546
|
+
recursive: true
|
|
1547
|
+
});
|
|
1548
|
+
const routeService = await initRouteService({
|
|
1549
|
+
config,
|
|
1550
|
+
runtimeTempDir: runtimeAbsTempDir,
|
|
1551
|
+
scanDir: userDocRoot,
|
|
1552
|
+
pluginDriver
|
|
1553
|
+
});
|
|
1554
|
+
const { createRsbuild, mergeRsbuildConfig } = await import("@rsbuild/core");
|
|
1555
|
+
const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver, runtimeTempDir);
|
|
1556
|
+
const rsbuild = await createRsbuild({
|
|
1557
|
+
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 || {})
|
|
1558
|
+
});
|
|
1559
|
+
rsbuild.addPlugins(builderPlugins);
|
|
1560
|
+
return rsbuild;
|
|
1561
|
+
}
|
|
1562
|
+
function checkLanguageParity_normalizePath(filePath) {
|
|
1563
|
+
return filePath.split(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].sep).join('/');
|
|
1918
1564
|
}
|
|
1919
1565
|
async function getAllMarkdownFilesFrom(dirPath) {
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
const
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1566
|
+
const files = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readdir(dirPath, {
|
|
1567
|
+
withFileTypes: true
|
|
1568
|
+
});
|
|
1569
|
+
const allFiles = [];
|
|
1570
|
+
for (const file of files){
|
|
1571
|
+
const fullPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(dirPath, file.name);
|
|
1572
|
+
if (file.isDirectory()) {
|
|
1573
|
+
const nestedFiles = await getAllMarkdownFilesFrom(fullPath);
|
|
1574
|
+
allFiles.push(...nestedFiles);
|
|
1575
|
+
} else if ([
|
|
1576
|
+
'.md',
|
|
1577
|
+
'.mdx'
|
|
1578
|
+
].includes(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(file.name))) allFiles.push(fullPath);
|
|
1929
1579
|
}
|
|
1930
|
-
|
|
1931
|
-
return allFiles;
|
|
1580
|
+
return allFiles;
|
|
1932
1581
|
}
|
|
1933
1582
|
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
|
-
|
|
1583
|
+
const langDirPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(contentPath, lang);
|
|
1584
|
+
const langModuleDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(langDirPath, includedDir);
|
|
1585
|
+
try {
|
|
1586
|
+
const moduleDirStats = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].stat(langModuleDir);
|
|
1587
|
+
if (!moduleDirStats.isDirectory()) return fileLangMap;
|
|
1588
|
+
const files = await getAllMarkdownFilesFrom(langModuleDir);
|
|
1589
|
+
for (const file of files){
|
|
1590
|
+
const relativePath = checkLanguageParity_normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(langDirPath, file));
|
|
1591
|
+
if (excludedDirs.some((excludedDir)=>{
|
|
1592
|
+
const isFilePath = /\.(md|mdx)$/.test(excludedDir);
|
|
1593
|
+
return relativePath.includes(excludedDir + (isFilePath ? '' : '/'));
|
|
1594
|
+
})) continue;
|
|
1595
|
+
const baseName = relativePath;
|
|
1596
|
+
if (!fileLangMap[baseName]) fileLangMap[baseName] = new Set();
|
|
1597
|
+
fileLangMap[baseName].add(lang);
|
|
1598
|
+
}
|
|
1599
|
+
} catch (e) {
|
|
1600
|
+
throw new Error(`Failed to access directory: ${checkLanguageParity_normalizePath(langModuleDir)}`);
|
|
1952
1601
|
}
|
|
1953
|
-
|
|
1954
|
-
throw new Error(
|
|
1955
|
-
`Failed to access directory: ${normalizePath2(langModuleDir)}`
|
|
1956
|
-
);
|
|
1957
|
-
}
|
|
1958
|
-
return fileLangMap;
|
|
1602
|
+
return fileLangMap;
|
|
1959
1603
|
}
|
|
1960
1604
|
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
|
-
}
|
|
1605
|
+
var _config_languageParity_include, _this, _config_themeConfig;
|
|
1606
|
+
if (!(null == config ? void 0 : config.languageParity) || false === config.languageParity.enabled) return;
|
|
1607
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Checking language parity...');
|
|
1608
|
+
const contentPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(config.root);
|
|
1609
|
+
const includedDirs = (null === (_config_languageParity_include = config.languageParity.include) || void 0 === _config_languageParity_include ? void 0 : _config_languageParity_include.length) ? config.languageParity.include : [
|
|
1610
|
+
''
|
|
1611
|
+
];
|
|
1612
|
+
const excludedDirs = config.languageParity.exclude ?? [];
|
|
1613
|
+
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)) || [];
|
|
1614
|
+
if (!supportedLanguages.length) {
|
|
1615
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error('No supported languages found in the configuration.');
|
|
1616
|
+
return;
|
|
1999
1617
|
}
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
1618
|
+
const missingLanguagesFile = [];
|
|
1619
|
+
try {
|
|
1620
|
+
for (const includedDir of includedDirs){
|
|
1621
|
+
if (excludedDirs.some((excludedDir)=>excludedDir === includedDir)) continue;
|
|
1622
|
+
const curFileLangMap = {};
|
|
1623
|
+
for (const lang of supportedLanguages)await collectModuleFiles(contentPath, lang, includedDir, excludedDirs, curFileLangMap);
|
|
1624
|
+
for (const [baseName, langs] of Object.entries(curFileLangMap)){
|
|
1625
|
+
const missingLangs = supportedLanguages.filter((lang)=>!langs.has(lang));
|
|
1626
|
+
missingLangs.forEach((lang)=>{
|
|
1627
|
+
const missingPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(lang, baseName);
|
|
1628
|
+
missingLanguagesFile.push(missingPath);
|
|
1629
|
+
});
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
if (missingLanguagesFile.length > 0) throw new Error(`Check language parity failed! Missing content:\n${missingLanguagesFile.map((file)=>` - ${checkLanguageParity_normalizePath(file)}`).join('\n')}`);
|
|
1633
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.success('Language parity checked successfully.');
|
|
1634
|
+
} catch (err) {
|
|
1635
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Error during language parity check: ${err.message}`);
|
|
1636
|
+
throw err;
|
|
2005
1637
|
}
|
|
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
|
|
1638
|
+
}
|
|
2014
1639
|
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";
|
|
1640
|
+
const { docDirectory, config, extraBuilderConfig } = options;
|
|
1641
|
+
const isProd = false;
|
|
1642
|
+
const pluginDriver = new PluginDriver(config, isProd);
|
|
1643
|
+
await pluginDriver.init();
|
|
1644
|
+
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1645
|
+
try {
|
|
1646
|
+
await pluginDriver.beforeBuild();
|
|
1647
|
+
const builder = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, false, extraBuilderConfig);
|
|
1648
|
+
builder.onDevCompileDone(async ()=>{
|
|
1649
|
+
await pluginDriver.afterBuild();
|
|
1650
|
+
});
|
|
1651
|
+
const { server } = await builder.startDevServer({
|
|
1652
|
+
getPortSilently: true
|
|
1653
|
+
});
|
|
1654
|
+
return server;
|
|
1655
|
+
} finally{
|
|
1656
|
+
await writeSearchIndex(modifiedConfig);
|
|
1657
|
+
await checkLanguageParity(modifiedConfig);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
2058
1660
|
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("");
|
|
1661
|
+
if (!isRouteMeta(route)) return '';
|
|
1662
|
+
const content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, {
|
|
1663
|
+
encoding: 'utf-8'
|
|
1664
|
+
});
|
|
1665
|
+
const { frontmatter: { head } } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.loadFrontMatter)(content, route.absolutePath, '', true);
|
|
1666
|
+
if (!head || 0 === head.length) return '';
|
|
1667
|
+
return head.map(([tag, attrs])=>`<${tag} ${renderAttrs(attrs)}>`).join('');
|
|
2070
1668
|
}
|
|
2071
1669
|
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("");
|
|
1670
|
+
if (!isRouteMeta(route)) return '';
|
|
1671
|
+
if (!config.head || 0 === config.head.length) return '';
|
|
1672
|
+
return config.head.map((head)=>{
|
|
1673
|
+
if ('string' == typeof head) return head;
|
|
1674
|
+
if ('function' == typeof head) {
|
|
1675
|
+
const resultHead = head(route);
|
|
1676
|
+
if (!resultHead) return '';
|
|
1677
|
+
if ('string' == typeof resultHead) return resultHead;
|
|
1678
|
+
return `<${resultHead[0]} ${renderAttrs(resultHead[1])}>`;
|
|
1679
|
+
}
|
|
1680
|
+
return `<${head[0]} ${renderAttrs(head[1])}>`;
|
|
1681
|
+
}).join('');
|
|
2089
1682
|
}
|
|
2090
1683
|
function renderAttrs(attrs) {
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
throw new Error(
|
|
2097
|
-
`Invalid value for attribute ${key}:${JSON.stringify(value)}`
|
|
2098
|
-
);
|
|
2099
|
-
}).join("");
|
|
1684
|
+
return Object.entries(attrs).map(([key, value])=>{
|
|
1685
|
+
if ('boolean' == typeof value) return key;
|
|
1686
|
+
if ('string' == typeof value || 'number' == typeof value) return `${key}="${value}"`;
|
|
1687
|
+
throw new Error(`Invalid value for attribute ${key}:${JSON.stringify(value)}`);
|
|
1688
|
+
}).join('');
|
|
2100
1689
|
}
|
|
2101
1690
|
function isRouteMeta(route) {
|
|
2102
|
-
|
|
1691
|
+
return 'routePath' in route && 'absolutePath' in route;
|
|
2103
1692
|
}
|
|
2104
|
-
|
|
2105
|
-
// src/node/build.ts
|
|
2106
1693
|
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 });
|
|
1694
|
+
try {
|
|
1695
|
+
const rsbuild = await initRsbuild(docDirectory, config, pluginDriver, enableSSG);
|
|
1696
|
+
await rsbuild.build();
|
|
1697
|
+
} finally{
|
|
1698
|
+
await writeSearchIndex(config);
|
|
1699
|
+
await checkLanguageParity(config);
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
function emptyDir(path) {
|
|
1703
|
+
return __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].rm(path, {
|
|
1704
|
+
force: true,
|
|
1705
|
+
recursive: true
|
|
1706
|
+
});
|
|
2122
1707
|
}
|
|
2123
1708
|
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;
|
|
1709
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Rendering pages...');
|
|
1710
|
+
const startTime = Date.now();
|
|
1711
|
+
const outputPath = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(appDirectory, OUTPUT_DIR);
|
|
1712
|
+
const ssrBundlePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'ssr', 'main.cjs');
|
|
1713
|
+
try {
|
|
1714
|
+
const { version } = await __webpack_require__.e("193").then(__webpack_require__.t.bind(__webpack_require__, "./package.json", 19));
|
|
1715
|
+
let render = null;
|
|
1716
|
+
if (ssgConfig) try {
|
|
1717
|
+
const { default: ssrExports } = await import((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(ssrBundlePath).toString());
|
|
1718
|
+
({ render } = ssrExports);
|
|
1719
|
+
} catch (e) {
|
|
1720
|
+
if ('object' == typeof ssgConfig && ssgConfig.strict) {
|
|
1721
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}.`);
|
|
1722
|
+
throw e;
|
|
2182
1723
|
}
|
|
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
|
-
);
|
|
1724
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(e);
|
|
1725
|
+
__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
1726
|
}
|
|
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
|
|
1727
|
+
const routes = init_routeService.getRoutes();
|
|
1728
|
+
const base = (null == config ? void 0 : config.base) ?? '';
|
|
1729
|
+
const htmlTemplatePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'index.html');
|
|
1730
|
+
const htmlTemplate = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(htmlTemplatePath, 'utf-8');
|
|
1731
|
+
const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route)=>({
|
|
1732
|
+
routePath: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(route.path, base)
|
|
1733
|
+
}));
|
|
1734
|
+
const allRoutes = [
|
|
1735
|
+
...routes,
|
|
1736
|
+
...additionalRoutes
|
|
1737
|
+
];
|
|
1738
|
+
const is404RouteInRoutes = allRoutes.some((route)=>'/404' === route.routePath);
|
|
1739
|
+
if (!is404RouteInRoutes) allRoutes.push({
|
|
1740
|
+
routePath: '/404'
|
|
2226
1741
|
});
|
|
2227
|
-
await
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
1742
|
+
await Promise.all(allRoutes.filter((route)=>!route.routePath.includes(':')).map(async (route)=>{
|
|
1743
|
+
var _helmet_title, _helmet_meta, _helmet_link, _helmet_style, _helmet_script;
|
|
1744
|
+
const helmetContext = {
|
|
1745
|
+
context: {}
|
|
1746
|
+
};
|
|
1747
|
+
const { routePath } = route;
|
|
1748
|
+
let appHtml = '';
|
|
1749
|
+
if (render) try {
|
|
1750
|
+
({ appHtml } = await render(routePath, helmetContext.context));
|
|
1751
|
+
} catch (e) {
|
|
1752
|
+
if ('object' == typeof ssgConfig && ssgConfig.strict) {
|
|
1753
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering failed.`);
|
|
1754
|
+
throw e;
|
|
1755
|
+
}
|
|
1756
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering error: ${e.message}, fallback to CSR.`);
|
|
1757
|
+
}
|
|
1758
|
+
const { helmet } = helmetContext.context;
|
|
1759
|
+
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, [
|
|
1760
|
+
await renderConfigHead(config, route),
|
|
1761
|
+
null == helmet ? void 0 : null === (_helmet_title = helmet.title) || void 0 === _helmet_title ? void 0 : _helmet_title.toString(),
|
|
1762
|
+
null == helmet ? void 0 : null === (_helmet_meta = helmet.meta) || void 0 === _helmet_meta ? void 0 : _helmet_meta.toString(),
|
|
1763
|
+
null == helmet ? void 0 : null === (_helmet_link = helmet.link) || void 0 === _helmet_link ? void 0 : _helmet_link.toString(),
|
|
1764
|
+
null == helmet ? void 0 : null === (_helmet_style = helmet.style) || void 0 === _helmet_style ? void 0 : _helmet_style.toString(),
|
|
1765
|
+
null == helmet ? void 0 : null === (_helmet_script = helmet.script) || void 0 === _helmet_script ? void 0 : _helmet_script.toString(),
|
|
1766
|
+
await renderFrontmatterHead(route)
|
|
1767
|
+
].join(''));
|
|
1768
|
+
if (null == helmet ? void 0 : helmet.htmlAttributes) {
|
|
1769
|
+
var _helmet_htmlAttributes;
|
|
1770
|
+
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()}`);
|
|
1771
|
+
}
|
|
1772
|
+
if (null == helmet ? void 0 : helmet.bodyAttributes) {
|
|
1773
|
+
var _helmet_bodyAttributes;
|
|
1774
|
+
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()}`);
|
|
1775
|
+
}
|
|
1776
|
+
const normalizeHtmlFilePath = (path)=>{
|
|
1777
|
+
const normalizedBase = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeSlash)((null == config ? void 0 : config.base) || '/');
|
|
1778
|
+
if (path.endsWith('/')) return `${path}index.html`.replace(normalizedBase, '');
|
|
1779
|
+
return `${path}.html`.replace(normalizedBase, '');
|
|
1780
|
+
};
|
|
1781
|
+
const fileName = normalizeHtmlFilePath(routePath);
|
|
1782
|
+
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)), {
|
|
1783
|
+
recursive: true
|
|
1784
|
+
});
|
|
1785
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, fileName), html);
|
|
1786
|
+
}));
|
|
1787
|
+
if (!(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isDebugMode)()) await emptyDir((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'ssr'));
|
|
1788
|
+
await emptyDir((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'html'));
|
|
1789
|
+
const totalTime = Date.now() - startTime;
|
|
1790
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.success(`Pages rendered in ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(totalTime)} ms.`);
|
|
1791
|
+
} catch (e) {
|
|
1792
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Pages render error: ${e.stack}`);
|
|
1793
|
+
throw e;
|
|
2232
1794
|
}
|
|
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
1795
|
}
|
|
2241
1796
|
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";
|
|
1797
|
+
const { docDirectory, appDirectory, config } = options;
|
|
1798
|
+
const pluginDriver = new PluginDriver(config, true);
|
|
1799
|
+
await pluginDriver.init();
|
|
1800
|
+
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1801
|
+
await pluginDriver.beforeBuild();
|
|
1802
|
+
const ssgConfig = modifiedConfig.ssg ?? true;
|
|
1803
|
+
await emptyDir(TEMP_DIR);
|
|
1804
|
+
await bundle(docDirectory, modifiedConfig, pluginDriver, Boolean(ssgConfig));
|
|
1805
|
+
await renderPages(appDirectory, modifiedConfig, pluginDriver, ssgConfig);
|
|
1806
|
+
await pluginDriver.afterBuild();
|
|
1807
|
+
}
|
|
2256
1808
|
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
|
|
1809
|
+
var _builderConfig_server, _builderConfig_server1;
|
|
1810
|
+
const { config, port: userPort, host: userHost } = options;
|
|
1811
|
+
const envPort = process.env.PORT;
|
|
1812
|
+
const envHost = process.env.HOST;
|
|
1813
|
+
const { builderConfig } = config;
|
|
1814
|
+
const port = Number(envPort || userPort || (null == builderConfig ? void 0 : null === (_builderConfig_server = builderConfig.server) || void 0 === _builderConfig_server ? void 0 : _builderConfig_server.port) || 4173);
|
|
1815
|
+
const host = envHost || userHost || (null == builderConfig ? void 0 : null === (_builderConfig_server1 = builderConfig.server) || void 0 === _builderConfig_server1 ? void 0 : _builderConfig_server1.host) || 'localhost';
|
|
1816
|
+
config.builderConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(builderConfig, {
|
|
1817
|
+
server: {
|
|
1818
|
+
port,
|
|
1819
|
+
host
|
|
1820
|
+
}
|
|
1821
|
+
});
|
|
1822
|
+
const pluginDriver = new PluginDriver(config, true);
|
|
1823
|
+
await pluginDriver.init();
|
|
1824
|
+
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1825
|
+
const builder = await initRsbuild(config.root, modifiedConfig, pluginDriver, false);
|
|
1826
|
+
await builder.preview();
|
|
1827
|
+
}
|
|
1828
|
+
var __webpack_exports__mergeDocConfig = __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.mergeDocConfig;
|
|
1829
|
+
export { build, dev, serve, __webpack_exports__mergeDocConfig as mergeDocConfig };
|