@rspress/core 1.41.3 → 1.43.0-canary-20240224
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 +1 -3
- package/dist/index.js +55 -19
- package/dist/runtime/App.js +6 -8
- package/dist/runtime/clientEntry.js +4 -8
- package/package.json +8 -8
- package/src/runtime/App.tsx +19 -18
- package/src/runtime/clientEntry.tsx +5 -11
- package/theme.ts +0 -1
package/dist/193.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -8,6 +8,8 @@ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_less_4c557a99__ from "@rsb
|
|
|
8
8
|
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__ from "@rsbuild/plugin-react";
|
|
9
9
|
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_sass_b13a7d33__ from "@rsbuild/plugin-sass";
|
|
10
10
|
import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
|
|
11
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
12
|
+
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
11
13
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__ from "@rspress/shared/constants";
|
|
12
14
|
import * as __WEBPACK_EXTERNAL_MODULE_tinyglobby__ from "tinyglobby";
|
|
13
15
|
import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
|
|
@@ -22,8 +24,6 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
|
22
24
|
import * as __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__ from "@mdx-js/mdx";
|
|
23
25
|
import * as __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__ from "enhanced-resolve";
|
|
24
26
|
import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
|
|
25
|
-
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
26
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
27
27
|
export * from "@rspress/shared";
|
|
28
28
|
var __webpack_modules__ = {};
|
|
29
29
|
var __webpack_module_cache__ = {};
|
|
@@ -330,6 +330,48 @@ const BODY_START_TAG = '<body';
|
|
|
330
330
|
const DEFAULT_TITLE = 'Rspress';
|
|
331
331
|
const PUBLIC_DIR = 'public';
|
|
332
332
|
const TEMP_DIR = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'node_modules', __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR);
|
|
333
|
+
async function pathExists(path) {
|
|
334
|
+
try {
|
|
335
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].access(path);
|
|
336
|
+
return true;
|
|
337
|
+
} catch {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
async function readJson(path) {
|
|
342
|
+
const raw = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(path, 'utf8');
|
|
343
|
+
return JSON.parse(raw);
|
|
344
|
+
}
|
|
345
|
+
const THEME_DEFAULT_EXPORT_PATTERN = /export default \{(.*?)\}/m;
|
|
346
|
+
async function hintThemeBreakingChange(customThemeDir) {
|
|
347
|
+
const fileList = [
|
|
348
|
+
'index.ts',
|
|
349
|
+
'index.tsx',
|
|
350
|
+
'index.js',
|
|
351
|
+
'index.mjs'
|
|
352
|
+
];
|
|
353
|
+
let useDefaultExportFilePath;
|
|
354
|
+
for (const file of fileList){
|
|
355
|
+
const filePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(customThemeDir, file);
|
|
356
|
+
if (await pathExists(filePath)) {
|
|
357
|
+
const content = await (0, __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__.readFile)(filePath, {
|
|
358
|
+
encoding: 'utf-8'
|
|
359
|
+
});
|
|
360
|
+
if (THEME_DEFAULT_EXPORT_PATTERN.test(content)) useDefaultExportFilePath = filePath;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (useDefaultExportFilePath) __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.warn(`[Rspress] Theme breaking change: The theme/index is now using namedExports instead of defaultExports, please update your config file in ${useDefaultExportFilePath}`, __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].red(`
|
|
364
|
+
- import Theme from '@rspress/theme-default';
|
|
365
|
+
- export default {
|
|
366
|
+
- ...Theme,
|
|
367
|
+
- Layout,
|
|
368
|
+
- };
|
|
369
|
+
- export * from 'rspress/theme';`) + __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].green(`+ import { Layout } from '@rspress/theme-default';
|
|
370
|
+
|
|
371
|
+
+ export { Layout };
|
|
372
|
+
+ export * from 'rspress/theme';
|
|
373
|
+
`));
|
|
374
|
+
}
|
|
333
375
|
const isWindows = 'win32' === __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__["default"].platform();
|
|
334
376
|
function slash(p) {
|
|
335
377
|
return p.replace(/\\/g, '/');
|
|
@@ -804,14 +846,20 @@ async function extractPageData(replaceRules, alias, domain, root, routeService,
|
|
|
804
846
|
applyReplaceRulesToNestedObject(frontmatter, replaceRules);
|
|
805
847
|
const { flattenContent } = await flattenMdxContent(applyReplaceRules(strippedFrontMatter, replaceRules), route.absolutePath, alias);
|
|
806
848
|
content = flattenContent.replace(importStatementRegex, '');
|
|
807
|
-
const { html, title, toc: rawToc, languages } = await (0, __WEBPACK_EXTERNAL_MODULE__rspress_mdx_rs_d2f3021f__.compile)({
|
|
849
|
+
const { html: rawHtml, title, toc: rawToc, languages } = await (0, __WEBPACK_EXTERNAL_MODULE__rspress_mdx_rs_d2f3021f__.compile)({
|
|
808
850
|
value: content,
|
|
809
851
|
filepath: route.absolutePath,
|
|
810
852
|
development: 'production' !== process.env.NODE_ENV,
|
|
811
853
|
root
|
|
812
854
|
});
|
|
813
855
|
if (!(null == title ? void 0 : title.length) && !frontmatter && !(null === (_frontmatter_title = frontmatter.title) || void 0 === _frontmatter_title ? void 0 : _frontmatter_title.length)) return null;
|
|
814
|
-
|
|
856
|
+
function encodeHtml(html) {
|
|
857
|
+
return html.replace(/<code>([\s\S]*?)<\/\s?code>/gm, function(_match, innerContent) {
|
|
858
|
+
return `<code>${innerContent.replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>')}</code>`;
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
const html = encodeHtml(String(rawHtml));
|
|
862
|
+
content = (0, __WEBPACK_EXTERNAL_MODULE_html_to_text_2c51ed38__.htmlToText)(html, {
|
|
815
863
|
wordwrap: 80,
|
|
816
864
|
selectors: [
|
|
817
865
|
{
|
|
@@ -1211,18 +1259,6 @@ function serveSearchIndexMiddleware(config) {
|
|
|
1211
1259
|
} else null == next || next();
|
|
1212
1260
|
};
|
|
1213
1261
|
}
|
|
1214
|
-
async function pathExists(path) {
|
|
1215
|
-
try {
|
|
1216
|
-
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].access(path);
|
|
1217
|
-
return true;
|
|
1218
|
-
} catch {
|
|
1219
|
-
return false;
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
async function readJson(path) {
|
|
1223
|
-
const raw = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(path, 'utf8');
|
|
1224
|
-
return JSON.parse(raw);
|
|
1225
|
-
}
|
|
1226
1262
|
const { CachedInputFileSystem: detectReactVersion_CachedInputFileSystem, ResolverFactory: detectReactVersion_ResolverFactory } = __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__["default"];
|
|
1227
1263
|
const DEFAULT_REACT_VERSION = 18;
|
|
1228
1264
|
async function detectReactVersion() {
|
|
@@ -1338,6 +1374,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1338
1374
|
if (__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].isAbsolute(icon)) return __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(userDocRoot, PUBLIC_DIR, icon);
|
|
1339
1375
|
return icon;
|
|
1340
1376
|
};
|
|
1377
|
+
await hintThemeBreakingChange(CUSTOM_THEME_DIR);
|
|
1341
1378
|
const [detectCustomIconAlias, reactCSRAlias, reactSSRAlias] = await Promise.all([
|
|
1342
1379
|
detectCustomIcon(CUSTOM_THEME_DIR),
|
|
1343
1380
|
resolveReactAlias(reactVersion, false),
|
|
@@ -1406,11 +1443,10 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1406
1443
|
CUSTOM_THEME_DIR,
|
|
1407
1444
|
DEFAULT_THEME
|
|
1408
1445
|
],
|
|
1409
|
-
'
|
|
1446
|
+
'@theme-assets': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(DEFAULT_THEME, '../assets'),
|
|
1410
1447
|
'@rspress/core': PACKAGE_ROOT,
|
|
1411
1448
|
'react-lazy-with-preload': require.resolve('react-lazy-with-preload'),
|
|
1412
|
-
'react-syntax-highlighter': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(require.resolve('react-syntax-highlighter/package.json'))
|
|
1413
|
-
'@theme-assets': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(DEFAULT_THEME, '../assets')
|
|
1449
|
+
'react-syntax-highlighter': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(require.resolve('react-syntax-highlighter/package.json'))
|
|
1414
1450
|
}
|
|
1415
1451
|
},
|
|
1416
1452
|
source: {
|
package/dist/runtime/App.js
CHANGED
|
@@ -14,16 +14,14 @@ var App_rslib_entry_QueryStatus = /*#__PURE__*/ function(QueryStatus) {
|
|
|
14
14
|
}({});
|
|
15
15
|
async function initPageData(routePath) {
|
|
16
16
|
var _siteData_multiVersion;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
if (matched) {
|
|
17
|
+
const matchedRoute = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.pathnameToRouteService)(routePath);
|
|
18
|
+
if (matchedRoute) {
|
|
20
19
|
var _mod_default___RSPRESS_PAGE_META;
|
|
21
|
-
const matchedRoute = matched[0].route;
|
|
22
20
|
const mod = await matchedRoute.preload();
|
|
23
|
-
const pagePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.cleanUrl)(
|
|
21
|
+
const pagePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.cleanUrl)(matchedRoute.filePath);
|
|
24
22
|
const extractPageInfo = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].pages.find((page)=>{
|
|
25
23
|
const normalize = (p)=>p.replace(/\/$/, '').toLowerCase();
|
|
26
|
-
return (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.isEqualPath)(normalize(page.routePath), normalize(
|
|
24
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.isEqualPath)(normalize(page.routePath), normalize(matchedRoute.path));
|
|
27
25
|
});
|
|
28
26
|
const encodedPagePath = encodeURIComponent(pagePath);
|
|
29
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]) || {};
|
|
@@ -80,7 +78,7 @@ function App({ helmetContext }) {
|
|
|
80
78
|
(0, __WEBPACK_EXTERNAL_MODULE_react__.useLayoutEffect)(()=>{
|
|
81
79
|
async function refetchData() {
|
|
82
80
|
try {
|
|
83
|
-
const pageData = await initPageData(
|
|
81
|
+
const pageData = await initPageData(pathname);
|
|
84
82
|
setPageData(pageData);
|
|
85
83
|
} catch (e) {
|
|
86
84
|
console.log(e);
|
|
@@ -94,7 +92,7 @@ function App({ helmetContext }) {
|
|
|
94
92
|
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__.HelmetProvider, {
|
|
95
93
|
context: helmetContext,
|
|
96
94
|
children: [
|
|
97
|
-
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__
|
|
95
|
+
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__.Layout, {}),
|
|
98
96
|
!hideGlobalUIComponents && __WEBPACK_EXTERNAL_MODULE_virtual_global_components_43dbb356__["default"].map((componentInfo, index)=>{
|
|
99
97
|
if (Array.isArray(componentInfo)) {
|
|
100
98
|
const [component, props] = componentInfo;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import * as __WEBPACK_EXTERNAL_MODULE__theme_75e53063__ from "@theme";
|
|
2
1
|
import * as __WEBPACK_EXTERNAL_MODULE_react_dom_7136dc57__ from "react-dom";
|
|
3
2
|
import * as __WEBPACK_EXTERNAL_MODULE_react_dom_client_76b1397c__ from "react-dom/client";
|
|
4
3
|
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
|
|
5
4
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress/runtime";
|
|
6
5
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__theme_75e53063__ from "@theme";
|
|
7
7
|
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
8
8
|
import * as __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__ from "virtual-site-data";
|
|
9
9
|
import * as __WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__ from "./App.js";
|
|
10
10
|
var __webpack_modules__ = {
|
|
11
|
-
"@theme": function(module) {
|
|
12
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE__theme_75e53063__;
|
|
13
|
-
},
|
|
14
11
|
"react-dom": function(module) {
|
|
15
12
|
module.exports = __WEBPACK_EXTERNAL_MODULE_react_dom_7136dc57__;
|
|
16
13
|
},
|
|
@@ -29,14 +26,13 @@ function __webpack_require__(moduleId) {
|
|
|
29
26
|
return module.exports;
|
|
30
27
|
}
|
|
31
28
|
const enableSSG = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].ssg;
|
|
32
|
-
const { default: Theme, useThemeState } = __webpack_require__("@theme");
|
|
33
29
|
async function renderInBrowser() {
|
|
34
30
|
const container = document.getElementById('root');
|
|
35
31
|
const enhancedApp = async ()=>{
|
|
36
|
-
const initialPageData = await (0, __WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__.initPageData)(
|
|
32
|
+
const initialPageData = await (0, __WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__.initPageData)(window.location.pathname);
|
|
37
33
|
return function() {
|
|
38
34
|
const [data, setData] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(initialPageData);
|
|
39
|
-
const [theme, setTheme] = useThemeState();
|
|
35
|
+
const [theme, setTheme] = (0, __WEBPACK_EXTERNAL_MODULE__theme_75e53063__.useThemeState)();
|
|
40
36
|
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.ThemeContext.Provider, {
|
|
41
37
|
value: (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
|
|
42
38
|
theme,
|
|
@@ -72,6 +68,6 @@ async function renderInBrowser() {
|
|
|
72
68
|
}
|
|
73
69
|
}
|
|
74
70
|
renderInBrowser().then(()=>{
|
|
75
|
-
|
|
71
|
+
(0, __WEBPACK_EXTERNAL_MODULE__theme_75e53063__.setup)();
|
|
76
72
|
});
|
|
77
73
|
export { renderInBrowser };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.43.0-canary-20240224",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -78,13 +78,13 @@
|
|
|
78
78
|
"unified": "^10.1.2",
|
|
79
79
|
"unist-util-visit": "^4.1.2",
|
|
80
80
|
"unist-util-visit-children": "^3.0.0",
|
|
81
|
-
"@rspress/plugin-auto-nav-sidebar": "1.
|
|
82
|
-
"@rspress/plugin-
|
|
83
|
-
"@rspress/
|
|
84
|
-
"@rspress/
|
|
85
|
-
"@rspress/plugin-
|
|
86
|
-
"@rspress/shared": "1.
|
|
87
|
-
"@rspress/theme-default": "1.
|
|
81
|
+
"@rspress/plugin-auto-nav-sidebar": "1.43.0-canary-20240224",
|
|
82
|
+
"@rspress/plugin-last-updated": "1.43.0-canary-20240224",
|
|
83
|
+
"@rspress/runtime": "1.43.0-canary-20240224",
|
|
84
|
+
"@rspress/plugin-medium-zoom": "1.43.0-canary-20240224",
|
|
85
|
+
"@rspress/plugin-container-syntax": "1.43.0-canary-20240224",
|
|
86
|
+
"@rspress/shared": "1.43.0-canary-20240224",
|
|
87
|
+
"@rspress/theme-default": "1.43.0-canary-20240224"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@microsoft/api-extractor": "^7.49.2",
|
package/src/runtime/App.tsx
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DataContext,
|
|
3
3
|
isEqualPath,
|
|
4
|
-
|
|
5
|
-
normalizeRoutePath,
|
|
4
|
+
pathnameToRouteService,
|
|
6
5
|
useLocation,
|
|
7
6
|
} from '@rspress/runtime';
|
|
8
7
|
import {
|
|
@@ -11,7 +10,7 @@ import {
|
|
|
11
10
|
type PageData,
|
|
12
11
|
cleanUrl,
|
|
13
12
|
} from '@rspress/shared';
|
|
14
|
-
import
|
|
13
|
+
import { Layout } from '@theme';
|
|
15
14
|
import React, { useContext, useLayoutEffect } from 'react';
|
|
16
15
|
import { HelmetProvider } from 'react-helmet-async';
|
|
17
16
|
import globalComponents from 'virtual-global-components';
|
|
@@ -31,32 +30,32 @@ type PageMeta = {
|
|
|
31
30
|
};
|
|
32
31
|
|
|
33
32
|
export async function initPageData(routePath: string): Promise<PageData> {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
((await import('virtual-routes-ssr')) as typeof import(
|
|
37
|
-
'virtual-routes-ssr'
|
|
38
|
-
))
|
|
39
|
-
: ((await import('virtual-routes')) as typeof import('virtual-routes'));
|
|
40
|
-
const matched = matchRoutes(routes, routePath)!;
|
|
41
|
-
if (matched) {
|
|
33
|
+
const matchedRoute = pathnameToRouteService(routePath)!;
|
|
34
|
+
if (matchedRoute) {
|
|
42
35
|
// Preload route component
|
|
43
|
-
const matchedRoute = matched[0].route;
|
|
44
36
|
const mod = await matchedRoute.preload();
|
|
45
|
-
const pagePath = cleanUrl(
|
|
37
|
+
const pagePath = cleanUrl(matchedRoute.filePath);
|
|
46
38
|
const extractPageInfo = siteData.pages.find(page => {
|
|
47
39
|
const normalize = (p: string) =>
|
|
48
40
|
// compat the path that has no / suffix and ignore case
|
|
49
41
|
p
|
|
50
42
|
.replace(/\/$/, '')
|
|
51
43
|
.toLowerCase();
|
|
52
|
-
return isEqualPath(
|
|
44
|
+
return isEqualPath(
|
|
45
|
+
normalize(page.routePath),
|
|
46
|
+
normalize(matchedRoute.path),
|
|
47
|
+
);
|
|
53
48
|
});
|
|
54
49
|
|
|
55
50
|
// FIXME: when sidebar item is configured as link string, the sidebar text won't updated when page title changed
|
|
56
51
|
// Reason: The sidebar item text depends on pageData, which is not updated when page title changed, because the pageData is computed once when build
|
|
57
52
|
const encodedPagePath = encodeURIComponent(pagePath);
|
|
58
53
|
const meta: PageMeta =
|
|
59
|
-
|
|
54
|
+
(
|
|
55
|
+
mod.default as unknown as {
|
|
56
|
+
__RSPRESS_PAGE_META: Record<string, PageMeta>;
|
|
57
|
+
}
|
|
58
|
+
).__RSPRESS_PAGE_META?.[encodedPagePath] || ({} as PageMeta);
|
|
60
59
|
// mdx loader will generate __RSPRESS_PAGE_META,
|
|
61
60
|
// if the filePath don't match it, we can get meta from j(t)sx if we customize it
|
|
62
61
|
const {
|
|
@@ -64,7 +63,9 @@ export async function initPageData(routePath: string): Promise<PageData> {
|
|
|
64
63
|
title = '',
|
|
65
64
|
frontmatter = {},
|
|
66
65
|
...rest
|
|
67
|
-
} = MDX_REGEXP.test(matchedRoute.filePath)
|
|
66
|
+
} = MDX_REGEXP.test(matchedRoute.filePath)
|
|
67
|
+
? meta
|
|
68
|
+
: (mod as unknown as PageMeta);
|
|
68
69
|
return {
|
|
69
70
|
siteData,
|
|
70
71
|
page: {
|
|
@@ -138,7 +139,7 @@ export function App({ helmetContext }: { helmetContext?: object }) {
|
|
|
138
139
|
useLayoutEffect(() => {
|
|
139
140
|
async function refetchData() {
|
|
140
141
|
try {
|
|
141
|
-
const pageData = await initPageData(
|
|
142
|
+
const pageData = await initPageData(pathname);
|
|
142
143
|
setPageData(pageData);
|
|
143
144
|
} catch (e) {
|
|
144
145
|
console.log(e);
|
|
@@ -149,7 +150,7 @@ export function App({ helmetContext }: { helmetContext?: object }) {
|
|
|
149
150
|
|
|
150
151
|
return (
|
|
151
152
|
<HelmetProvider context={helmetContext}>
|
|
152
|
-
<
|
|
153
|
+
<Layout />
|
|
153
154
|
{
|
|
154
155
|
// Global UI
|
|
155
156
|
!hideGlobalUIComponents &&
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BrowserRouter,
|
|
3
|
-
DataContext,
|
|
4
|
-
ThemeContext,
|
|
5
|
-
normalizeRoutePath,
|
|
6
|
-
} from '@rspress/runtime';
|
|
1
|
+
import { BrowserRouter, DataContext, ThemeContext } from '@rspress/runtime';
|
|
7
2
|
import { isProduction } from '@rspress/shared';
|
|
3
|
+
import { setup, useThemeState } from '@theme';
|
|
8
4
|
import { useMemo, useState } from 'react';
|
|
9
5
|
import siteData from 'virtual-site-data';
|
|
10
6
|
import { App, initPageData } from './App';
|
|
@@ -12,15 +8,13 @@ import { App, initPageData } from './App';
|
|
|
12
8
|
const enableSSG = siteData.ssg;
|
|
13
9
|
|
|
14
10
|
// eslint-disable-next-line import/no-commonjs
|
|
15
|
-
const { default: Theme, useThemeState } = require('@theme');
|
|
16
11
|
|
|
17
12
|
export async function renderInBrowser() {
|
|
18
13
|
const container = document.getElementById('root')!;
|
|
19
14
|
|
|
20
15
|
const enhancedApp = async () => {
|
|
21
|
-
const initialPageData = await initPageData(
|
|
22
|
-
|
|
23
|
-
);
|
|
16
|
+
const initialPageData = await initPageData(window.location.pathname);
|
|
17
|
+
|
|
24
18
|
return function RootApp() {
|
|
25
19
|
const [data, setData] = useState(initialPageData);
|
|
26
20
|
const [theme, setTheme] = useThemeState();
|
|
@@ -58,5 +52,5 @@ export async function renderInBrowser() {
|
|
|
58
52
|
}
|
|
59
53
|
|
|
60
54
|
renderInBrowser().then(() => {
|
|
61
|
-
|
|
55
|
+
setup();
|
|
62
56
|
});
|
package/theme.ts
CHANGED