@rspress/core 2.0.0-alpha.1 → 2.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -1
- package/dist/index.js +133 -84
- package/dist/loader.d.ts +2 -0
- package/dist/loader.js +21 -15
- package/dist/runtime/App.d.ts +0 -6
- package/dist/runtime/App.js +3 -65
- package/dist/runtime/ClientApp.d.ts +1 -0
- package/dist/runtime/ClientApp.js +40 -0
- package/dist/runtime/clientEntry.d.ts +1 -1
- package/dist/runtime/clientEntry.js +8 -63
- package/dist/runtime/initPageData.d.ts +3 -0
- package/dist/runtime/initPageData.js +59 -0
- package/dist/runtime/ssrEntry.js +2 -1
- package/package.json +35 -33
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mergeDocConfig } from '@rspress/shared/node-utils';
|
|
2
2
|
import type { RsbuildConfig } from '@rsbuild/core';
|
|
3
|
+
import { RsbuildInstance } from '@rsbuild/core';
|
|
3
4
|
import { UserConfig } from '@rspress/shared';
|
|
4
5
|
|
|
5
6
|
export declare function build(options: BuildOptions): Promise<void>;
|
|
@@ -21,7 +22,7 @@ declare interface DevOptions {
|
|
|
21
22
|
|
|
22
23
|
export { mergeDocConfig }
|
|
23
24
|
|
|
24
|
-
export declare function serve(options: ServeOptions): Promise<
|
|
25
|
+
export declare function serve(options: ServeOptions): Promise<ReturnType<RsbuildInstance['preview']>>;
|
|
25
26
|
|
|
26
27
|
declare interface ServeOptions {
|
|
27
28
|
config: UserConfig;
|
package/dist/index.js
CHANGED
|
@@ -4,17 +4,14 @@ import * as __WEBPACK_EXTERNAL_MODULE__rspress_plugin_container_syntax_12d3c700_
|
|
|
4
4
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
|
|
5
5
|
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__ from "node:fs/promises";
|
|
6
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
7
|
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
8
|
import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
|
|
11
|
-
import * as
|
|
9
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__ from "@rspress/shared/logger";
|
|
12
10
|
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
13
11
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__ from "@rspress/shared/constants";
|
|
14
12
|
import * as __WEBPACK_EXTERNAL_MODULE_tinyglobby__ from "tinyglobby";
|
|
15
13
|
import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
|
|
16
14
|
import * as __WEBPACK_EXTERNAL_MODULE_rspack_plugin_virtual_module_609978fd__ from "rspack-plugin-virtual-module";
|
|
17
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__ from "@rspress/shared/logger";
|
|
18
15
|
import * as __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__ from "lodash-es";
|
|
19
16
|
import * as __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__ from "node:crypto";
|
|
20
17
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_mdx_rs_d2f3021f__ from "@rspress/mdx-rs";
|
|
@@ -25,6 +22,7 @@ import * as __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__ from "@mdx-js/mdx";
|
|
|
25
22
|
import * as __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__ from "enhanced-resolve";
|
|
26
23
|
import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
|
|
27
24
|
import * as __WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__ from "react-helmet-async";
|
|
25
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
28
26
|
export * from "@rspress/shared";
|
|
29
27
|
function _check_private_redeclaration(obj, privateCollection) {
|
|
30
28
|
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
@@ -186,6 +184,37 @@ class PluginDriver {
|
|
|
186
184
|
_class_private_field_set(this, _plugins, []);
|
|
187
185
|
}
|
|
188
186
|
}
|
|
187
|
+
const PLUGIN_VIRTUAL_MODULE_NAME = 'rsbuild:virtual-module';
|
|
188
|
+
const pluginVirtualModule = (pluginOptions = {})=>({
|
|
189
|
+
name: PLUGIN_VIRTUAL_MODULE_NAME,
|
|
190
|
+
async setup (api) {
|
|
191
|
+
const TEMP_DIR = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), 'node_modules/.rsbuild-virtual-module');
|
|
192
|
+
const { virtualModules = {} } = pluginOptions;
|
|
193
|
+
const virtualFileAbsolutePaths = Object.keys(virtualModules).map((i)=>{
|
|
194
|
+
let absolutePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(TEMP_DIR, i);
|
|
195
|
+
if (!(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.extname)(absolutePath)) absolutePath = `${absolutePath}.js`;
|
|
196
|
+
return [
|
|
197
|
+
i,
|
|
198
|
+
absolutePath
|
|
199
|
+
];
|
|
200
|
+
});
|
|
201
|
+
api.onBeforeCreateCompiler(async ()=>{
|
|
202
|
+
await (0, __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__.mkdir)(TEMP_DIR, {
|
|
203
|
+
recursive: true
|
|
204
|
+
});
|
|
205
|
+
await Promise.all(virtualFileAbsolutePaths.map(([_, absolutePath])=>(0, __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__.writeFile)(absolutePath, '', 'utf-8')));
|
|
206
|
+
});
|
|
207
|
+
api.modifyBundlerChain((chain)=>{
|
|
208
|
+
chain.resolve.alias.merge(Object.fromEntries(virtualFileAbsolutePaths));
|
|
209
|
+
});
|
|
210
|
+
for (const [moduleName, absolutePath] of virtualFileAbsolutePaths){
|
|
211
|
+
const handler = virtualModules[moduleName];
|
|
212
|
+
if (handler) api.transform({
|
|
213
|
+
test: absolutePath
|
|
214
|
+
}, handler);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
189
218
|
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
190
219
|
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
191
220
|
const inlineThemeScript = `{
|
|
@@ -193,6 +222,7 @@ const inlineThemeScript = `{
|
|
|
193
222
|
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
194
223
|
const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
|
|
195
224
|
document.documentElement.classList.toggle('dark', isDark)
|
|
225
|
+
document.documentElement.classList.toggle('rp-dark', isDark)
|
|
196
226
|
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
197
227
|
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
198
228
|
const dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(new URL(import.meta.url)));
|
|
@@ -207,7 +237,7 @@ const HTML_START_TAG = '<html';
|
|
|
207
237
|
const BODY_START_TAG = '<body';
|
|
208
238
|
const DEFAULT_TITLE = 'Rspress';
|
|
209
239
|
const PUBLIC_DIR = 'public';
|
|
210
|
-
const
|
|
240
|
+
const constants_TEMP_DIR = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'node_modules', __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR);
|
|
211
241
|
async function pathExists(path) {
|
|
212
242
|
try {
|
|
213
243
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].access(path);
|
|
@@ -220,7 +250,7 @@ async function readJson(path) {
|
|
|
220
250
|
const raw = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(path, 'utf8');
|
|
221
251
|
return JSON.parse(raw);
|
|
222
252
|
}
|
|
223
|
-
const THEME_DEFAULT_EXPORT_PATTERN = /export
|
|
253
|
+
const THEME_DEFAULT_EXPORT_PATTERN = /export\s+default\s+\{/;
|
|
224
254
|
async function hintThemeBreakingChange(customThemeDir) {
|
|
225
255
|
const fileList = [
|
|
226
256
|
'index.ts',
|
|
@@ -236,20 +266,30 @@ async function hintThemeBreakingChange(customThemeDir) {
|
|
|
236
266
|
encoding: 'utf-8'
|
|
237
267
|
});
|
|
238
268
|
if (THEME_DEFAULT_EXPORT_PATTERN.test(content)) useDefaultExportFilePath = filePath;
|
|
269
|
+
break;
|
|
239
270
|
}
|
|
240
271
|
}
|
|
241
|
-
if (useDefaultExportFilePath)
|
|
272
|
+
if (useDefaultExportFilePath) __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`[Rspress v2] Breaking Change: The "theme/index.tsx" is now using named export instead of default export, please update ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].greenBright(useDefaultExportFilePath)} (https://github.com/web-infra-dev/rspress/discussions/1891#discussioncomment-12422737).\n`, __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].redBright(`
|
|
242
273
|
- import Theme from '@rspress/theme-default';
|
|
243
274
|
- export default {
|
|
244
275
|
- ...Theme,
|
|
245
276
|
- Layout,
|
|
246
277
|
- };
|
|
247
|
-
- export * from 'rspress/theme';`) + __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].
|
|
278
|
+
- export * from 'rspress/theme';`) + __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].greenBright(`
|
|
279
|
+
+ import { Layout } from '@rspress/theme-default';
|
|
248
280
|
|
|
249
281
|
+ export { Layout };
|
|
250
282
|
+ export * from 'rspress/theme';
|
|
251
283
|
`));
|
|
252
284
|
}
|
|
285
|
+
function hintSSGFailed() {
|
|
286
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info(`[Rspress v2] \`ssg: true\` requires the source code to support SSR. If the code is not compatible to SSR, the build process will fail. You can try:
|
|
287
|
+
1. Fix code to make it SSR-compatible.
|
|
288
|
+
2. Set \`ssg: false\`, but the SSG feature will be lost.`);
|
|
289
|
+
}
|
|
290
|
+
function hintSSGFalse() {
|
|
291
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('`ssg: false` detected, SSG will be disabled.');
|
|
292
|
+
}
|
|
253
293
|
const isWindows = 'win32' === __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__["default"].platform();
|
|
254
294
|
function slash(p) {
|
|
255
295
|
return p.replace(/\\/g, '/');
|
|
@@ -261,7 +301,7 @@ function getPageKey(route) {
|
|
|
261
301
|
const cleanRoute = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeLeadingSlash)(route);
|
|
262
302
|
return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
|
|
263
303
|
}
|
|
264
|
-
const
|
|
304
|
+
const getRoutePathParts = (routePath, lang, version, langs, versions)=>{
|
|
265
305
|
const hasTrailSlash = routePath.endsWith('/');
|
|
266
306
|
let versionPart = '';
|
|
267
307
|
let langPart = '';
|
|
@@ -282,14 +322,20 @@ const normalizeRoutePath = (routePath, base, lang, version, langs, versions, ext
|
|
|
282
322
|
}
|
|
283
323
|
}
|
|
284
324
|
purePathPart = parts.join('/');
|
|
325
|
+
return [
|
|
326
|
+
versionPart,
|
|
327
|
+
langPart,
|
|
328
|
+
hasTrailSlash ? (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addTrailingSlash)(purePathPart) : purePathPart
|
|
329
|
+
];
|
|
330
|
+
};
|
|
331
|
+
const normalizeRoutePath = (routePath, base, lang, version, langs, versions, extensions = __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS)=>{
|
|
332
|
+
const [versionPart, langPart, purePathPart] = getRoutePathParts(routePath, lang, version, langs, versions);
|
|
285
333
|
const extensionsWithoutDot = extensions.map((i)=>i.slice(1));
|
|
286
334
|
const cleanExtensionPattern = new RegExp(`\\.(${extensionsWithoutDot.join('|')})$`, 'i');
|
|
287
|
-
|
|
335
|
+
const normalizedRoutePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)([
|
|
288
336
|
versionPart,
|
|
289
|
-
langPart
|
|
290
|
-
|
|
291
|
-
].filter(Boolean).join('/')).replace(cleanExtensionPattern, '').replace(/\.html$/, '').replace(/\/index$/, '/');
|
|
292
|
-
if (hasTrailSlash) normalizedRoutePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addTrailingSlash)(normalizedRoutePath);
|
|
337
|
+
langPart
|
|
338
|
+
].filter(Boolean).join('/') + (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)(purePathPart)).replace(cleanExtensionPattern, '').replace(/\.html$/, '').replace(/\/index$/, '/');
|
|
293
339
|
return {
|
|
294
340
|
routePath: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(normalizedRoutePath, base),
|
|
295
341
|
lang: langPart || lang,
|
|
@@ -347,6 +393,9 @@ function _define_property(obj, key, value) {
|
|
|
347
393
|
}
|
|
348
394
|
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();
|
|
349
395
|
class RouteService {
|
|
396
|
+
get extensions() {
|
|
397
|
+
return RouteService_class_private_field_get(this, _extensions);
|
|
398
|
+
}
|
|
350
399
|
async init() {
|
|
351
400
|
const extensions = RouteService_class_private_field_get(this, _extensions).map((i)=>i.slice(1));
|
|
352
401
|
const files = (await (0, __WEBPACK_EXTERNAL_MODULE_tinyglobby__.glob)([
|
|
@@ -437,6 +486,9 @@ ${routeMeta.map((route, index)=>{
|
|
|
437
486
|
];
|
|
438
487
|
`;
|
|
439
488
|
}
|
|
489
|
+
getRoutePathParts(routePath) {
|
|
490
|
+
return getRoutePathParts(routePath, 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));
|
|
491
|
+
}
|
|
440
492
|
normalizeRoutePath(routePath) {
|
|
441
493
|
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));
|
|
442
494
|
}
|
|
@@ -531,16 +583,10 @@ async function initRouteService(options) {
|
|
|
531
583
|
async function globalStylesVMPlugin(context) {
|
|
532
584
|
const { config, pluginDriver } = context;
|
|
533
585
|
const globalStylesByPlugins = pluginDriver.globalStyles();
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
const styleContent = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(source, 'utf-8');
|
|
537
|
-
const patchedStyleContent = styleContent.replace(/--modern-/g, '--rp-').replace(/\.modern-doc/g, '.rspress').replace(/\.modern-/g, '.rspress-');
|
|
538
|
-
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(source, patchedStyleContent, 'utf-8');
|
|
539
|
-
}
|
|
540
|
-
const moduleContent = (await Promise.all([
|
|
541
|
-
(null == config ? void 0 : config.globalStyles) || '',
|
|
586
|
+
const moduleContent = [
|
|
587
|
+
null == config ? void 0 : config.globalStyles,
|
|
542
588
|
...globalStylesByPlugins
|
|
543
|
-
].filter(
|
|
589
|
+
].filter(Boolean).map((source)=>`import ${JSON.stringify(source)};`).join('');
|
|
544
590
|
return {
|
|
545
591
|
[runtimeModule_RuntimeModuleID.GlobalStyles]: moduleContent
|
|
546
592
|
};
|
|
@@ -569,25 +615,6 @@ const Props_${index++} = ${JSON.stringify(source[1])};\n`;
|
|
|
569
615
|
[runtimeModule_RuntimeModuleID.GlobalComponents]: moduleContent
|
|
570
616
|
};
|
|
571
617
|
}
|
|
572
|
-
const DEFAULT_I18N_SOURCE = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), 'i18n.json');
|
|
573
|
-
function getI18nData(docConfig) {
|
|
574
|
-
const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
|
|
575
|
-
try {
|
|
576
|
-
delete require.cache[i18nSourcePath];
|
|
577
|
-
const i18nSource = require(i18nSourcePath);
|
|
578
|
-
return i18nSource;
|
|
579
|
-
} catch (e) {
|
|
580
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug('getI18nData Failed: \n', e);
|
|
581
|
-
return {};
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
function i18nVMPlugin(context) {
|
|
585
|
-
const { config } = context;
|
|
586
|
-
const i18nData = getI18nData(config);
|
|
587
|
-
return {
|
|
588
|
-
[runtimeModule_RuntimeModuleID.I18nText]: `export default ${JSON.stringify(i18nData, null, 2)}`
|
|
589
|
-
};
|
|
590
|
-
}
|
|
591
618
|
async function routeVMPlugin(context) {
|
|
592
619
|
const { routeService, isSSR } = context;
|
|
593
620
|
if (!isSSR) return {
|
|
@@ -841,6 +868,29 @@ function handleHighlightLanguages(highlightLanguages, defaultLanguages) {
|
|
|
841
868
|
}
|
|
842
869
|
return aliases;
|
|
843
870
|
}
|
|
871
|
+
const DEFAULT_I18N_SOURCE = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), 'i18n.json');
|
|
872
|
+
function getI18nData(docConfig) {
|
|
873
|
+
const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
|
|
874
|
+
try {
|
|
875
|
+
delete require.cache[i18nSourcePath];
|
|
876
|
+
const i18nSource = require(i18nSourcePath);
|
|
877
|
+
return i18nSource;
|
|
878
|
+
} catch (e) {
|
|
879
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug('getI18nData Failed: \n', e);
|
|
880
|
+
return {};
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
function i18nVMPlugin(context) {
|
|
884
|
+
const { config } = context;
|
|
885
|
+
return {
|
|
886
|
+
[runtimeModule_RuntimeModuleID.I18nText]: ({ addDependency, addMissingDependency })=>{
|
|
887
|
+
addDependency(config.i18nSourcePath || DEFAULT_I18N_SOURCE);
|
|
888
|
+
addMissingDependency(config.i18nSourcePath || DEFAULT_I18N_SOURCE);
|
|
889
|
+
const i18nData = getI18nData(config);
|
|
890
|
+
return `export default ${JSON.stringify(i18nData, null, 2)}`;
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
}
|
|
844
894
|
function normalizeThemeConfig(docConfig, pages = []) {
|
|
845
895
|
const { locales: siteLocales, base = '', lang, replaceRules = [], multiVersion } = docConfig;
|
|
846
896
|
const { versions = [] } = multiVersion || {};
|
|
@@ -963,7 +1013,7 @@ async function siteDataVMPlugin(context) {
|
|
|
963
1013
|
const replaceRules = (null == userConfig ? void 0 : userConfig.replaceRules) || [];
|
|
964
1014
|
const searchConfig = (null == userConfig ? void 0 : userConfig.search) || {};
|
|
965
1015
|
const domain = (null == searchConfig ? void 0 : searchConfig.mode) === 'remote' ? searchConfig.domain ?? '' : '';
|
|
966
|
-
const searchCodeBlocks = 'codeBlocks' in searchConfig ? Boolean(searchConfig.codeBlocks) :
|
|
1016
|
+
const searchCodeBlocks = 'codeBlocks' in searchConfig ? Boolean(searchConfig.codeBlocks) : true;
|
|
967
1017
|
const pages = await extractPageData(replaceRules, alias, domain, userDocRoot, routeService, highlightLanguages, searchCodeBlocks);
|
|
968
1018
|
await pluginDriver.modifySearchIndexData(pages);
|
|
969
1019
|
const versioned = userConfig.search && 'remote' !== userConfig.search.mode && userConfig.search.versioned;
|
|
@@ -983,10 +1033,10 @@ async function siteDataVMPlugin(context) {
|
|
|
983
1033
|
const [version, lang] = group.split('###');
|
|
984
1034
|
const indexVersion = version ? `.${version.replace('.', '_')}` : '';
|
|
985
1035
|
const indexLang = lang ? `.${lang}` : '';
|
|
986
|
-
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(
|
|
1036
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(constants_TEMP_DIR, {
|
|
987
1037
|
recursive: true
|
|
988
1038
|
});
|
|
989
|
-
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(
|
|
1039
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(constants_TEMP_DIR, `${__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME}${indexVersion}${indexLang}.${indexHash}.json`), stringifiedIndex);
|
|
990
1040
|
}));
|
|
991
1041
|
await Promise.all(pages.map(async (pageData)=>pluginDriver.extendPageData(pageData)));
|
|
992
1042
|
const siteData = {
|
|
@@ -1042,7 +1092,6 @@ const runtimeModuleFactory = [
|
|
|
1042
1092
|
siteDataVMPlugin,
|
|
1043
1093
|
globalUIComponentsVMPlugin,
|
|
1044
1094
|
globalStylesVMPlugin,
|
|
1045
|
-
i18nVMPlugin,
|
|
1046
1095
|
searchHookVMPlugin
|
|
1047
1096
|
];
|
|
1048
1097
|
function rsbuildPluginDocVM(factoryContext) {
|
|
@@ -1088,7 +1137,7 @@ async function writeSearchIndex(config) {
|
|
|
1088
1137
|
var _config_search;
|
|
1089
1138
|
if ((null == config ? void 0 : config.search) === false) return;
|
|
1090
1139
|
const cwd = process.cwd();
|
|
1091
|
-
const searchIndexFiles = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readdir(
|
|
1140
|
+
const searchIndexFiles = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readdir(constants_TEMP_DIR);
|
|
1092
1141
|
const outDir = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, OUTPUT_DIR);
|
|
1093
1142
|
const targetDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outDir, 'static');
|
|
1094
1143
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(targetDir, {
|
|
@@ -1098,9 +1147,9 @@ async function writeSearchIndex(config) {
|
|
|
1098
1147
|
let scanning = false;
|
|
1099
1148
|
for (const searchIndexFile of searchIndexFiles){
|
|
1100
1149
|
if (!searchIndexFile.includes(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME) || !searchIndexFile.endsWith('.json')) continue;
|
|
1101
|
-
const source = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(
|
|
1150
|
+
const source = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(constants_TEMP_DIR, searchIndexFile);
|
|
1102
1151
|
const target = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(targetDir, searchIndexFile);
|
|
1103
|
-
const searchIndex = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(
|
|
1152
|
+
const searchIndex = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(constants_TEMP_DIR, searchIndexFile), 'utf-8');
|
|
1104
1153
|
searchIndexData = `${searchIndexData.slice(0, -1)}${scanning ? ',' : ''}${searchIndex.slice(1)}`;
|
|
1105
1154
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].rename(source, target);
|
|
1106
1155
|
scanning = true;
|
|
@@ -1256,23 +1305,23 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1256
1305
|
resolveReactAlias(reactVersion, false),
|
|
1257
1306
|
enableSSG ? resolveReactAlias(reactVersion, true) : Promise.resolve({})
|
|
1258
1307
|
]);
|
|
1308
|
+
const context = {
|
|
1309
|
+
userDocRoot,
|
|
1310
|
+
config,
|
|
1311
|
+
runtimeTempDir,
|
|
1312
|
+
routeService,
|
|
1313
|
+
pluginDriver
|
|
1314
|
+
};
|
|
1259
1315
|
return {
|
|
1260
1316
|
plugins: [
|
|
1261
1317
|
...isPluginIncluded(config, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__.PLUGIN_REACT_NAME) ? [] : [
|
|
1262
1318
|
(0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__.pluginReact)()
|
|
1263
1319
|
],
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
],
|
|
1270
|
-
rsbuildPluginDocVM({
|
|
1271
|
-
userDocRoot,
|
|
1272
|
-
config,
|
|
1273
|
-
runtimeTempDir,
|
|
1274
|
-
routeService,
|
|
1275
|
-
pluginDriver
|
|
1320
|
+
rsbuildPluginDocVM(context),
|
|
1321
|
+
pluginVirtualModule({
|
|
1322
|
+
virtualModules: {
|
|
1323
|
+
...i18nVMPlugin(context)
|
|
1324
|
+
}
|
|
1276
1325
|
})
|
|
1277
1326
|
],
|
|
1278
1327
|
server: {
|
|
@@ -1567,7 +1616,7 @@ async function dev(options) {
|
|
|
1567
1616
|
await checkLanguageParity(modifiedConfig);
|
|
1568
1617
|
}
|
|
1569
1618
|
}
|
|
1570
|
-
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-alpha.
|
|
1619
|
+
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-alpha.10"}');
|
|
1571
1620
|
async function renderFrontmatterHead(route) {
|
|
1572
1621
|
if (!isRouteMeta(route)) return '';
|
|
1573
1622
|
const content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, {
|
|
@@ -1616,24 +1665,23 @@ function emptyDir(path) {
|
|
|
1616
1665
|
recursive: true
|
|
1617
1666
|
});
|
|
1618
1667
|
}
|
|
1619
|
-
async function renderPages(appDirectory, config, pluginDriver
|
|
1668
|
+
async function renderPages(appDirectory, config, pluginDriver) {
|
|
1620
1669
|
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Rendering pages...');
|
|
1621
1670
|
const startTime = Date.now();
|
|
1622
1671
|
const outputPath = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(appDirectory, OUTPUT_DIR);
|
|
1623
1672
|
const ssrBundlePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'ssr', 'main.cjs');
|
|
1673
|
+
let render;
|
|
1624
1674
|
try {
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}.`);
|
|
1632
|
-
throw e;
|
|
1633
|
-
}
|
|
1634
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(e);
|
|
1635
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}, fallback to CSR.`);
|
|
1675
|
+
const { default: ssrExports } = await import((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(ssrBundlePath).toString());
|
|
1676
|
+
({ render } = ssrExports);
|
|
1677
|
+
} catch (e) {
|
|
1678
|
+
if (e instanceof Error) {
|
|
1679
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}: ${e.message}`);
|
|
1680
|
+
hintSSGFailed();
|
|
1636
1681
|
}
|
|
1682
|
+
throw e;
|
|
1683
|
+
}
|
|
1684
|
+
try {
|
|
1637
1685
|
const routes = init_routeService.getRoutes();
|
|
1638
1686
|
const base = (null == config ? void 0 : config.base) ?? '';
|
|
1639
1687
|
const htmlTemplatePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'index.html');
|
|
@@ -1650,17 +1698,14 @@ async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
|
|
|
1650
1698
|
routePath: '/404'
|
|
1651
1699
|
});
|
|
1652
1700
|
await Promise.all(allRoutes.filter((route)=>!route.routePath.includes(':')).map(async (route)=>{
|
|
1653
|
-
const helmetContext = new __WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__.HelmetData({});
|
|
1701
|
+
const helmetContext = new __WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__["default"].HelmetData({});
|
|
1654
1702
|
const { routePath } = route;
|
|
1655
1703
|
let appHtml = '';
|
|
1656
1704
|
if (render) try {
|
|
1657
1705
|
({ appHtml } = await render(routePath, helmetContext.context));
|
|
1658
1706
|
} catch (e) {
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
throw e;
|
|
1662
|
-
}
|
|
1663
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering error, fallback to CSR.`, e);
|
|
1707
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering failed.`);
|
|
1708
|
+
throw e;
|
|
1664
1709
|
}
|
|
1665
1710
|
const { helmet } = helmetContext.context;
|
|
1666
1711
|
let html = htmlTemplate.replace(/<title>(.*?)<\/title>/gi, '').replace(APP_HTML_MARKER, ()=>appHtml).replace(META_GENERATOR, ()=>`<meta name="generator" content="Rspress v${package_namespaceObject.i8}">`).replace(HEAD_MARKER, [
|
|
@@ -1696,7 +1741,10 @@ async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
|
|
|
1696
1741
|
const totalTime = Date.now() - startTime;
|
|
1697
1742
|
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.success(`Pages rendered in ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(totalTime)} ms.`);
|
|
1698
1743
|
} catch (e) {
|
|
1699
|
-
if (e instanceof Error)
|
|
1744
|
+
if (e instanceof Error) {
|
|
1745
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Pages render error: ${e.message}`);
|
|
1746
|
+
hintSSGFailed();
|
|
1747
|
+
}
|
|
1700
1748
|
throw e;
|
|
1701
1749
|
}
|
|
1702
1750
|
}
|
|
@@ -1707,9 +1755,10 @@ async function build(options) {
|
|
|
1707
1755
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1708
1756
|
await pluginDriver.beforeBuild();
|
|
1709
1757
|
const ssgConfig = modifiedConfig.ssg ?? true;
|
|
1710
|
-
await emptyDir(
|
|
1758
|
+
await emptyDir(constants_TEMP_DIR);
|
|
1711
1759
|
await bundle(docDirectory, modifiedConfig, pluginDriver, Boolean(ssgConfig));
|
|
1712
|
-
await renderPages(appDirectory, modifiedConfig, pluginDriver
|
|
1760
|
+
if (ssgConfig) await renderPages(appDirectory, modifiedConfig, pluginDriver);
|
|
1761
|
+
else hintSSGFalse();
|
|
1713
1762
|
await pluginDriver.afterBuild();
|
|
1714
1763
|
}
|
|
1715
1764
|
async function serve(options) {
|
|
@@ -1730,7 +1779,7 @@ async function serve(options) {
|
|
|
1730
1779
|
await pluginDriver.init();
|
|
1731
1780
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1732
1781
|
const builder = await initRsbuild(config.root, modifiedConfig, pluginDriver, false);
|
|
1733
|
-
|
|
1782
|
+
return builder.preview();
|
|
1734
1783
|
}
|
|
1735
1784
|
var __webpack_exports__mergeDocConfig = __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.mergeDocConfig;
|
|
1736
1785
|
export { build, dev, serve, __webpack_exports__mergeDocConfig as mergeDocConfig };
|
package/dist/loader.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ declare class RouteService {
|
|
|
58
58
|
#private;
|
|
59
59
|
routeData: Map<string, RouteMeta>;
|
|
60
60
|
constructor(scanDir: string, userConfig: UserConfig, tempDir: string, pluginDriver: PluginDriver);
|
|
61
|
+
get extensions(): readonly string[];
|
|
61
62
|
init(): Promise<void>;
|
|
62
63
|
addRoute(routeInfo: RouteMeta): void;
|
|
63
64
|
removeRoute(filePath: string): void;
|
|
@@ -66,6 +67,7 @@ declare class RouteService {
|
|
|
66
67
|
isEmpty(): boolean;
|
|
67
68
|
generateRoutesCode(isStaticImport?: boolean): string;
|
|
68
69
|
generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[], isStaticImport: boolean): string;
|
|
70
|
+
getRoutePathParts(routePath: string): readonly [string, string, string];
|
|
69
71
|
normalizeRoutePath(routePath: string): {
|
|
70
72
|
routePath: string;
|
|
71
73
|
lang: string;
|
package/dist/loader.js
CHANGED
|
@@ -16,6 +16,7 @@ import * as __WEBPACK_EXTERNAL_MODULE_remark_gfm_073acf21__ from "remark-gfm";
|
|
|
16
16
|
import * as __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__ from "unist-util-visit";
|
|
17
17
|
import * as __WEBPACK_EXTERNAL_MODULE_github_slugger_8e9a17cb__ from "github-slugger";
|
|
18
18
|
import * as __WEBPACK_EXTERNAL_MODULE_hast_util_heading_rank_cff646ba__ from "hast-util-heading-rank";
|
|
19
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__ from "@rspress/shared/constants";
|
|
19
20
|
import * as __WEBPACK_EXTERNAL_MODULE_unist_util_visit_children_71921007__ from "unist-util-visit-children";
|
|
20
21
|
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
21
22
|
`{
|
|
@@ -23,6 +24,7 @@ const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
|
23
24
|
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
24
25
|
const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
|
|
25
26
|
document.documentElement.classList.toggle('dark', isDark)
|
|
27
|
+
document.documentElement.classList.toggle('rp-dark', isDark)
|
|
26
28
|
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
27
29
|
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
28
30
|
const dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(new URL(import.meta.url)));
|
|
@@ -173,8 +175,7 @@ const collectHeaderText = (node)=>{
|
|
|
173
175
|
child.value = textPart;
|
|
174
176
|
text += textPart;
|
|
175
177
|
id = idPart;
|
|
176
|
-
}
|
|
177
|
-
if ('element' === child.type) child.children.forEach((c)=>{
|
|
178
|
+
} else if ('element' === child.type) child.children.forEach((c)=>{
|
|
178
179
|
if ('text' === c.type) text += c.value;
|
|
179
180
|
});
|
|
180
181
|
});
|
|
@@ -242,7 +243,7 @@ function checkLinks(links, filepath, root, routeService) {
|
|
|
242
243
|
const errorInfos = [];
|
|
243
244
|
links.filter((link)=>!IGNORE_REGEXP.test(link)).map((link)=>normalizePath(link)).forEach((link)=>{
|
|
244
245
|
const relativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, filepath);
|
|
245
|
-
if (!routeService.isExistRoute((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.cleanUrl)(link))) errorInfos.push(`Internal link to ${link} is dead, check it in ${relativePath}`);
|
|
246
|
+
if (!routeService.isExistRoute((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.cleanUrl)(link))) errorInfos.push(`Internal link to "${link}" is dead, check it in "${relativePath}"`);
|
|
246
247
|
});
|
|
247
248
|
if (errorInfos.length > 0) {
|
|
248
249
|
null == errorInfos || errorInfos.forEach((err)=>{
|
|
@@ -258,7 +259,7 @@ const remarkCheckDeadLinks = (checkLink)=>{
|
|
|
258
259
|
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'link', ({ url })=>{
|
|
259
260
|
if (!url) return;
|
|
260
261
|
if (internalLinks.has(url)) return;
|
|
261
|
-
if (!url.startsWith('http') && !url.startsWith('https')) {
|
|
262
|
+
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
|
262
263
|
var _url_split_join;
|
|
263
264
|
const { routePath: normalizeUrl } = routeService.normalizeRoutePath(null === (_url_split_join = url.split(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].sep).join('/')) || void 0 === _url_split_join ? void 0 : _url_split_join.split('#')[0]);
|
|
264
265
|
internalLinks.add(normalizeUrl);
|
|
@@ -267,7 +268,7 @@ const remarkCheckDeadLinks = (checkLink)=>{
|
|
|
267
268
|
checkLinks(Array.from(internalLinks), vfile.path, root, routeService);
|
|
268
269
|
};
|
|
269
270
|
};
|
|
270
|
-
const remarkPluginNormalizeLink = ({
|
|
271
|
+
const remarkPluginNormalizeLink = ({ root, cleanUrls, routeService })=>(tree, file)=>{
|
|
271
272
|
const images = [];
|
|
272
273
|
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'link', (node)=>{
|
|
273
274
|
if (!node.url) return;
|
|
@@ -281,12 +282,19 @@ const remarkPluginNormalizeLink = ({ base, root, cleanUrls })=>(tree, file)=>{
|
|
|
281
282
|
return;
|
|
282
283
|
}
|
|
283
284
|
const extname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(url);
|
|
284
|
-
if (
|
|
285
|
+
if (((null == routeService ? void 0 : routeService.extensions) ?? __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS).includes(extname)) url = url.replace(new RegExp(`\\${extname}$`), '');
|
|
285
286
|
const relativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, file.path);
|
|
286
287
|
if (url.startsWith('.')) url = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].posix.join((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(relativePath)), url);
|
|
288
|
+
else if (routeService) {
|
|
289
|
+
const [pathVersion, pathLang] = routeService.getRoutePathParts((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(relativePath));
|
|
290
|
+
const [urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
|
|
291
|
+
url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)(urlPath);
|
|
292
|
+
if (pathLang && urlLang !== pathLang) url = `/${pathLang}${url}`;
|
|
293
|
+
if (pathVersion && urlVersion !== pathVersion) url = `/${pathVersion}${url}`;
|
|
294
|
+
}
|
|
287
295
|
url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeHref)(url, cleanUrls);
|
|
288
296
|
if (hash) url += `#${hash}`;
|
|
289
|
-
node.url =
|
|
297
|
+
node.url = url;
|
|
290
298
|
});
|
|
291
299
|
const normalizeImageUrl = (imageUrl)=>{
|
|
292
300
|
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(imageUrl) || imageUrl.startsWith('/')) return '';
|
|
@@ -338,12 +346,12 @@ const remarkPluginNormalizeLink = ({ base, root, cleanUrls })=>(tree, file)=>{
|
|
|
338
346
|
});
|
|
339
347
|
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, (node)=>{
|
|
340
348
|
if ('mdxJsxFlowElement' !== node.type && 'mdxJsxTextElement' !== node.type || 'img' !== node.name) return;
|
|
341
|
-
const
|
|
342
|
-
if ('string' != typeof
|
|
343
|
-
const imagePath = normalizeImageUrl(
|
|
349
|
+
const srcAttr = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'src', true);
|
|
350
|
+
if ('string' != typeof (null == srcAttr ? void 0 : srcAttr.value)) return;
|
|
351
|
+
const imagePath = normalizeImageUrl(srcAttr.value);
|
|
344
352
|
if (!imagePath) return;
|
|
345
353
|
const tempVariableName = `image${images.length}`;
|
|
346
|
-
Object.assign(
|
|
354
|
+
Object.assign(srcAttr, getMdxSrcAttribute(tempVariableName));
|
|
347
355
|
images.push(getASTNodeImport(tempVariableName, imagePath));
|
|
348
356
|
});
|
|
349
357
|
tree.children.unshift(...images);
|
|
@@ -427,7 +435,6 @@ async function createMDXOptions(docDirectory, config, checkDeadLinks, routeServi
|
|
|
427
435
|
}),
|
|
428
436
|
...globalComponentsFromConfig
|
|
429
437
|
];
|
|
430
|
-
const defaultLang = (null == config ? void 0 : config.lang) || '';
|
|
431
438
|
return {
|
|
432
439
|
providerImportSource: '@mdx-js/react',
|
|
433
440
|
format: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(filepath).slice(1),
|
|
@@ -437,10 +444,9 @@ async function createMDXOptions(docDirectory, config, checkDeadLinks, routeServi
|
|
|
437
444
|
[
|
|
438
445
|
remarkPluginNormalizeLink,
|
|
439
446
|
{
|
|
440
|
-
base: (null == config ? void 0 : config.base) || '',
|
|
441
447
|
cleanUrls,
|
|
442
|
-
|
|
443
|
-
|
|
448
|
+
root: docDirectory,
|
|
449
|
+
routeService
|
|
444
450
|
}
|
|
445
451
|
],
|
|
446
452
|
checkDeadLinks && [
|
package/dist/runtime/App.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import { type PageData } from '@rspress/shared';
|
|
2
1
|
import 'virtual-global-styles';
|
|
3
|
-
export declare enum QueryStatus {
|
|
4
|
-
Show = "1",
|
|
5
|
-
Hide = "0"
|
|
6
|
-
}
|
|
7
|
-
export declare function initPageData(routePath: string): Promise<PageData>;
|
|
8
2
|
export declare function App({ helmetContext }: {
|
|
9
3
|
helmetContext?: object;
|
|
10
4
|
}): import("react/jsx-runtime").JSX.Element;
|
package/dist/runtime/App.js
CHANGED
|
@@ -1,73 +1,11 @@
|
|
|
1
1
|
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
|
|
2
2
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress/runtime";
|
|
3
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
|
|
4
3
|
import * as __WEBPACK_EXTERNAL_MODULE__theme_75e53063__ from "@theme";
|
|
5
4
|
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
6
5
|
import * as __WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__ from "react-helmet-async";
|
|
7
6
|
import * as __WEBPACK_EXTERNAL_MODULE_virtual_global_components_43dbb356__ from "virtual-global-components";
|
|
8
|
-
import * as __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__ from "virtual-site-data";
|
|
9
7
|
import "virtual-global-styles";
|
|
10
|
-
|
|
11
|
-
QueryStatus["Show"] = "1";
|
|
12
|
-
QueryStatus["Hide"] = "0";
|
|
13
|
-
return QueryStatus;
|
|
14
|
-
}({});
|
|
15
|
-
async function initPageData(routePath) {
|
|
16
|
-
var _siteData_multiVersion;
|
|
17
|
-
const matchedRoute = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.pathnameToRouteService)(routePath);
|
|
18
|
-
if (matchedRoute) {
|
|
19
|
-
var _mod_default___RSPRESS_PAGE_META;
|
|
20
|
-
const mod = await matchedRoute.preload();
|
|
21
|
-
const pagePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.cleanUrl)(matchedRoute.filePath);
|
|
22
|
-
const extractPageInfo = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].pages.find((page)=>{
|
|
23
|
-
const normalize = (p)=>p.replace(/\/$/, '').toLowerCase();
|
|
24
|
-
return (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.isEqualPath)(normalize(page.routePath), normalize(matchedRoute.path));
|
|
25
|
-
});
|
|
26
|
-
const encodedPagePath = encodeURIComponent(pagePath);
|
|
27
|
-
const meta = (null === (_mod_default___RSPRESS_PAGE_META = mod.default.__RSPRESS_PAGE_META) || void 0 === _mod_default___RSPRESS_PAGE_META ? void 0 : _mod_default___RSPRESS_PAGE_META[encodedPagePath]) || {};
|
|
28
|
-
const { toc = [], title = '', frontmatter = {}, ...rest } = __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_OR_MD_REGEXP.test(matchedRoute.filePath) ? meta : mod;
|
|
29
|
-
return {
|
|
30
|
-
siteData: __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"],
|
|
31
|
-
page: {
|
|
32
|
-
...rest,
|
|
33
|
-
pagePath,
|
|
34
|
-
...extractPageInfo,
|
|
35
|
-
pageType: (null == frontmatter ? void 0 : frontmatter.pageType) || 'doc',
|
|
36
|
-
title,
|
|
37
|
-
frontmatter,
|
|
38
|
-
toc
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
let lang = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].lang || '';
|
|
43
|
-
let version = (null === (_siteData_multiVersion = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].multiVersion) || void 0 === _siteData_multiVersion ? void 0 : _siteData_multiVersion.default) || '';
|
|
44
|
-
if (__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].lang && 'undefined' != typeof window) {
|
|
45
|
-
const path = location.pathname.replace(__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].base, '').split('/').slice(0, 2);
|
|
46
|
-
if (__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].locales.length) {
|
|
47
|
-
const result = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].locales.find(({ lang })=>path.includes(lang));
|
|
48
|
-
if (result) lang = result.lang;
|
|
49
|
-
}
|
|
50
|
-
if (__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].multiVersion.versions) {
|
|
51
|
-
const result = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].multiVersion.versions.find((version)=>path.includes(version));
|
|
52
|
-
if (result) version = result;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
siteData: __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"],
|
|
57
|
-
page: {
|
|
58
|
-
pagePath: '',
|
|
59
|
-
pageType: '404',
|
|
60
|
-
routePath: '/404',
|
|
61
|
-
lang,
|
|
62
|
-
frontmatter: {},
|
|
63
|
-
title: '404',
|
|
64
|
-
toc: [],
|
|
65
|
-
version,
|
|
66
|
-
_filepath: '',
|
|
67
|
-
_relativePath: ''
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
8
|
+
import * as __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__ from "./initPageData.js";
|
|
71
9
|
function App({ helmetContext }) {
|
|
72
10
|
const { setData: setPageData, data } = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.DataContext);
|
|
73
11
|
const frontmatter = data.page.frontmatter || {};
|
|
@@ -78,7 +16,7 @@ function App({ helmetContext }) {
|
|
|
78
16
|
(0, __WEBPACK_EXTERNAL_MODULE_react__.useLayoutEffect)(()=>{
|
|
79
17
|
async function refetchData() {
|
|
80
18
|
try {
|
|
81
|
-
const pageData = await initPageData(pathname);
|
|
19
|
+
const pageData = await (0, __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__.initPageData)(pathname);
|
|
82
20
|
null == setPageData || setPageData(pageData);
|
|
83
21
|
} catch (e) {
|
|
84
22
|
console.log(e);
|
|
@@ -108,4 +46,4 @@ function App({ helmetContext }) {
|
|
|
108
46
|
]
|
|
109
47
|
});
|
|
110
48
|
}
|
|
111
|
-
export { App
|
|
49
|
+
export { App };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ClientApp(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress/runtime";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE__theme_75e53063__ from "@theme";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__ from "./App.js";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__ from "./initPageData.js";
|
|
7
|
+
function ClientApp() {
|
|
8
|
+
const [data, setData] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(null);
|
|
9
|
+
const [theme, setTheme] = (0, __WEBPACK_EXTERNAL_MODULE__theme_75e53063__.useThemeState)();
|
|
10
|
+
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
11
|
+
(0, __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__.initPageData)(window.location.pathname).then((pageData)=>{
|
|
12
|
+
setData(pageData);
|
|
13
|
+
});
|
|
14
|
+
}, []);
|
|
15
|
+
const themeValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
|
|
16
|
+
theme,
|
|
17
|
+
setTheme
|
|
18
|
+
}), [
|
|
19
|
+
theme,
|
|
20
|
+
setTheme
|
|
21
|
+
]);
|
|
22
|
+
const dataValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
|
|
23
|
+
data,
|
|
24
|
+
setData
|
|
25
|
+
}), [
|
|
26
|
+
data,
|
|
27
|
+
setData
|
|
28
|
+
]);
|
|
29
|
+
if (!data) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.Fragment, {});
|
|
30
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.ThemeContext.Provider, {
|
|
31
|
+
value: themeValue,
|
|
32
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.DataContext.Provider, {
|
|
33
|
+
value: dataValue,
|
|
34
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.BrowserRouter, {
|
|
35
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__.App, {})
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export { ClientApp };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export {};
|
|
@@ -1,73 +1,18 @@
|
|
|
1
|
-
import * as __WEBPACK_EXTERNAL_MODULE_react_dom_7136dc57__ from "react-dom";
|
|
2
|
-
import * as __WEBPACK_EXTERNAL_MODULE_react_dom_client_76b1397c__ from "react-dom/client";
|
|
3
1
|
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
|
|
4
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress/runtime";
|
|
5
2
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
|
|
6
|
-
import * as __WEBPACK_EXTERNAL_MODULE__theme_75e53063__ from "@theme";
|
|
7
|
-
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
8
3
|
import * as __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__ from "virtual-site-data";
|
|
9
|
-
import * as
|
|
10
|
-
var __webpack_modules__ = {
|
|
11
|
-
"react-dom": function(module) {
|
|
12
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_react_dom_7136dc57__;
|
|
13
|
-
},
|
|
14
|
-
"react-dom/client": function(module) {
|
|
15
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_react_dom_client_76b1397c__;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
var __webpack_module_cache__ = {};
|
|
19
|
-
function __webpack_require__(moduleId) {
|
|
20
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
21
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
22
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
23
|
-
exports: {}
|
|
24
|
-
};
|
|
25
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
26
|
-
return module.exports;
|
|
27
|
-
}
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__ from "./ClientApp.js";
|
|
28
5
|
const enableSSG = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].ssg;
|
|
29
6
|
async function renderInBrowser() {
|
|
30
7
|
const container = document.getElementById('root');
|
|
31
|
-
const enhancedApp = async ()=>{
|
|
32
|
-
const initialPageData = await (0, __WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__.initPageData)(window.location.pathname);
|
|
33
|
-
return function() {
|
|
34
|
-
const [data, setData] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(initialPageData);
|
|
35
|
-
const [theme, setTheme] = (0, __WEBPACK_EXTERNAL_MODULE__theme_75e53063__.useThemeState)();
|
|
36
|
-
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.ThemeContext.Provider, {
|
|
37
|
-
value: (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
|
|
38
|
-
theme,
|
|
39
|
-
setTheme
|
|
40
|
-
}), [
|
|
41
|
-
theme,
|
|
42
|
-
setTheme
|
|
43
|
-
]),
|
|
44
|
-
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.DataContext.Provider, {
|
|
45
|
-
value: (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
|
|
46
|
-
data,
|
|
47
|
-
setData
|
|
48
|
-
}), [
|
|
49
|
-
data,
|
|
50
|
-
setData
|
|
51
|
-
]),
|
|
52
|
-
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.BrowserRouter, {
|
|
53
|
-
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__.App, {})
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
const RootApp = await enhancedApp();
|
|
60
8
|
if (process.env.__REACT_GTE_18__) {
|
|
61
|
-
const { createRoot, hydrateRoot } =
|
|
62
|
-
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isProduction)() && enableSSG) hydrateRoot(container, /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(
|
|
63
|
-
else createRoot(container).render(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(
|
|
9
|
+
const { createRoot, hydrateRoot } = await import("react-dom/client");
|
|
10
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isProduction)() && enableSSG) hydrateRoot(container, /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__.ClientApp, {}));
|
|
11
|
+
else createRoot(container).render(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__.ClientApp, {}));
|
|
64
12
|
} else {
|
|
65
|
-
const ReactDOM =
|
|
66
|
-
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isProduction)()) ReactDOM.hydrate(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(
|
|
67
|
-
else ReactDOM.render(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(
|
|
13
|
+
const ReactDOM = await import("react-dom");
|
|
14
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isProduction)()) ReactDOM.hydrate(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__.ClientApp, {}), container);
|
|
15
|
+
else ReactDOM.render(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__.ClientApp, {}), container);
|
|
68
16
|
}
|
|
69
17
|
}
|
|
70
|
-
renderInBrowser()
|
|
71
|
-
(0, __WEBPACK_EXTERNAL_MODULE__theme_75e53063__.setup)();
|
|
72
|
-
});
|
|
73
|
-
export { renderInBrowser };
|
|
18
|
+
renderInBrowser();
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress/runtime";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
|
|
3
|
+
import "virtual-global-styles";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__ from "virtual-site-data";
|
|
5
|
+
async function initPageData(routePath) {
|
|
6
|
+
var _siteData_multiVersion;
|
|
7
|
+
const matchedRoute = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.pathnameToRouteService)(routePath);
|
|
8
|
+
if (matchedRoute) {
|
|
9
|
+
var _mod_default___RSPRESS_PAGE_META;
|
|
10
|
+
const mod = await matchedRoute.preload();
|
|
11
|
+
const pagePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.cleanUrl)(matchedRoute.filePath);
|
|
12
|
+
const normalize = (p)=>p.replace(/\/$/, '').toLowerCase();
|
|
13
|
+
const extractPageInfo = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].pages.find((page)=>(0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.isEqualPath)(normalize(page.routePath), normalize(matchedRoute.path)));
|
|
14
|
+
const encodedPagePath = encodeURIComponent(pagePath);
|
|
15
|
+
const meta = (null === (_mod_default___RSPRESS_PAGE_META = mod.default.__RSPRESS_PAGE_META) || void 0 === _mod_default___RSPRESS_PAGE_META ? void 0 : _mod_default___RSPRESS_PAGE_META[encodedPagePath]) || {};
|
|
16
|
+
const { toc = [], title = '', frontmatter = {}, ...rest } = __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_OR_MD_REGEXP.test(matchedRoute.filePath) ? meta : mod;
|
|
17
|
+
return {
|
|
18
|
+
siteData: __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"],
|
|
19
|
+
page: {
|
|
20
|
+
...rest,
|
|
21
|
+
pagePath,
|
|
22
|
+
...extractPageInfo,
|
|
23
|
+
pageType: (null == frontmatter ? void 0 : frontmatter.pageType) || 'doc',
|
|
24
|
+
title,
|
|
25
|
+
frontmatter,
|
|
26
|
+
toc
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
let lang = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].lang || '';
|
|
31
|
+
let version = (null === (_siteData_multiVersion = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].multiVersion) || void 0 === _siteData_multiVersion ? void 0 : _siteData_multiVersion.default) || '';
|
|
32
|
+
if (__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].lang && 'undefined' != typeof window) {
|
|
33
|
+
const path = location.pathname.replace(__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].base, '').split('/').slice(0, 2);
|
|
34
|
+
if (__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].locales.length) {
|
|
35
|
+
const result = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].locales.find(({ lang })=>path.includes(lang));
|
|
36
|
+
if (result) lang = result.lang;
|
|
37
|
+
}
|
|
38
|
+
if (__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].multiVersion.versions) {
|
|
39
|
+
const result = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].multiVersion.versions.find((version)=>path.includes(version));
|
|
40
|
+
if (result) version = result;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
siteData: __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"],
|
|
45
|
+
page: {
|
|
46
|
+
pagePath: '',
|
|
47
|
+
pageType: '404',
|
|
48
|
+
routePath: '/404',
|
|
49
|
+
lang,
|
|
50
|
+
frontmatter: {},
|
|
51
|
+
title: '404',
|
|
52
|
+
toc: [],
|
|
53
|
+
version,
|
|
54
|
+
_filepath: '',
|
|
55
|
+
_relativePath: ''
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export { initPageData };
|
package/dist/runtime/ssrEntry.js
CHANGED
|
@@ -3,10 +3,11 @@ import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress
|
|
|
3
3
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_server_673c713a__ from "@rspress/runtime/server";
|
|
4
4
|
import * as __WEBPACK_EXTERNAL_MODULE_react_dom_server_98c38d5c__ from "react-dom/server";
|
|
5
5
|
import * as __WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__ from "./App.js";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__ from "./initPageData.js";
|
|
6
7
|
import * as __WEBPACK_EXTERNAL_MODULE_virtual_routes_ssr_f802e6e5__ from "virtual-routes-ssr";
|
|
7
8
|
const DEFAULT_THEME = 'light';
|
|
8
9
|
async function render(pagePath, helmetContext) {
|
|
9
|
-
const initialPageData = await (0,
|
|
10
|
+
const initialPageData = await (0, __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__.initPageData)(pagePath);
|
|
10
11
|
const appHtml = (0, __WEBPACK_EXTERNAL_MODULE_react_dom_server_98c38d5c__.renderToString)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.ThemeContext.Provider, {
|
|
11
12
|
value: {
|
|
12
13
|
theme: DEFAULT_THEME
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.10",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -42,64 +42,66 @@
|
|
|
42
42
|
"theme.ts"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@mdx-js/loader": "
|
|
46
|
-
"@mdx-js/mdx": "
|
|
47
|
-
"@mdx-js/react": "
|
|
48
|
-
"@rsbuild/core": "1.
|
|
49
|
-
"@rsbuild/plugin-less": "~1.1.1",
|
|
45
|
+
"@mdx-js/loader": "^3.1.0",
|
|
46
|
+
"@mdx-js/mdx": "^3.1.0",
|
|
47
|
+
"@mdx-js/react": "^3.1.0",
|
|
48
|
+
"@rsbuild/core": "1.3.4",
|
|
50
49
|
"@rsbuild/plugin-react": "~1.1.1",
|
|
51
|
-
"@rsbuild/plugin-sass": "~1.2.2",
|
|
52
50
|
"@rspress/mdx-rs": "0.6.6",
|
|
53
51
|
"enhanced-resolve": "5.18.1",
|
|
54
52
|
"github-slugger": "^2.0.0",
|
|
55
53
|
"hast-util-from-html": "^2.0.3",
|
|
56
|
-
"hast-util-heading-rank": "^
|
|
54
|
+
"hast-util-heading-rank": "^3.0.0",
|
|
57
55
|
"html-to-text": "^9.0.5",
|
|
58
56
|
"htmr": "^1.0.2",
|
|
59
57
|
"lodash-es": "^4.17.21",
|
|
60
|
-
"mdast-util-mdxjs-esm": "^
|
|
61
|
-
"memfs": "^4.17.0",
|
|
58
|
+
"mdast-util-mdxjs-esm": "^2.0.1",
|
|
62
59
|
"picocolors": "^1.1.1",
|
|
63
60
|
"react": "^18.3.1",
|
|
64
61
|
"react-dom": "^18.3.1",
|
|
65
|
-
"react-helmet-async": "^
|
|
62
|
+
"react-helmet-async": "^2.0.5",
|
|
66
63
|
"react-lazy-with-preload": "^2.2.1",
|
|
67
64
|
"react-syntax-highlighter": "^15.6.1",
|
|
68
65
|
"rehype-external-links": "^3.0.0",
|
|
69
|
-
"remark": "^
|
|
70
|
-
"remark-gfm": "
|
|
66
|
+
"remark": "^15.0.1",
|
|
67
|
+
"remark-gfm": "^4.0.1",
|
|
71
68
|
"rspack-plugin-virtual-module": "0.1.13",
|
|
72
69
|
"tinyglobby": "^0.2.12",
|
|
73
|
-
"unified": "^
|
|
74
|
-
"unist-util-visit": "^
|
|
75
|
-
"unist-util-visit-children": "^
|
|
76
|
-
"@rspress/plugin-auto-nav-sidebar": "2.0.0-alpha.
|
|
77
|
-
"@rspress/plugin-container-syntax": "2.0.0-alpha.
|
|
78
|
-
"@rspress/plugin-last-updated": "2.0.0-alpha.
|
|
79
|
-
"@rspress/plugin-medium-zoom": "2.0.0-alpha.
|
|
80
|
-
"@rspress/runtime": "2.0.0-alpha.
|
|
81
|
-
"@rspress/shared": "2.0.0-alpha.
|
|
82
|
-
"@rspress/theme-default": "2.0.0-alpha.
|
|
70
|
+
"unified": "^11.0.5",
|
|
71
|
+
"unist-util-visit": "^5.0.0",
|
|
72
|
+
"unist-util-visit-children": "^3.0.0",
|
|
73
|
+
"@rspress/plugin-auto-nav-sidebar": "2.0.0-alpha.10",
|
|
74
|
+
"@rspress/plugin-container-syntax": "2.0.0-alpha.10",
|
|
75
|
+
"@rspress/plugin-last-updated": "2.0.0-alpha.10",
|
|
76
|
+
"@rspress/plugin-medium-zoom": "2.0.0-alpha.10",
|
|
77
|
+
"@rspress/runtime": "2.0.0-alpha.10",
|
|
78
|
+
"@rspress/shared": "2.0.0-alpha.10",
|
|
79
|
+
"@rspress/theme-default": "2.0.0-alpha.10"
|
|
83
80
|
},
|
|
84
81
|
"devDependencies": {
|
|
85
|
-
"@microsoft/api-extractor": "^7.
|
|
86
|
-
"@rslib/core": "0.
|
|
82
|
+
"@microsoft/api-extractor": "^7.52.3",
|
|
83
|
+
"@rslib/core": "0.6.1",
|
|
87
84
|
"@rspress-dev/plugin-preview": "link:../plugin-preview",
|
|
88
|
-
"@types/hast": "^
|
|
85
|
+
"@types/hast": "^3.0.4",
|
|
89
86
|
"@types/html-to-text": "^9.0.4",
|
|
90
87
|
"@types/jest": "~29.5.14",
|
|
91
88
|
"@types/lodash-es": "^4.17.12",
|
|
92
|
-
"@types/mdast": "^
|
|
89
|
+
"@types/mdast": "^4.0.4",
|
|
93
90
|
"@types/node": "^18.11.17",
|
|
94
|
-
"@types/react": "^18.3.
|
|
95
|
-
"@types/react-dom": "^18.3.
|
|
91
|
+
"@types/react": "^18.3.20",
|
|
92
|
+
"@types/react-dom": "^18.3.6",
|
|
93
|
+
"memfs": "^4.17.0",
|
|
96
94
|
"postcss": "8.5.3",
|
|
97
|
-
"rehype-stringify": "^
|
|
98
|
-
"remark-
|
|
99
|
-
"remark-
|
|
95
|
+
"rehype-stringify": "^10.0.1",
|
|
96
|
+
"remark-mdx": "^3.1.0",
|
|
97
|
+
"remark-parse": "^11.0.0",
|
|
98
|
+
"remark-rehype": "^11.1.2",
|
|
99
|
+
"remark-stringify": "^11.0.0",
|
|
100
100
|
"rimraf": "^6.0.1",
|
|
101
|
+
"rsbuild-plugin-virtual-module": "0.1.1",
|
|
101
102
|
"tailwindcss": "^3.4.17",
|
|
102
|
-
"typescript": "^5.
|
|
103
|
+
"typescript": "^5.8.2",
|
|
104
|
+
"vfile": "^5.3.7",
|
|
103
105
|
"@rspress/config": "1.0.0"
|
|
104
106
|
},
|
|
105
107
|
"engines": {
|