@rspress/core 1.41.0 → 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 -2175
- package/dist/loader.d.ts +78 -70
- package/dist/loader.js +550 -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 +16 -18
- 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/loader.cjs +0 -8
package/dist/index.js
CHANGED
|
@@ -1,2302 +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
|
-
test: "vitest run --passWithNoTests"
|
|
122
|
-
},
|
|
123
|
-
dependencies: {
|
|
124
|
-
"@mdx-js/loader": "2.3.0",
|
|
125
|
-
"@mdx-js/mdx": "2.3.0",
|
|
126
|
-
"@mdx-js/react": "2.3.0",
|
|
127
|
-
"@rsbuild/core": "1.2.3",
|
|
128
|
-
"@rsbuild/plugin-less": "~1.1.0",
|
|
129
|
-
"@rsbuild/plugin-react": "~1.1.0",
|
|
130
|
-
"@rsbuild/plugin-sass": "~1.2.0",
|
|
131
|
-
"@rspress/mdx-rs": "0.6.6",
|
|
132
|
-
"@rspress/plugin-auto-nav-sidebar": "workspace:*",
|
|
133
|
-
"@rspress/plugin-container-syntax": "workspace:*",
|
|
134
|
-
"@rspress/plugin-last-updated": "workspace:*",
|
|
135
|
-
"@rspress/plugin-medium-zoom": "workspace:*",
|
|
136
|
-
"@rspress/runtime": "workspace:*",
|
|
137
|
-
"@rspress/shared": "workspace:*",
|
|
138
|
-
"@rspress/theme-default": "workspace:*",
|
|
139
|
-
"enhanced-resolve": "5.18.0",
|
|
140
|
-
"github-slugger": "^2.0.0",
|
|
141
|
-
"hast-util-from-html": "^2.0.3",
|
|
142
|
-
"hast-util-heading-rank": "^3.0.0",
|
|
143
|
-
"html-to-text": "^9.0.5",
|
|
144
|
-
htmr: "^1.0.2",
|
|
145
|
-
"lodash-es": "^4.17.21",
|
|
146
|
-
"mdast-util-mdxjs-esm": "^1.3.1",
|
|
147
|
-
memfs: "^4.17.0",
|
|
148
|
-
react: "^18.3.1",
|
|
149
|
-
"react-dom": "^18.3.1",
|
|
150
|
-
"react-helmet-async": "^1.3.0",
|
|
151
|
-
"react-lazy-with-preload": "^2.2.1",
|
|
152
|
-
"react-syntax-highlighter": "^15.6.1",
|
|
153
|
-
"rehype-external-links": "^3.0.0",
|
|
154
|
-
remark: "^14.0.3",
|
|
155
|
-
"remark-gfm": "3.0.1",
|
|
156
|
-
"rspack-plugin-virtual-module": "0.1.13",
|
|
157
|
-
tinyglobby: "^0.2.10",
|
|
158
|
-
unified: "^10.1.2",
|
|
159
|
-
"unist-util-visit": "^4.1.2",
|
|
160
|
-
"unist-util-visit-children": "^3.0.0"
|
|
161
|
-
},
|
|
162
|
-
devDependencies: {
|
|
163
|
-
"@modern-js/plugin-tailwindcss": "2.64.0",
|
|
164
|
-
"@modern-js/tsconfig": "2.64.0",
|
|
165
|
-
"@types/hast": "3.0.4",
|
|
166
|
-
"@types/html-to-text": "^9.0.4",
|
|
167
|
-
"@types/jest": "~29.5.14",
|
|
168
|
-
"@types/lodash-es": "^4.17.12",
|
|
169
|
-
"@types/mdast": "^3.0.15",
|
|
170
|
-
"@types/node": "^18.11.17",
|
|
171
|
-
"@types/react": "^18.3.18",
|
|
172
|
-
"@types/react-dom": "^18.3.5",
|
|
173
|
-
postcss: "8.5.1",
|
|
174
|
-
"rehype-stringify": "^9.0.4",
|
|
175
|
-
"remark-parse": "^10.0.2",
|
|
176
|
-
"remark-rehype": "^10.1.0",
|
|
177
|
-
rimraf: "^3.0.2",
|
|
178
|
-
tailwindcss: "^3.4.17",
|
|
179
|
-
typescript: "^5.5.3",
|
|
180
|
-
vitest: "2.1.9"
|
|
181
|
-
},
|
|
182
|
-
engines: {
|
|
183
|
-
node: ">=14.17.6"
|
|
184
|
-
},
|
|
185
|
-
publishConfig: {
|
|
186
|
-
access: "public",
|
|
187
|
-
provenance: true,
|
|
188
|
-
registry: "https://registry.npmjs.org/"
|
|
189
|
-
},
|
|
190
|
-
"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;
|
|
191
75
|
};
|
|
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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
+
}
|
|
219
214
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
typeof mediumZoomConfig === "object" ? mediumZoomConfig : void 0
|
|
225
|
-
)
|
|
226
|
-
);
|
|
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);
|
|
227
219
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const SourceBuildPlugin = await import(
|
|
231
|
-
// @ts-expect-error need moduleResolution: Node16, NodeNext or Bundler to get type declarations work
|
|
232
|
-
"@rspress/theme-default/node/source-build-plugin.js"
|
|
233
|
-
).then(
|
|
234
|
-
(r) => r.SourceBuildPlugin,
|
|
235
|
-
() => null
|
|
236
|
-
);
|
|
237
|
-
if (SourceBuildPlugin) {
|
|
238
|
-
this.addPlugin(SourceBuildPlugin());
|
|
239
|
-
}
|
|
220
|
+
getPlugins() {
|
|
221
|
+
return _class_private_field_get(this, _plugins);
|
|
240
222
|
}
|
|
241
|
-
(
|
|
242
|
-
|
|
243
|
-
});
|
|
244
|
-
if (!haveNavSidebarConfig) {
|
|
245
|
-
const { pluginAutoNavSidebar } = await import("@rspress/plugin-auto-nav-sidebar");
|
|
246
|
-
this.addPlugin(pluginAutoNavSidebar());
|
|
223
|
+
clearPlugins() {
|
|
224
|
+
_class_private_field_set(this, _plugins, []);
|
|
247
225
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
(item) => item.name === plugin.name
|
|
252
|
-
);
|
|
253
|
-
if (existedIndex !== -1) {
|
|
254
|
-
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);
|
|
255
229
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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)));
|
|
268
285
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (typeof plugin.config === "function") {
|
|
275
|
-
config = await plugin.config(
|
|
276
|
-
config || {},
|
|
277
|
-
{
|
|
278
|
-
addPlugin: this.addPlugin.bind(this),
|
|
279
|
-
removePlugin: (pluginName) => {
|
|
280
|
-
const index = __privateGet(this, _plugins).findIndex(
|
|
281
|
-
(item) => item.name === pluginName
|
|
282
|
-
);
|
|
283
|
-
this.removePlugin(pluginName);
|
|
284
|
-
if (index <= i && index > 0) {
|
|
285
|
-
i--;
|
|
286
|
-
}
|
|
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);
|
|
287
291
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
+
return prev;
|
|
293
|
+
}, Promise.resolve());
|
|
292
294
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
async extendPageData(pageData) {
|
|
318
|
-
return this._runParallelAsyncHook("extendPageData", pageData, __privateGet(this, _isProd));
|
|
319
|
-
}
|
|
320
|
-
async addPages() {
|
|
321
|
-
const result = await this._runParallelAsyncHook(
|
|
322
|
-
"addPages",
|
|
323
|
-
__privateGet(this, _config) || {},
|
|
324
|
-
__privateGet(this, _isProd)
|
|
325
|
-
);
|
|
326
|
-
return result.flat();
|
|
327
|
-
}
|
|
328
|
-
async routeGenerated(routes) {
|
|
329
|
-
return this._runParallelAsyncHook("routeGenerated", routes);
|
|
330
|
-
}
|
|
331
|
-
async addRuntimeModules() {
|
|
332
|
-
const result = await this._runParallelAsyncHook(
|
|
333
|
-
"addRuntimeModules",
|
|
334
|
-
__privateGet(this, _config) || {},
|
|
335
|
-
__privateGet(this, _isProd)
|
|
336
|
-
);
|
|
337
|
-
return result.reduce((prev, current) => {
|
|
338
|
-
return {
|
|
339
|
-
...prev,
|
|
340
|
-
...current
|
|
341
|
-
};
|
|
342
|
-
}, {});
|
|
343
|
-
}
|
|
344
|
-
async addSSGRoutes() {
|
|
345
|
-
const result = await this._runParallelAsyncHook(
|
|
346
|
-
"addSSGRoutes",
|
|
347
|
-
__privateGet(this, _config) || {},
|
|
348
|
-
__privateGet(this, _isProd)
|
|
349
|
-
);
|
|
350
|
-
return result.flat();
|
|
351
|
-
}
|
|
352
|
-
globalUIComponents() {
|
|
353
|
-
const result = __privateGet(this, _plugins).map((plugin) => {
|
|
354
|
-
return plugin.globalUIComponents || [];
|
|
355
|
-
});
|
|
356
|
-
return result.flat();
|
|
357
|
-
}
|
|
358
|
-
globalStyles() {
|
|
359
|
-
return __privateGet(this, _plugins).filter((plugin) => typeof plugin.globalStyles === "string").map((plugin) => {
|
|
360
|
-
return plugin.globalStyles;
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
_runParallelAsyncHook(hookName, ...args) {
|
|
364
|
-
return Promise.all(
|
|
365
|
-
__privateGet(this, _plugins).filter((plugin) => typeof plugin[hookName] === "function").map((plugin) => {
|
|
366
|
-
return plugin[hookName](...args);
|
|
367
|
-
})
|
|
368
|
-
);
|
|
369
|
-
}
|
|
370
|
-
_runSerialAsyncHook(hookName, ...args) {
|
|
371
|
-
return __privateGet(this, _plugins).reduce(async (prev, plugin) => {
|
|
372
|
-
if (typeof plugin[hookName] === "function") {
|
|
373
|
-
await prev;
|
|
374
|
-
return plugin[hookName](...args);
|
|
375
|
-
}
|
|
376
|
-
return prev;
|
|
377
|
-
}, Promise.resolve());
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
_config = new WeakMap();
|
|
381
|
-
_plugins = new WeakMap();
|
|
382
|
-
_isProd = new WeakMap();
|
|
383
|
-
|
|
384
|
-
// src/node/initRsbuild.ts
|
|
385
|
-
import fs9 from "fs/promises";
|
|
386
|
-
import path11 from "path";
|
|
387
|
-
import { PLUGIN_LESS_NAME, pluginLess } from "@rsbuild/plugin-less";
|
|
388
|
-
import { PLUGIN_REACT_NAME, pluginReact } from "@rsbuild/plugin-react";
|
|
389
|
-
import { PLUGIN_SASS_NAME, pluginSass } from "@rsbuild/plugin-sass";
|
|
390
|
-
import {
|
|
391
|
-
MDX_REGEXP as MDX_REGEXP3,
|
|
392
|
-
RSPRESS_TEMP_DIR as RSPRESS_TEMP_DIR2,
|
|
393
|
-
isDebugMode,
|
|
394
|
-
removeLeadingSlash as removeLeadingSlash2,
|
|
395
|
-
removeTrailingSlash
|
|
396
|
-
} from "@rspress/shared";
|
|
397
|
-
|
|
398
|
-
// src/node/constants.ts
|
|
399
|
-
import path from "path";
|
|
400
|
-
import { fileURLToPath } from "url";
|
|
401
|
-
import { APPEARANCE_KEY, RSPRESS_TEMP_DIR } from "@rspress/shared";
|
|
402
|
-
var isProduction = () => process.env.NODE_ENV === "production";
|
|
403
|
-
var importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
404
|
-
var inlineThemeScript = `{
|
|
405
|
-
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}')
|
|
406
317
|
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
407
318
|
const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
|
|
408
319
|
document.documentElement.classList.toggle('dark', isDark)
|
|
409
320
|
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
410
|
-
}`.replace(/\n/g,
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
);
|
|
425
|
-
var OUTPUT_DIR = "doc_build";
|
|
426
|
-
var APP_HTML_MARKER = "<!--<?- DOC_CONTENT ?>-->";
|
|
427
|
-
var HEAD_MARKER = "<!--<?- HEAD ?>-->";
|
|
428
|
-
var META_GENERATOR = "<!--<?- GENERATOR ?>-->";
|
|
429
|
-
var HTML_START_TAG = "<html";
|
|
430
|
-
var BODY_START_TAG = "<body";
|
|
431
|
-
var DEFAULT_TITLE = "Rspress";
|
|
432
|
-
var PUBLIC_DIR = "public";
|
|
433
|
-
var TEMP_DIR = path.join(
|
|
434
|
-
process.cwd(),
|
|
435
|
-
"node_modules",
|
|
436
|
-
RSPRESS_TEMP_DIR
|
|
437
|
-
);
|
|
438
|
-
|
|
439
|
-
// src/node/route/RouteService.ts
|
|
440
|
-
import fs4 from "fs/promises";
|
|
441
|
-
import path5 from "path";
|
|
442
|
-
import {
|
|
443
|
-
addLeadingSlash,
|
|
444
|
-
addTrailingSlash,
|
|
445
|
-
withBase
|
|
446
|
-
} from "@rspress/shared";
|
|
447
|
-
import { glob } from "tinyglobby";
|
|
448
|
-
|
|
449
|
-
// src/node/utils/normalizePath.ts
|
|
450
|
-
import os from "os";
|
|
451
|
-
import path2 from "path";
|
|
452
|
-
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();
|
|
453
336
|
function slash(p) {
|
|
454
|
-
|
|
337
|
+
return p.replace(/\\/g, '/');
|
|
455
338
|
}
|
|
456
339
|
function normalizePath(id) {
|
|
457
|
-
|
|
340
|
+
return __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].posix.normalize(isWindows ? slash(id) : id);
|
|
458
341
|
}
|
|
459
|
-
|
|
460
|
-
// src/node/utils/getPageKey.ts
|
|
461
|
-
import { removeLeadingSlash } from "@rspress/shared";
|
|
462
342
|
function getPageKey(route) {
|
|
463
|
-
|
|
464
|
-
|
|
343
|
+
const cleanRoute = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeLeadingSlash)(route);
|
|
344
|
+
return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
|
|
465
345
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
import { createHash as createHashFunc } from "crypto";
|
|
469
|
-
function createHash(str) {
|
|
470
|
-
return createHashFunc("sha256").update(str).digest("hex").slice(0, 8);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// src/node/utils/detectReactVersion.ts
|
|
474
|
-
import fs2 from "fs";
|
|
475
|
-
import path3 from "path";
|
|
476
|
-
import { logger } from "@rspress/shared/logger";
|
|
477
|
-
import enhancedResolve from "enhanced-resolve";
|
|
478
|
-
|
|
479
|
-
// src/node/utils/fs.ts
|
|
480
|
-
import fs from "fs/promises";
|
|
481
|
-
async function pathExists(path13) {
|
|
482
|
-
try {
|
|
483
|
-
await fs.access(path13);
|
|
484
|
-
return true;
|
|
485
|
-
} catch {
|
|
486
|
-
return false;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
async function readJson(path13) {
|
|
490
|
-
const raw = await fs.readFile(path13, "utf8");
|
|
491
|
-
return JSON.parse(raw);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
// src/node/utils/detectReactVersion.ts
|
|
495
|
-
var { CachedInputFileSystem, ResolverFactory } = enhancedResolve;
|
|
496
|
-
var DEFAULT_REACT_VERSION = 18;
|
|
497
|
-
async function detectReactVersion() {
|
|
498
|
-
const cwd = process.cwd();
|
|
499
|
-
const reactPath = path3.join(cwd, "node_modules", "react");
|
|
500
|
-
if (await pathExists(reactPath)) {
|
|
501
|
-
const reactPkg = await readJson(
|
|
502
|
-
path3.join(reactPath, "package.json")
|
|
503
|
-
);
|
|
504
|
-
const version = Number(reactPkg.version?.split(".")[0]);
|
|
505
|
-
return version;
|
|
506
|
-
}
|
|
507
|
-
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");
|
|
508
348
|
}
|
|
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
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
async function resolveDepPath(importPath, importer, alias) {
|
|
565
|
-
if (!resolver) {
|
|
566
|
-
resolver = ResolverFactory2.createResolver({
|
|
567
|
-
fileSystem: new CachedInputFileSystem2(fs3, 0),
|
|
568
|
-
extensions: [".mdx", ".md"],
|
|
569
|
-
alias
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
const resolveResult = await new Promise((resolve, reject) => {
|
|
573
|
-
resolver.resolve(
|
|
574
|
-
{
|
|
575
|
-
importer
|
|
576
|
-
},
|
|
577
|
-
importer,
|
|
578
|
-
importPath,
|
|
579
|
-
{},
|
|
580
|
-
(err, filePath) => {
|
|
581
|
-
if (err) {
|
|
582
|
-
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();
|
|
583
404
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
)
|
|
589
|
-
|
|
405
|
+
}
|
|
406
|
+
if (lang) {
|
|
407
|
+
const langToMatch = parts[0];
|
|
408
|
+
if (langs.includes(langToMatch)) {
|
|
409
|
+
if (langToMatch !== lang) langPart = langToMatch;
|
|
410
|
+
parts.shift();
|
|
590
411
|
}
|
|
591
|
-
return resolve(filePath);
|
|
592
|
-
}
|
|
593
|
-
);
|
|
594
|
-
});
|
|
595
|
-
return resolveResult;
|
|
596
|
-
}
|
|
597
|
-
async function flattenMdxContent(content, basePath, alias) {
|
|
598
|
-
const deps = [];
|
|
599
|
-
const regex = new RegExp(importStatementRegex);
|
|
600
|
-
if (!regex.test(content)) {
|
|
601
|
-
return { flattenContent: content, deps };
|
|
602
|
-
}
|
|
603
|
-
if (!startFlatten) {
|
|
604
|
-
resolver = ResolverFactory2.createResolver({
|
|
605
|
-
fileSystem: new CachedInputFileSystem2(fs3, 0),
|
|
606
|
-
extensions: [".mdx", ".md", ".js"],
|
|
607
|
-
alias
|
|
608
|
-
});
|
|
609
|
-
startFlatten = true;
|
|
610
|
-
}
|
|
611
|
-
let ast;
|
|
612
|
-
let result = content;
|
|
613
|
-
try {
|
|
614
|
-
ast = processor.parse(content);
|
|
615
|
-
} catch (e) {
|
|
616
|
-
return { flattenContent: content, deps };
|
|
617
|
-
}
|
|
618
|
-
const importNodes = ast.children.filter((node) => node.type === "mdxjsEsm").flatMap((node) => node.data?.estree?.body || []).filter((node) => node.type === "ImportDeclaration");
|
|
619
|
-
for (const importNode of importNodes) {
|
|
620
|
-
const id = importNode.specifiers[0].local.name;
|
|
621
|
-
const importPath = importNode.source.value;
|
|
622
|
-
let absoluteImportPath;
|
|
623
|
-
try {
|
|
624
|
-
absoluteImportPath = await resolveDepPath(
|
|
625
|
-
importPath,
|
|
626
|
-
path4.dirname(basePath),
|
|
627
|
-
alias
|
|
628
|
-
);
|
|
629
|
-
} catch (e) {
|
|
630
|
-
continue;
|
|
631
412
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
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);
|
|
640
480
|
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
// src/node/utils/applyReplaceRules.ts
|
|
646
|
-
function applyReplaceRules(code = "", replaceRules = []) {
|
|
647
|
-
let result = code;
|
|
648
|
-
for (const rule of replaceRules) {
|
|
649
|
-
result = result.replace(rule.search, rule.replace);
|
|
650
|
-
}
|
|
651
|
-
return result;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
// src/node/route/RouteService.ts
|
|
655
|
-
var DEFAULT_PAGE_EXTENSIONS = ["js", "jsx", "ts", "tsx", "md", "mdx"];
|
|
656
|
-
var normalizeRoutePath = (routePath, base, lang, version, langs, versions, extensions = DEFAULT_PAGE_EXTENSIONS) => {
|
|
657
|
-
const hasTrailSlash = routePath.endsWith("/");
|
|
658
|
-
let versionPart = "";
|
|
659
|
-
let langPart = "";
|
|
660
|
-
let purePathPart = "";
|
|
661
|
-
const parts = routePath.split("/").filter(Boolean);
|
|
662
|
-
if (version) {
|
|
663
|
-
const versionToMatch = parts[0];
|
|
664
|
-
if (versions.includes(versionToMatch)) {
|
|
665
|
-
if (versionToMatch !== version) {
|
|
666
|
-
versionPart = versionToMatch;
|
|
667
|
-
}
|
|
668
|
-
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);
|
|
669
485
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
const langToMatch = parts[0];
|
|
673
|
-
if (langs.includes(langToMatch)) {
|
|
674
|
-
if (langToMatch !== lang) {
|
|
675
|
-
langPart = langToMatch;
|
|
676
|
-
}
|
|
677
|
-
parts.shift();
|
|
486
|
+
getRoutes() {
|
|
487
|
+
return Array.from(this.routeData.values());
|
|
678
488
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
[versionPart, langPart, purePathPart].filter(Boolean).join("/")
|
|
683
|
-
).replace(new RegExp(`\\.(${extensions.join("|")})$`), "").replace(/\.html$/, "").replace(/\/index$/, "/");
|
|
684
|
-
if (hasTrailSlash) {
|
|
685
|
-
normalizedRoutePath = addTrailingSlash(normalizedRoutePath);
|
|
686
|
-
}
|
|
687
|
-
return {
|
|
688
|
-
routePath: withBase(normalizedRoutePath, base),
|
|
689
|
-
lang: langPart || lang,
|
|
690
|
-
version: versionPart || version
|
|
691
|
-
};
|
|
692
|
-
};
|
|
693
|
-
var _scanDir, _defaultLang, _defaultVersion, _extensions, _langs, _versions, _include, _exclude, _base, _tempDir, _pluginDriver, _writeTempFile, writeTempFile_fn, _generateRouteInfo, generateRouteInfo_fn;
|
|
694
|
-
var RouteService = class {
|
|
695
|
-
constructor(scanDir, userConfig, tempDir, pluginDriver) {
|
|
696
|
-
__privateAdd(this, _writeTempFile);
|
|
697
|
-
__privateAdd(this, _generateRouteInfo);
|
|
698
|
-
__publicField(this, "routeData", /* @__PURE__ */ new Map());
|
|
699
|
-
__privateAdd(this, _scanDir, void 0);
|
|
700
|
-
__privateAdd(this, _defaultLang, void 0);
|
|
701
|
-
__privateAdd(this, _defaultVersion, "");
|
|
702
|
-
__privateAdd(this, _extensions, []);
|
|
703
|
-
__privateAdd(this, _langs, []);
|
|
704
|
-
__privateAdd(this, _versions, []);
|
|
705
|
-
__privateAdd(this, _include, []);
|
|
706
|
-
__privateAdd(this, _exclude, []);
|
|
707
|
-
__privateAdd(this, _base, "");
|
|
708
|
-
__privateAdd(this, _tempDir, "");
|
|
709
|
-
__privateAdd(this, _pluginDriver, void 0);
|
|
710
|
-
const routeOptions = userConfig?.route || {};
|
|
711
|
-
__privateSet(this, _scanDir, scanDir);
|
|
712
|
-
__privateSet(this, _extensions, routeOptions.extensions || DEFAULT_PAGE_EXTENSIONS);
|
|
713
|
-
__privateSet(this, _include, routeOptions.include || []);
|
|
714
|
-
__privateSet(this, _exclude, routeOptions.exclude || []);
|
|
715
|
-
__privateSet(this, _defaultLang, userConfig?.lang || "");
|
|
716
|
-
__privateSet(this, _langs, (userConfig?.locales ?? userConfig?.themeConfig?.locales ?? []).map((item) => item.lang));
|
|
717
|
-
__privateSet(this, _base, userConfig?.base || "");
|
|
718
|
-
__privateSet(this, _tempDir, tempDir);
|
|
719
|
-
__privateSet(this, _pluginDriver, pluginDriver);
|
|
720
|
-
if (userConfig.multiVersion) {
|
|
721
|
-
__privateSet(this, _defaultVersion, userConfig.multiVersion.default || "");
|
|
722
|
-
__privateSet(this, _versions, userConfig.multiVersion.versions || []);
|
|
489
|
+
isExistRoute(routePath) {
|
|
490
|
+
const { routePath: normalizedRoute } = this.normalizeRoutePath(routePath);
|
|
491
|
+
return this.routeData.get(normalizedRoute);
|
|
723
492
|
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
ignore: [
|
|
730
|
-
...__privateGet(this, _exclude),
|
|
731
|
-
"**/node_modules/**",
|
|
732
|
-
"**/.eslintrc.js",
|
|
733
|
-
"**/.nx-cache/**",
|
|
734
|
-
`./${PUBLIC_DIR}/**`
|
|
735
|
-
]
|
|
736
|
-
})).sort();
|
|
737
|
-
files.forEach((filePath) => {
|
|
738
|
-
const fileRelativePath = normalizePath(
|
|
739
|
-
path5.relative(__privateGet(this, _scanDir), filePath)
|
|
740
|
-
);
|
|
741
|
-
const { routePath, lang, version } = this.normalizeRoutePath(fileRelativePath);
|
|
742
|
-
const absolutePath = path5.join(__privateGet(this, _scanDir), fileRelativePath);
|
|
743
|
-
const routeInfo = {
|
|
744
|
-
routePath,
|
|
745
|
-
absolutePath: normalizePath(absolutePath),
|
|
746
|
-
relativePath: fileRelativePath,
|
|
747
|
-
pageName: getPageKey(fileRelativePath),
|
|
748
|
-
lang,
|
|
749
|
-
version
|
|
750
|
-
};
|
|
751
|
-
this.addRoute(routeInfo);
|
|
752
|
-
});
|
|
753
|
-
const externalPages = await __privateGet(this, _pluginDriver).addPages();
|
|
754
|
-
await Promise.all(
|
|
755
|
-
externalPages.map(async (route, index) => {
|
|
756
|
-
const { routePath, content, filepath } = route;
|
|
757
|
-
if (filepath) {
|
|
758
|
-
const routeInfo = __privateMethod(this, _generateRouteInfo, generateRouteInfo_fn).call(this, routePath, filepath);
|
|
759
|
-
this.addRoute(routeInfo);
|
|
760
|
-
return;
|
|
761
|
-
}
|
|
762
|
-
if (content) {
|
|
763
|
-
const filepath2 = await __privateMethod(this, _writeTempFile, writeTempFile_fn).call(this, index, content);
|
|
764
|
-
const routeInfo = __privateMethod(this, _generateRouteInfo, generateRouteInfo_fn).call(this, routePath, filepath2);
|
|
765
|
-
this.addRoute(routeInfo);
|
|
766
|
-
}
|
|
767
|
-
})
|
|
768
|
-
);
|
|
769
|
-
await __privateGet(this, _pluginDriver).routeGenerated(this.getRoutes());
|
|
770
|
-
}
|
|
771
|
-
addRoute(routeInfo) {
|
|
772
|
-
const { routePath, absolutePath } = routeInfo;
|
|
773
|
-
if (this.routeData.has(routePath)) {
|
|
774
|
-
const preRouteExtIndex = __privateGet(this, _extensions).indexOf(
|
|
775
|
-
path5.extname(this.routeData.get(routePath).absolutePath).slice(1)
|
|
776
|
-
);
|
|
777
|
-
const currRouteExtIndex = __privateGet(this, _extensions).indexOf(
|
|
778
|
-
path5.extname(absolutePath).slice(1)
|
|
779
|
-
);
|
|
780
|
-
if (currRouteExtIndex !== -1 && (currRouteExtIndex < preRouteExtIndex || preRouteExtIndex === -1)) {
|
|
781
|
-
this.routeData.set(routePath, routeInfo);
|
|
782
|
-
}
|
|
783
|
-
} else {
|
|
784
|
-
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);
|
|
785
498
|
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
const fileRelativePath = path5.relative(__privateGet(this, _scanDir), filePath);
|
|
789
|
-
const { routePath } = this.normalizeRoutePath(fileRelativePath);
|
|
790
|
-
this.routeData.delete(routePath);
|
|
791
|
-
}
|
|
792
|
-
getRoutes() {
|
|
793
|
-
return Array.from(this.routeData.values());
|
|
794
|
-
}
|
|
795
|
-
isExistRoute(routePath) {
|
|
796
|
-
const { routePath: normalizedRoute } = this.normalizeRoutePath(routePath);
|
|
797
|
-
return this.routeData.get(normalizedRoute);
|
|
798
|
-
}
|
|
799
|
-
isEmpty() {
|
|
800
|
-
return this.routeData.size === 0;
|
|
801
|
-
}
|
|
802
|
-
generateRoutesCode(isStaticImport = false) {
|
|
803
|
-
return this.generateRoutesCodeByRouteMeta(this.getRoutes(), isStaticImport);
|
|
804
|
-
}
|
|
805
|
-
generateRoutesCodeByRouteMeta(routeMeta, isStaticImport) {
|
|
806
|
-
return `
|
|
499
|
+
generateRoutesCodeByRouteMeta(routeMeta, isStaticImport) {
|
|
500
|
+
return `
|
|
807
501
|
import React from 'react';
|
|
808
502
|
import { lazyWithPreload } from "react-lazy-with-preload";
|
|
809
|
-
${routeMeta.map((route, index) => {
|
|
810
|
-
return isStaticImport ? `import * as Route${index} from '${route.absolutePath}';` : `const Route${index} = lazyWithPreload(() => import('${route.absolutePath}'))`;
|
|
811
|
-
}).join("\n")}
|
|
503
|
+
${routeMeta.map((route, index)=>isStaticImport ? `import * as Route${index} from '${route.absolutePath}';` : `const Route${index} = lazyWithPreload(() => import('${route.absolutePath}'))`).join('\n')}
|
|
812
504
|
export const routes = [
|
|
813
|
-
${routeMeta.map((route, index)
|
|
814
|
-
|
|
505
|
+
${routeMeta.map((route, index)=>{
|
|
506
|
+
const preload = isStaticImport ? `() => Route${index}` : `async () => {
|
|
815
507
|
await Route${index}.preload();
|
|
816
508
|
return import("${route.absolutePath}");
|
|
817
509
|
}`;
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
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')}
|
|
821
513
|
];
|
|
822
514
|
`;
|
|
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
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
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;
|
|
872
609
|
async function initRouteService(options) {
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
pluginDriver
|
|
879
|
-
);
|
|
880
|
-
await routeService.init();
|
|
881
|
-
return routeService;
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
// src/node/runtimeModule/index.ts
|
|
885
|
-
import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
|
|
886
|
-
|
|
887
|
-
// src/node/runtimeModule/globalStyles.ts
|
|
888
|
-
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
|
+
}
|
|
889
615
|
async function globalStylesVMPlugin(context) {
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
}
|
|
898
|
-
const moduleContent = (await Promise.all(
|
|
899
|
-
[config?.globalStyles || "", ...globalStylesByPlugins].filter((source) => source.length > 0).map(async (source) => {
|
|
900
|
-
return `import ${JSON.stringify(source)};`;
|
|
901
|
-
})
|
|
902
|
-
)).join("");
|
|
903
|
-
return {
|
|
904
|
-
["virtual-global-styles" /* GlobalStyles */]: moduleContent
|
|
905
|
-
};
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
// src/node/runtimeModule/globalUIComponents.ts
|
|
909
|
-
async function globalUIComponentsVMPlugin(context) {
|
|
910
|
-
const { config, pluginDriver } = context;
|
|
911
|
-
let index = 0;
|
|
912
|
-
const globalUIComponentsByPlugins = pluginDriver.globalUIComponents();
|
|
913
|
-
const globalComponents = [
|
|
914
|
-
...config?.globalUIComponents || [],
|
|
915
|
-
...globalUIComponentsByPlugins
|
|
916
|
-
];
|
|
917
|
-
const moduleContent = globalComponents.map((source) => {
|
|
918
|
-
const name = `Comp_${index}`;
|
|
919
|
-
if (Array.isArray(source)) {
|
|
920
|
-
return `import ${name} from ${JSON.stringify(source[0])};
|
|
921
|
-
const Props_${index++} = ${JSON.stringify(source[1])};
|
|
922
|
-
`;
|
|
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');
|
|
923
623
|
}
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
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');
|
|
943
657
|
function getI18nData(docConfig) {
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
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
|
+
}
|
|
952
666
|
}
|
|
953
667
|
function i18nVMPlugin(context) {
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
// 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
|
+
}
|
|
962
674
|
async function routeVMPlugin(context) {
|
|
963
|
-
|
|
964
|
-
|
|
675
|
+
const { routeService, isSSR } = context;
|
|
676
|
+
if (!isSSR) return {
|
|
677
|
+
[runtimeModule_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
|
|
678
|
+
[runtimeModule_RuntimeModuleID.RouteForSSR]: ''
|
|
679
|
+
};
|
|
965
680
|
return {
|
|
966
|
-
|
|
681
|
+
[runtimeModule_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
|
|
682
|
+
[runtimeModule_RuntimeModuleID.RouteForSSR]: routeService.generateRoutesCode(true)
|
|
967
683
|
};
|
|
968
|
-
|
|
969
|
-
return {
|
|
970
|
-
["virtual-routes" /* RouteForClient */]: routeService2.generateRoutesCode(false),
|
|
971
|
-
["virtual-routes-ssr" /* RouteForSSR */]: routeService2.generateRoutesCode(true)
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
// src/node/runtimeModule/searchHooks.ts
|
|
976
|
-
import path6 from "path";
|
|
684
|
+
}
|
|
977
685
|
async function searchHookVMPlugin(context) {
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
}
|
|
985
|
-
return {
|
|
986
|
-
[`${"virtual-search-hooks" /* SearchHooks */}${extname}`]: content
|
|
987
|
-
};
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
// src/node/runtimeModule/siteData/index.ts
|
|
991
|
-
import fs7 from "fs/promises";
|
|
992
|
-
import path8 from "path";
|
|
993
|
-
import { SEARCH_INDEX_NAME } from "@rspress/shared";
|
|
994
|
-
import { groupBy } from "lodash-es";
|
|
995
|
-
|
|
996
|
-
// src/node/runtimeModule/siteData/extractPageData.ts
|
|
997
|
-
import fs6 from "fs/promises";
|
|
998
|
-
import path7 from "path";
|
|
999
|
-
import { compile } from "@rspress/mdx-rs";
|
|
1000
|
-
import {
|
|
1001
|
-
MDX_REGEXP as MDX_REGEXP2
|
|
1002
|
-
} from "@rspress/shared";
|
|
1003
|
-
import { loadFrontMatter } from "@rspress/shared/node-utils";
|
|
1004
|
-
import { htmlToText } from "html-to-text";
|
|
1005
|
-
function applyReplaceRulesToNestedObject(obj, replaceRules) {
|
|
1006
|
-
for (const key in obj) {
|
|
1007
|
-
if (typeof obj[key] === "string") {
|
|
1008
|
-
obj[key] = applyReplaceRules(obj[key], replaceRules);
|
|
1009
|
-
} else if (typeof obj[key] === "object") {
|
|
1010
|
-
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);
|
|
1011
692
|
}
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
_filepath: route.absolutePath,
|
|
1030
|
-
_relativePath: path7.relative(root, route.absolutePath)
|
|
1031
|
-
};
|
|
1032
|
-
if (!MDX_REGEXP2.test(route.absolutePath)) {
|
|
1033
|
-
return defaultIndexInfo;
|
|
1034
|
-
}
|
|
1035
|
-
let content = await fs6.readFile(route.absolutePath, "utf8");
|
|
1036
|
-
const { frontmatter, content: strippedFrontMatter } = loadFrontMatter(
|
|
1037
|
-
content,
|
|
1038
|
-
route.absolutePath,
|
|
1039
|
-
root
|
|
1040
|
-
);
|
|
1041
|
-
applyReplaceRulesToNestedObject(frontmatter, replaceRules);
|
|
1042
|
-
const { flattenContent } = await flattenMdxContent(
|
|
1043
|
-
applyReplaceRules(strippedFrontMatter, replaceRules),
|
|
1044
|
-
route.absolutePath,
|
|
1045
|
-
alias
|
|
1046
|
-
);
|
|
1047
|
-
content = flattenContent.replace(importStatementRegex, "");
|
|
1048
|
-
const {
|
|
1049
|
-
html,
|
|
1050
|
-
title,
|
|
1051
|
-
toc: rawToc,
|
|
1052
|
-
languages
|
|
1053
|
-
} = await compile({
|
|
1054
|
-
value: content,
|
|
1055
|
-
filepath: route.absolutePath,
|
|
1056
|
-
development: process.env.NODE_ENV !== "production",
|
|
1057
|
-
root
|
|
1058
|
-
});
|
|
1059
|
-
if (!title?.length && !frontmatter && !frontmatter.title?.length) {
|
|
1060
|
-
return null;
|
|
1061
|
-
}
|
|
1062
|
-
content = htmlToText(String(html), {
|
|
1063
|
-
wordwrap: 80,
|
|
1064
|
-
selectors: [
|
|
1065
|
-
{
|
|
1066
|
-
selector: "a",
|
|
1067
|
-
options: {
|
|
1068
|
-
ignoreHref: true
|
|
1069
|
-
}
|
|
1070
|
-
},
|
|
1071
|
-
{
|
|
1072
|
-
selector: "img",
|
|
1073
|
-
format: "skip"
|
|
1074
|
-
},
|
|
1075
|
-
{
|
|
1076
|
-
// Skip code blocks
|
|
1077
|
-
selector: "pre > code",
|
|
1078
|
-
format: searchCodeBlocks ? "block" : "skip"
|
|
1079
|
-
},
|
|
1080
|
-
...["h1", "h2", "h3", "h4", "h5", "h6"].map((tag) => ({
|
|
1081
|
-
selector: tag,
|
|
1082
|
-
options: {
|
|
1083
|
-
uppercase: false
|
|
1084
|
-
}
|
|
1085
|
-
}))
|
|
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'
|
|
1086
710
|
],
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
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) {
|
|
1110
748
|
return {
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
${item.text}#
|
|
1114
|
-
|
|
1115
|
-
`, position + 1)
|
|
749
|
+
flattenContent: content,
|
|
750
|
+
deps
|
|
1116
751
|
};
|
|
1117
|
-
});
|
|
1118
|
-
return {
|
|
1119
|
-
...defaultIndexInfo,
|
|
1120
|
-
title: frontmatter.title || title,
|
|
1121
|
-
toc,
|
|
1122
|
-
// Stripped frontmatter content
|
|
1123
|
-
content,
|
|
1124
|
-
_html: html,
|
|
1125
|
-
frontmatter: {
|
|
1126
|
-
...frontmatter,
|
|
1127
|
-
__content: void 0
|
|
1128
|
-
}
|
|
1129
|
-
};
|
|
1130
|
-
})
|
|
1131
|
-
);
|
|
1132
|
-
return pageData.filter(Boolean);
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
// src/node/runtimeModule/siteData/highlightLanguages.ts
|
|
1136
|
-
import { DEFAULT_HIGHLIGHT_LANGUAGES } from "@rspress/shared";
|
|
1137
|
-
import chalk from "@rspress/shared/chalk";
|
|
1138
|
-
var supportedLanguages;
|
|
1139
|
-
function handleHighlightLanguages(highlightLanguages, defaultLanguages) {
|
|
1140
|
-
const aliases = {};
|
|
1141
|
-
if (highlightLanguages.size) {
|
|
1142
|
-
if (!supportedLanguages) {
|
|
1143
|
-
const langs = __require("react-syntax-highlighter/dist/cjs/languages/prism/supported-languages").default;
|
|
1144
|
-
supportedLanguages = new Set(langs);
|
|
1145
752
|
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
"
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
if (name && supportedLanguages.has(name)) {
|
|
1165
|
-
const temp = aliases[name] || (aliases[name] = []);
|
|
1166
|
-
if (!temp.includes(lang)) {
|
|
1167
|
-
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);
|
|
1168
771
|
}
|
|
1169
|
-
highlightLanguages.delete(lang);
|
|
1170
|
-
highlightLanguages.add(name);
|
|
1171
|
-
return;
|
|
1172
|
-
}
|
|
1173
|
-
if (!supportedLanguages.has(lang)) {
|
|
1174
|
-
highlightLanguages.delete(lang);
|
|
1175
|
-
}
|
|
1176
|
-
});
|
|
1177
|
-
}
|
|
1178
|
-
return aliases;
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
// src/node/runtimeModule/siteData/normalizeThemeConfig.ts
|
|
1182
|
-
import {
|
|
1183
|
-
addLeadingSlash as addLeadingSlash2,
|
|
1184
|
-
isExternalUrl,
|
|
1185
|
-
slash as slash2,
|
|
1186
|
-
withBase as withBase2,
|
|
1187
|
-
withoutBase
|
|
1188
|
-
} from "@rspress/shared";
|
|
1189
|
-
function normalizeThemeConfig(docConfig, pages = []) {
|
|
1190
|
-
const {
|
|
1191
|
-
locales: siteLocales,
|
|
1192
|
-
base = "",
|
|
1193
|
-
lang,
|
|
1194
|
-
replaceRules = [],
|
|
1195
|
-
multiVersion
|
|
1196
|
-
} = docConfig;
|
|
1197
|
-
const { versions = [] } = multiVersion || {};
|
|
1198
|
-
const hasMultiVersion = versions.length > 0;
|
|
1199
|
-
docConfig.themeConfig = docConfig.themeConfig || {};
|
|
1200
|
-
const { themeConfig } = docConfig;
|
|
1201
|
-
const locales = siteLocales ?? (themeConfig?.locales || []);
|
|
1202
|
-
const i18nTextData = getI18nData(docConfig);
|
|
1203
|
-
const normalizeLinkPrefix = (link = "", currentLang = "") => {
|
|
1204
|
-
const normalizedLink = slash2(link);
|
|
1205
|
-
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
|
|
1206
|
-
hasMultiVersion) {
|
|
1207
|
-
return normalizedLink;
|
|
1208
|
-
}
|
|
1209
|
-
return lang === currentLang ? normalizedLink : `/${currentLang}${addLeadingSlash2(normalizedLink)}`;
|
|
1210
|
-
};
|
|
1211
|
-
const getI18nText = (key = "", currentLang = "") => {
|
|
1212
|
-
const text = i18nTextData[key]?.[currentLang];
|
|
1213
|
-
return text || key;
|
|
1214
|
-
};
|
|
1215
|
-
const normalizeSidebar = (sidebar, currentLang = "") => {
|
|
1216
|
-
const normalizedSidebar = {};
|
|
1217
|
-
if (!sidebar) {
|
|
1218
|
-
return {};
|
|
1219
772
|
}
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
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)
|
|
1245
804
|
};
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
const
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
);
|
|
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
|
+
});
|
|
1252
868
|
return {
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
869
|
+
...defaultIndexInfo,
|
|
870
|
+
title: frontmatter.title || title,
|
|
871
|
+
toc,
|
|
872
|
+
content,
|
|
873
|
+
_html: html,
|
|
874
|
+
frontmatter: {
|
|
875
|
+
...frontmatter,
|
|
876
|
+
__content: void 0
|
|
877
|
+
}
|
|
1256
878
|
};
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
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)}`;
|
|
1267
932
|
};
|
|
1268
|
-
const
|
|
1269
|
-
|
|
1270
|
-
const
|
|
1271
|
-
|
|
1272
|
-
});
|
|
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;
|
|
1273
937
|
};
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
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
|
+
}
|
|
1298
965
|
return {
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
),
|
|
1304
|
-
link: normalizeLinkPrefix(item.link, currentLang)
|
|
966
|
+
...item,
|
|
967
|
+
text: applyReplaceRules(getI18nText(item.text, currentLang), replaceRules),
|
|
968
|
+
link: normalizeLinkPrefix(item.link),
|
|
969
|
+
tag: item.tag
|
|
1305
970
|
};
|
|
1306
|
-
})
|
|
1307
971
|
};
|
|
1308
|
-
|
|
1309
|
-
|
|
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;
|
|
1310
980
|
};
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
)
|
|
1332
|
-
nav
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
)
|
|
1336
|
-
|
|
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
|
+
};
|
|
1337
1017
|
});
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
}
|
|
1342
|
-
return themeConfig;
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
// src/node/runtimeModule/siteData/index.ts
|
|
1346
|
-
function deletePrivateField(obj) {
|
|
1347
|
-
if (typeof obj !== "object" || obj === null) {
|
|
1348
|
-
return obj;
|
|
1349
|
-
}
|
|
1350
|
-
const newObj = { ...obj };
|
|
1351
|
-
Object.keys(newObj).forEach((key) => {
|
|
1352
|
-
if (key.startsWith("_")) {
|
|
1353
|
-
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);
|
|
1354
1021
|
}
|
|
1355
|
-
|
|
1356
|
-
|
|
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;
|
|
1357
1033
|
}
|
|
1358
1034
|
async function siteDataVMPlugin(context) {
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
tempSearchObj.searchHooks = void 0;
|
|
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
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
markdown: {
|
|
1436
|
-
showLineNumbers: userConfig?.markdown?.showLineNumbers ?? false,
|
|
1437
|
-
defaultWrapCode: userConfig?.markdown?.defaultWrapCode ?? false,
|
|
1438
|
-
codeHighlighter: userConfig?.markdown?.codeHighlighter || "prism"
|
|
1439
|
-
}
|
|
1440
|
-
};
|
|
1441
|
-
const { highlightLanguages: defaultLanguages = [] } = config.markdown || {};
|
|
1442
|
-
if (siteData.pages[0]?.extraHighlightLanguages?.length) {
|
|
1443
|
-
siteData.pages[0].extraHighlightLanguages.forEach(
|
|
1444
|
-
(lang) => highlightLanguages.add(lang)
|
|
1445
|
-
);
|
|
1446
|
-
}
|
|
1447
|
-
const aliases = handleHighlightLanguages(
|
|
1448
|
-
highlightLanguages,
|
|
1449
|
-
defaultLanguages
|
|
1450
|
-
);
|
|
1451
|
-
const sortedAliases = Object.fromEntries(Object.entries(aliases).sort());
|
|
1452
|
-
const sortedHighlightLanguages = Array.from(highlightLanguages).sort();
|
|
1453
|
-
return {
|
|
1454
|
-
[`${"virtual-site-data" /* SiteData */}.mjs`]: `export default ${JSON.stringify(
|
|
1455
|
-
siteData,
|
|
1456
|
-
null,
|
|
1457
|
-
2
|
|
1458
|
-
)}`,
|
|
1459
|
-
["virtual-search-index-hash" /* SearchIndexHash */]: `export default ${JSON.stringify(
|
|
1460
|
-
indexHashByGroup,
|
|
1461
|
-
null,
|
|
1462
|
-
2
|
|
1463
|
-
)}`,
|
|
1464
|
-
["virtual-prism-languages" /* PrismLanguages */]: `export const aliases = ${JSON.stringify(
|
|
1465
|
-
sortedAliases,
|
|
1466
|
-
null,
|
|
1467
|
-
2
|
|
1468
|
-
)};
|
|
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)};
|
|
1469
1111
|
export const languages = {
|
|
1470
|
-
${sortedHighlightLanguages.map((lang)
|
|
1471
|
-
return `"${lang}": require(
|
|
1112
|
+
${sortedHighlightLanguages.map((lang)=>`"${lang}": require(
|
|
1472
1113
|
"react-syntax-highlighter/dist/cjs/languages/prism/${lang}"
|
|
1473
|
-
).default
|
|
1474
|
-
})}
|
|
1114
|
+
).default`)}
|
|
1475
1115
|
}`
|
|
1476
|
-
|
|
1477
|
-
}
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
/**
|
|
1486
|
-
* Generate search index and site data for client runtime
|
|
1487
|
-
* Also responsible for automatically importing prism languages
|
|
1488
|
-
*/
|
|
1489
|
-
siteDataVMPlugin,
|
|
1490
|
-
/**
|
|
1491
|
-
* Generate global components from config and plugins
|
|
1492
|
-
*/
|
|
1493
|
-
globalUIComponentsVMPlugin,
|
|
1494
|
-
/**
|
|
1495
|
-
* Generate global styles from config and plugins
|
|
1496
|
-
*/
|
|
1497
|
-
globalStylesVMPlugin,
|
|
1498
|
-
/**
|
|
1499
|
-
* Generate i18n text for client runtime
|
|
1500
|
-
*/
|
|
1501
|
-
i18nVMPlugin,
|
|
1502
|
-
/**
|
|
1503
|
-
* Generate search hook module
|
|
1504
|
-
*/
|
|
1505
|
-
searchHookVMPlugin
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
const runtimeModuleFactory = [
|
|
1119
|
+
routeVMPlugin,
|
|
1120
|
+
siteDataVMPlugin,
|
|
1121
|
+
globalUIComponentsVMPlugin,
|
|
1122
|
+
globalStylesVMPlugin,
|
|
1123
|
+
i18nVMPlugin,
|
|
1124
|
+
searchHookVMPlugin
|
|
1506
1125
|
];
|
|
1507
1126
|
function rsbuildPluginDocVM(factoryContext) {
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
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
|
+
});
|
|
1523
1150
|
}
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
);
|
|
1539
|
-
});
|
|
1540
|
-
}
|
|
1541
|
-
};
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
// src/node/searchIndex.ts
|
|
1545
|
-
import { createReadStream } from "fs";
|
|
1546
|
-
import fs8 from "fs/promises";
|
|
1547
|
-
import path9, { join as join2 } from "path";
|
|
1548
|
-
import { SEARCH_INDEX_NAME as SEARCH_INDEX_NAME2, isSCM } from "@rspress/shared";
|
|
1549
|
-
import chalk2 from "@rspress/shared/chalk";
|
|
1550
|
-
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
|
+
}({});
|
|
1551
1165
|
async function writeSearchIndex(config) {
|
|
1552
|
-
|
|
1553
|
-
return;
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
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;
|
|
1565
1185
|
}
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
method: "PUT",
|
|
1581
|
-
body: searchIndexData,
|
|
1582
|
-
headers: { "Content-Type": "application/json" }
|
|
1583
|
-
});
|
|
1584
|
-
logger2.info(
|
|
1585
|
-
chalk2.green(
|
|
1586
|
-
`[doc-tools] Search index uploaded to ${apiUrl}, indexName: ${indexName}`
|
|
1587
|
-
)
|
|
1588
|
-
);
|
|
1589
|
-
} catch (e) {
|
|
1590
|
-
logger2.info(
|
|
1591
|
-
chalk2.red(
|
|
1592
|
-
`[doc-tools] Upload search index \`${indexName}\` failed:
|
|
1593
|
-
${e}`
|
|
1594
|
-
)
|
|
1595
|
-
);
|
|
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
|
+
}
|
|
1596
1200
|
}
|
|
1597
|
-
}
|
|
1598
1201
|
}
|
|
1599
1202
|
function serveSearchIndexMiddleware(config) {
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
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;
|
|
1616
1238
|
}
|
|
1617
|
-
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
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
|
+
});
|
|
1628
1293
|
return alias;
|
|
1629
|
-
}
|
|
1630
|
-
const files = await glob2("*.svg", {
|
|
1631
|
-
cwd: assetsDir
|
|
1632
|
-
});
|
|
1633
|
-
files.forEach((file) => {
|
|
1634
|
-
const name = path10.basename(file, ".svg");
|
|
1635
|
-
alias[`@theme-assets/${name}`] = path10.join(assetsDir, file);
|
|
1636
|
-
});
|
|
1637
|
-
return alias;
|
|
1638
1294
|
};
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
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"/>`,
|
|
1656
|
-
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"/>
|
|
1657
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"/>`,
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
};
|
|
1661
|
-
var formatIconName = (icon) => {
|
|
1662
|
-
const iconLowerCase = icon.toLowerCase();
|
|
1663
|
-
if (iconLowerCase === "twitter") {
|
|
1664
|
-
return "x";
|
|
1665
|
-
}
|
|
1666
|
-
return iconLowerCase;
|
|
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"/>'
|
|
1667
1314
|
};
|
|
1315
|
+
const formatIconName = (icon)=>icon.toLowerCase();
|
|
1668
1316
|
function getSocialIcons(socialLinks = []) {
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
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>`;
|
|
1674
1321
|
}
|
|
1675
|
-
|
|
1676
|
-
return icons;
|
|
1322
|
+
return icons;
|
|
1677
1323
|
}
|
|
1678
|
-
|
|
1679
|
-
// src/node/initRsbuild.ts
|
|
1680
1324
|
function isPluginIncluded(config, pluginName) {
|
|
1681
|
-
|
|
1682
|
-
(plugin)
|
|
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
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
}
|
|
1730
|
-
},
|
|
1731
|
-
dev: {
|
|
1732
|
-
progressBar: false,
|
|
1733
|
-
// Serve static files
|
|
1734
|
-
setupMiddlewares: [
|
|
1735
|
-
(middlewares) => {
|
|
1736
|
-
middlewares.unshift(serveSearchIndexMiddleware(config));
|
|
1737
|
-
}
|
|
1738
|
-
],
|
|
1739
|
-
cliShortcuts: {
|
|
1740
|
-
// does not support restart server yet
|
|
1741
|
-
custom: (shortcuts) => shortcuts.filter(({ key }) => key !== "r")
|
|
1742
|
-
}
|
|
1743
|
-
},
|
|
1744
|
-
html: {
|
|
1745
|
-
title: config?.title ?? DEFAULT_TITLE,
|
|
1746
|
-
favicon: normalizeIcon(config?.icon),
|
|
1747
|
-
template: path11.join(PACKAGE_ROOT, "index.html"),
|
|
1748
|
-
tags: [
|
|
1749
|
-
config.themeConfig?.darkMode !== false && {
|
|
1750
|
-
tag: "script",
|
|
1751
|
-
children: inlineThemeScript,
|
|
1752
|
-
append: false
|
|
1753
|
-
}
|
|
1754
|
-
].filter(Boolean)
|
|
1755
|
-
},
|
|
1756
|
-
output: {
|
|
1757
|
-
assetPrefix,
|
|
1758
|
-
distPath: {
|
|
1759
|
-
// just for rsbuild preview
|
|
1760
|
-
root: csrOutDir
|
|
1761
|
-
}
|
|
1762
|
-
},
|
|
1763
|
-
resolve: {
|
|
1764
|
-
alias: {
|
|
1765
|
-
...detectCustomIconAlias,
|
|
1766
|
-
"@mdx-js/react": __require.resolve("@mdx-js/react"),
|
|
1767
|
-
"@theme": [CUSTOM_THEME_DIR, DEFAULT_THEME],
|
|
1768
|
-
"@/theme-default": DEFAULT_THEME,
|
|
1769
|
-
"@rspress/core": PACKAGE_ROOT,
|
|
1770
|
-
"react-lazy-with-preload": __require.resolve("react-lazy-with-preload"),
|
|
1771
|
-
"react-syntax-highlighter": path11.dirname(
|
|
1772
|
-
__require.resolve("react-syntax-highlighter/package.json")
|
|
1773
|
-
),
|
|
1774
|
-
"@theme-assets": path11.join(DEFAULT_THEME, "../assets")
|
|
1775
|
-
}
|
|
1776
|
-
},
|
|
1777
|
-
source: {
|
|
1778
|
-
include: [PACKAGE_ROOT, path11.join(cwd, "node_modules", RSPRESS_TEMP_DIR2)],
|
|
1779
|
-
define: {
|
|
1780
|
-
"process.env.__REACT_GTE_18__": JSON.stringify(reactVersion >= 18),
|
|
1781
|
-
"process.env.TEST": JSON.stringify(process.env.TEST),
|
|
1782
|
-
"process.env.RSPRESS_SOCIAL_ICONS": JSON.stringify(
|
|
1783
|
-
getSocialIcons(config.themeConfig.socialLinks)
|
|
1784
|
-
)
|
|
1785
|
-
}
|
|
1786
|
-
},
|
|
1787
|
-
performance: {
|
|
1788
|
-
chunkSplit: {
|
|
1789
|
-
override: {
|
|
1790
|
-
cacheGroups: {
|
|
1791
|
-
// extract all CSS into a single file
|
|
1792
|
-
// ensure CSS in async chunks can be loaded for SSG
|
|
1793
|
-
styles: {
|
|
1794
|
-
name: "styles",
|
|
1795
|
-
minSize: 0,
|
|
1796
|
-
chunks: "all",
|
|
1797
|
-
test: /\.(?:css|less|sass|scss)$/,
|
|
1798
|
-
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)
|
|
1799
1373
|
}
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
}
|
|
1803
|
-
},
|
|
1804
|
-
tools: {
|
|
1805
|
-
bundlerChain(chain, { CHAIN_ID, target }) {
|
|
1806
|
-
const isServer = target === "node";
|
|
1807
|
-
const jsModuleRule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
1808
|
-
const swcLoaderOptions = jsModuleRule.use(CHAIN_ID.USE.SWC).get("options");
|
|
1809
|
-
const checkDeadLinks = (config?.markdown?.checkDeadLinks && !isServer) ?? false;
|
|
1810
|
-
chain.module.rule("MDX").type("javascript/auto").test(MDX_REGEXP3).resolve.merge({
|
|
1811
|
-
conditionNames: jsModuleRule.resolve.conditionNames.values(),
|
|
1812
|
-
mainFields: jsModuleRule.resolve.mainFields.values()
|
|
1813
|
-
}).end().oneOf("MDXCompile").use("builtin:swc-loader").loader("builtin:swc-loader").options(swcLoaderOptions).end().use("mdx-loader").loader(__require.resolve("../loader.cjs")).options({
|
|
1814
|
-
config,
|
|
1815
|
-
docDirectory: userDocRoot,
|
|
1816
|
-
checkDeadLinks,
|
|
1817
|
-
routeService: routeService2,
|
|
1818
|
-
pluginDriver
|
|
1819
|
-
}).end();
|
|
1820
|
-
if (chain.plugins.has(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH)) {
|
|
1821
|
-
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).tap((options) => {
|
|
1822
|
-
options[0] ?? (options[0] = {});
|
|
1823
|
-
options[0].include = [/\.([cm]js|[jt]sx?|flow)$/i, MDX_REGEXP3];
|
|
1824
|
-
return options;
|
|
1825
|
-
});
|
|
1826
|
-
}
|
|
1827
|
-
chain.resolve.extensions.prepend(".md").prepend(".mdx").prepend(".mjs");
|
|
1828
|
-
chain.module.rule("css-virtual-module").test(/\.rspress[\\/]runtime[\\/]virtual-global-styles/).merge({ sideEffects: true });
|
|
1829
|
-
if (isServer) {
|
|
1830
|
-
chain.output.filename("main.cjs");
|
|
1831
|
-
}
|
|
1832
|
-
const enableIncremental = !isProduction() && !process.env.DISABLE_RSPACK_INCREMENTAL;
|
|
1833
|
-
if (enableIncremental) {
|
|
1834
|
-
chain.merge({ experiments: { incremental: true } });
|
|
1835
|
-
}
|
|
1836
|
-
}
|
|
1837
|
-
},
|
|
1838
|
-
environments: {
|
|
1839
|
-
web: {
|
|
1840
|
-
resolve: {
|
|
1841
|
-
alias: reactCSRAlias
|
|
1842
1374
|
},
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
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)
|
|
1850
1397
|
},
|
|
1851
1398
|
output: {
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
}
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
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
|
+
],
|
|
1867
1424
|
define: {
|
|
1868
|
-
|
|
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))
|
|
1869
1428
|
}
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
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
|
+
}
|
|
1879
1505
|
},
|
|
1880
|
-
|
|
1881
|
-
|
|
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
|
+
} : {}
|
|
1882
1535
|
}
|
|
1883
|
-
|
|
1884
|
-
}
|
|
1885
|
-
};
|
|
1536
|
+
};
|
|
1886
1537
|
}
|
|
1887
1538
|
async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuildConfig) {
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
enableSSG,
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
config?.builderConfig || {},
|
|
1914
|
-
extraRsbuildConfig || {}
|
|
1915
|
-
)
|
|
1916
|
-
});
|
|
1917
|
-
rsbuild.addPlugins(builderPlugins);
|
|
1918
|
-
return rsbuild;
|
|
1919
|
-
}
|
|
1920
|
-
|
|
1921
|
-
// src/node/utils/checkLanguageParity.ts
|
|
1922
|
-
import fs10 from "fs/promises";
|
|
1923
|
-
import path12 from "path";
|
|
1924
|
-
import { logger as logger3 } from "@rspress/shared/logger";
|
|
1925
|
-
function normalizePath2(filePath) {
|
|
1926
|
-
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('/');
|
|
1927
1564
|
}
|
|
1928
1565
|
async function getAllMarkdownFilesFrom(dirPath) {
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
const
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
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);
|
|
1938
1579
|
}
|
|
1939
|
-
|
|
1940
|
-
return allFiles;
|
|
1580
|
+
return allFiles;
|
|
1941
1581
|
}
|
|
1942
1582
|
async function collectModuleFiles(contentPath, lang, includedDir, excludedDirs, fileLangMap) {
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
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)}`);
|
|
1961
1601
|
}
|
|
1962
|
-
|
|
1963
|
-
throw new Error(
|
|
1964
|
-
`Failed to access directory: ${normalizePath2(langModuleDir)}`
|
|
1965
|
-
);
|
|
1966
|
-
}
|
|
1967
|
-
return fileLangMap;
|
|
1602
|
+
return fileLangMap;
|
|
1968
1603
|
}
|
|
1969
1604
|
async function checkLanguageParity(config) {
|
|
1970
|
-
|
|
1971
|
-
return;
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
(
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
return;
|
|
1983
|
-
}
|
|
1984
|
-
const missingLanguagesFile = [];
|
|
1985
|
-
try {
|
|
1986
|
-
for (const includedDir of includedDirs) {
|
|
1987
|
-
if (excludedDirs.some((excludedDir) => excludedDir === includedDir))
|
|
1988
|
-
continue;
|
|
1989
|
-
const curFileLangMap = {};
|
|
1990
|
-
for (const lang of supportedLanguages2) {
|
|
1991
|
-
await collectModuleFiles(
|
|
1992
|
-
contentPath,
|
|
1993
|
-
lang,
|
|
1994
|
-
includedDir,
|
|
1995
|
-
excludedDirs,
|
|
1996
|
-
curFileLangMap
|
|
1997
|
-
);
|
|
1998
|
-
}
|
|
1999
|
-
for (const [baseName, langs] of Object.entries(curFileLangMap)) {
|
|
2000
|
-
const missingLangs = supportedLanguages2.filter(
|
|
2001
|
-
(lang) => !langs.has(lang)
|
|
2002
|
-
);
|
|
2003
|
-
missingLangs.forEach((lang) => {
|
|
2004
|
-
const missingPath = path12.join(lang, baseName);
|
|
2005
|
-
missingLanguagesFile.push(missingPath);
|
|
2006
|
-
});
|
|
2007
|
-
}
|
|
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;
|
|
2008
1617
|
}
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
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;
|
|
2014
1637
|
}
|
|
2015
|
-
|
|
2016
|
-
} catch (err) {
|
|
2017
|
-
logger3.error(`Error during language parity check: ${err.message}`);
|
|
2018
|
-
throw err;
|
|
2019
|
-
}
|
|
2020
|
-
}
|
|
2021
|
-
|
|
2022
|
-
// src/node/dev.ts
|
|
1638
|
+
}
|
|
2023
1639
|
async function dev(options) {
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
});
|
|
2045
|
-
return server;
|
|
2046
|
-
} finally {
|
|
2047
|
-
await writeSearchIndex(modifiedConfig);
|
|
2048
|
-
await checkLanguageParity(modifiedConfig);
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
|
|
2052
|
-
// src/node/build.ts
|
|
2053
|
-
import fs12 from "fs/promises";
|
|
2054
|
-
import { dirname as dirname2, join as join3 } from "path";
|
|
2055
|
-
import { pathToFileURL } from "url";
|
|
2056
|
-
import {
|
|
2057
|
-
isDebugMode as isDebugMode2,
|
|
2058
|
-
normalizeSlash,
|
|
2059
|
-
withBase as withBase3
|
|
2060
|
-
} from "@rspress/shared";
|
|
2061
|
-
import chalk3 from "@rspress/shared/chalk";
|
|
2062
|
-
import { logger as logger4 } from "@rspress/shared/logger";
|
|
2063
|
-
|
|
2064
|
-
// src/node/utils/renderHead.ts
|
|
2065
|
-
import fs11 from "fs/promises";
|
|
2066
|
-
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
|
+
}
|
|
2067
1660
|
async function renderFrontmatterHead(route) {
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
} = loadFrontMatter2(content, route.absolutePath, "", true);
|
|
2076
|
-
if (!head || head.length === 0)
|
|
2077
|
-
return "";
|
|
2078
|
-
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('');
|
|
2079
1668
|
}
|
|
2080
1669
|
async function renderConfigHead(config, route) {
|
|
2081
|
-
|
|
2082
|
-
return
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
return
|
|
2092
|
-
|
|
2093
|
-
return resultHead;
|
|
2094
|
-
return `<${resultHead[0]} ${renderAttrs(resultHead[1])}>`;
|
|
2095
|
-
}
|
|
2096
|
-
return `<${head[0]} ${renderAttrs(head[1])}>`;
|
|
2097
|
-
}).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('');
|
|
2098
1682
|
}
|
|
2099
1683
|
function renderAttrs(attrs) {
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
throw new Error(
|
|
2106
|
-
`Invalid value for attribute ${key}:${JSON.stringify(value)}`
|
|
2107
|
-
);
|
|
2108
|
-
}).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('');
|
|
2109
1689
|
}
|
|
2110
1690
|
function isRouteMeta(route) {
|
|
2111
|
-
|
|
1691
|
+
return 'routePath' in route && 'absolutePath' in route;
|
|
2112
1692
|
}
|
|
2113
|
-
|
|
2114
|
-
// src/node/build.ts
|
|
2115
1693
|
async function bundle(docDirectory, config, pluginDriver, enableSSG) {
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
}
|
|
2129
|
-
function emptyDir(path13) {
|
|
2130
|
-
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
|
+
});
|
|
2131
1707
|
}
|
|
2132
1708
|
async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
`Failed to load SSG bundle: ${chalk3.yellow(ssrBundlePath)}.`
|
|
2148
|
-
);
|
|
2149
|
-
throw e;
|
|
2150
|
-
}
|
|
2151
|
-
logger4.error(e);
|
|
2152
|
-
logger4.warn(
|
|
2153
|
-
`Failed to load SSG bundle: ${chalk3.yellow(ssrBundlePath)}, fallback to CSR.`
|
|
2154
|
-
);
|
|
2155
|
-
}
|
|
2156
|
-
}
|
|
2157
|
-
const routes = routeService.getRoutes();
|
|
2158
|
-
const base = config?.base ?? "";
|
|
2159
|
-
const htmlTemplatePath = join3(outputPath, "index.html");
|
|
2160
|
-
const htmlTemplate = await fs12.readFile(htmlTemplatePath, "utf-8");
|
|
2161
|
-
const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route) => ({
|
|
2162
|
-
routePath: withBase3(route.path, base)
|
|
2163
|
-
}));
|
|
2164
|
-
const allRoutes = [...routes, ...additionalRoutes];
|
|
2165
|
-
const is404RouteInRoutes = allRoutes.some(
|
|
2166
|
-
(route) => route.routePath === "/404"
|
|
2167
|
-
);
|
|
2168
|
-
if (!is404RouteInRoutes) {
|
|
2169
|
-
allRoutes.push({
|
|
2170
|
-
routePath: "/404"
|
|
2171
|
-
});
|
|
2172
|
-
}
|
|
2173
|
-
await Promise.all(
|
|
2174
|
-
allRoutes.filter((route) => {
|
|
2175
|
-
return !route.routePath.includes(":");
|
|
2176
|
-
}).map(async (route) => {
|
|
2177
|
-
const helmetContext = {
|
|
2178
|
-
context: {}
|
|
2179
|
-
};
|
|
2180
|
-
const { routePath } = route;
|
|
2181
|
-
let appHtml = "";
|
|
2182
|
-
if (render) {
|
|
2183
|
-
try {
|
|
2184
|
-
({ appHtml } = await render(routePath, helmetContext.context));
|
|
2185
|
-
} catch (e) {
|
|
2186
|
-
if (typeof ssgConfig === "object" && ssgConfig.strict) {
|
|
2187
|
-
logger4.error(
|
|
2188
|
-
`Page "${chalk3.yellow(routePath)}" SSG rendering failed.`
|
|
2189
|
-
);
|
|
2190
|
-
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;
|
|
2191
1723
|
}
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
);
|
|
2195
|
-
}
|
|
2196
|
-
}
|
|
2197
|
-
const { helmet } = helmetContext.context;
|
|
2198
|
-
let html = htmlTemplate.replace(/<title>(.*?)<\/title>/gi, "").replace(APP_HTML_MARKER, () => appHtml).replace(
|
|
2199
|
-
META_GENERATOR,
|
|
2200
|
-
() => `<meta name="generator" content="Rspress v${version}">`
|
|
2201
|
-
).replace(
|
|
2202
|
-
HEAD_MARKER,
|
|
2203
|
-
[
|
|
2204
|
-
await renderConfigHead(config, route),
|
|
2205
|
-
helmet?.title?.toString(),
|
|
2206
|
-
helmet?.meta?.toString(),
|
|
2207
|
-
helmet?.link?.toString(),
|
|
2208
|
-
helmet?.style?.toString(),
|
|
2209
|
-
helmet?.script?.toString(),
|
|
2210
|
-
await renderFrontmatterHead(route)
|
|
2211
|
-
].join("")
|
|
2212
|
-
);
|
|
2213
|
-
if (helmet?.htmlAttributes) {
|
|
2214
|
-
html = html.replace(
|
|
2215
|
-
HTML_START_TAG,
|
|
2216
|
-
`${HTML_START_TAG} ${helmet?.htmlAttributes?.toString()}`
|
|
2217
|
-
);
|
|
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.`);
|
|
2218
1726
|
}
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
await fs12.mkdir(join3(outputPath, dirname2(fileName)), {
|
|
2234
|
-
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'
|
|
2235
1741
|
});
|
|
2236
|
-
await
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
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;
|
|
2241
1794
|
}
|
|
2242
|
-
await emptyDir(join3(outputPath, "html"));
|
|
2243
|
-
const totalTime = Date.now() - startTime;
|
|
2244
|
-
logger4.success(`Pages rendered in ${chalk3.yellow(totalTime)} ms.`);
|
|
2245
|
-
} catch (e) {
|
|
2246
|
-
logger4.error(`Pages render error: ${e.stack}`);
|
|
2247
|
-
throw e;
|
|
2248
|
-
}
|
|
2249
1795
|
}
|
|
2250
1796
|
async function build(options) {
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
}
|
|
2262
|
-
|
|
2263
|
-
// src/node/serve.ts
|
|
2264
|
-
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
|
+
}
|
|
2265
1808
|
async function serve(options) {
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
envPort || userPort || builderConfig
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
}
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
false
|
|
2288
|
-
);
|
|
2289
|
-
await builder.preview();
|
|
2290
|
-
}
|
|
2291
|
-
|
|
2292
|
-
// src/index.ts
|
|
2293
|
-
export * from "@rspress/shared";
|
|
2294
|
-
import { mergeDocConfig } from "@rspress/shared/node-utils";
|
|
2295
|
-
export {
|
|
2296
|
-
build,
|
|
2297
|
-
dev,
|
|
2298
|
-
mergeDocConfig,
|
|
2299
|
-
serve
|
|
2300
|
-
};
|
|
2301
|
-
|
|
2302
|
-
//# 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 };
|