Skip to content

Commit 97d9b89

Browse files
committed
chore: update
1 parent 9ad688a commit 97d9b89

File tree

18 files changed

+53
-92
lines changed

18 files changed

+53
-92
lines changed

packages/core/src/node/initRsbuild.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { globalStylesVMPlugin } from './runtimeModule/globalStyles';
4040
import { globalUIComponentsVMPlugin } from './runtimeModule/globalUIComponents';
4141
import { i18nVMPlugin } from './runtimeModule/i18n';
4242
import { routeListVMPlugin } from './runtimeModule/routeList';
43+
import { runtimeConfigVMPlugin } from './runtimeModule/runtimeConfig';
4344
import { searchHookVMPlugin } from './runtimeModule/searchHooks';
4445
import type { FactoryContext } from './runtimeModule/types';
4546
import { serveSearchIndexMiddleware } from './searchIndex';
@@ -149,6 +150,11 @@ async function createInternalBuildConfig(
149150
* Get virtual modules from plugins
150151
*/
151152
...(await getVirtualModulesFromPlugins(pluginDriver)),
153+
154+
/**
155+
* Serialize rspress.config.ts to runtime
156+
*/
157+
...runtimeConfigVMPlugin(context),
152158
},
153159
}),
154160
...(enableSSG

packages/core/src/node/route/RouteService.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ export class RouteService {
5050

5151
#exclude: string[] = [];
5252

53-
#base: string = '';
54-
5553
#tempDir: string = '';
5654

5755
#pluginDriver: PluginDriver;
@@ -94,7 +92,6 @@ export class RouteService {
9492
userConfig?.themeConfig?.locales ??
9593
[]
9694
).map(item => item.lang);
97-
this.#base = userConfig?.base || '';
9895
this.#tempDir = tempDir;
9996
this.#pluginDriver = pluginDriver;
10097

@@ -239,7 +236,6 @@ ${routeMeta
239236
getRoutePathParts(routePath: string) {
240237
return getRoutePathParts(
241238
routePath,
242-
this.#base,
243239
this.#defaultLang,
244240
this.#defaultVersion,
245241
this.#langs,
@@ -250,7 +246,6 @@ ${routeMeta
250246
normalizeRoutePath(routePath: string) {
251247
return normalizeRoutePath(
252248
routePath,
253-
this.#base,
254249
this.#defaultLang,
255250
this.#defaultVersion,
256251
this.#langs,

packages/core/src/node/route/normalizeRoutePath.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { DEFAULT_PAGE_EXTENSIONS } from '@rspress/shared/constants';
33

44
export const getRoutePathParts = (
55
routePath: string,
6-
base: string,
76
lang: string,
87
version: string,
98
langs: string[],
@@ -40,7 +39,6 @@ export const getRoutePathParts = (
4039
purePathPart = parts.join('/');
4140

4241
return [
43-
base,
4442
versionPart,
4543
langPart,
4644
// restore the trail slash
@@ -50,16 +48,14 @@ export const getRoutePathParts = (
5048

5149
export const normalizeRoutePath = (
5250
routePath: string,
53-
base: string,
5451
lang: string,
5552
version: string,
5653
langs: string[],
5754
versions: string[],
5855
extensions: string[] = DEFAULT_PAGE_EXTENSIONS,
5956
) => {
60-
const [_, versionPart, langPart, purePathPart] = getRoutePathParts(
57+
const [versionPart, langPart, purePathPart] = getRoutePathParts(
6158
routePath,
62-
base,
6359
lang,
6460
version,
6561
langs,

packages/core/src/node/runtimeModule/siteData/normalizeThemeConfig.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
addLeadingSlash,
1414
isExternalUrl,
1515
slash,
16-
withoutBase,
1716
} from '@rspress/shared';
1817
import { applyReplaceRules } from '../../utils/applyReplaceRules';
1918
import { getI18nData } from '../i18n';
@@ -23,7 +22,6 @@ export function normalizeThemeConfig(
2322
): NormalizedDefaultThemeConfig {
2423
const {
2524
locales: siteLocales,
26-
base = '',
2725
lang,
2826
replaceRules = [],
2927
multiVersion,
@@ -40,9 +38,8 @@ export function normalizeThemeConfig(
4038
if (
4139
!currentLang ||
4240
!link ||
43-
withoutBase(normalizedLink, base).startsWith(`/${currentLang}`) ||
41+
normalizedLink.startsWith(`/${currentLang}`) ||
4442
isExternalUrl(normalizedLink) ||
45-
// In multi version case, we have got the complete link prefix in `auto-nav-sidebar` and does not need to add the lang prefix
4643
hasMultiVersion
4744
) {
4845
return normalizedLink;

packages/core/src/node/utils/normalizePath.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ function absolutePathToRoutePrefix(
4141
),
4242
);
4343
const routeService = RouteService.getInstance();
44-
const [basePrefix, versionPrefix, langPrefix] =
44+
const [_, versionPrefix, langPrefix] =
4545
routeService.getRoutePathParts(relativePath);
46-
return `${basePrefix}${versionPrefix ? `/${versionPrefix}` : ''}${langPrefix ? `/${langPrefix}` : ''}`;
46+
return `${versionPrefix ? `/${versionPrefix}` : ''}${langPrefix ? `/${langPrefix}` : ''}`;
4747
}
4848

4949
export function addRoutePrefix(

packages/core/src/runtime/ssrServerEntry.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { renderToPipeableStream } from 'react-dom/server';
1111
import { PassThrough } from 'node:stream';
1212
import { text } from 'node:stream/consumers';
1313
import type { ReactNode } from 'react';
14+
import { base } from 'virtual-runtime-config';
1415
import { App } from './App';
1516
import { initPageData } from './initPageData';
1617

@@ -46,7 +47,7 @@ export async function render(
4647
const appHtml = await renderToHtml(
4748
<ThemeContext.Provider value={{ theme: DEFAULT_THEME }}>
4849
<DataContext.Provider value={{ data: initialPageData }}>
49-
<StaticRouter location={pagePath}>
50+
<StaticRouter location={pagePath} basename={base}>
5051
<UnheadProvider value={head}>
5152
<App />
5253
</UnheadProvider>

packages/runtime/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export function removeBase(url: string): string {
2222

2323
export function isEqualPath(a: string, b: string) {
2424
return (
25-
withBase(normalizeHrefInRuntime(removeHash(a))) ===
26-
withBase(normalizeHrefInRuntime(removeHash(b)))
25+
removeBase(normalizeHrefInRuntime(removeHash(a))) ===
26+
removeBase(normalizeHrefInRuntime(removeHash(b)))
2727
);
2828
}
2929

packages/shared/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,5 @@ export {
3434
replaceVersion,
3535
slash,
3636
withBase,
37-
withoutBase,
3837
withoutLang,
3938
} from './runtime-utils/utils';

packages/shared/src/runtime-utils/sidebar.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import type { NavItemWithLink, NormalizedSidebar } from '../types/defaultTheme';
2-
import { withBase, withoutBase } from './utils';
3-
import { addTrailingSlash } from './utils';
42

53
/**
64
* match the sidebar key in user config
@@ -10,22 +8,20 @@ import { addTrailingSlash } from './utils';
108
export const matchSidebar = (
119
pattern: string,
1210
currentPathname: string,
13-
base: string,
1411
): boolean => {
15-
const prefix = withBase(pattern, base);
16-
if (prefix === currentPathname) {
12+
if (pattern === currentPathname) {
1713
return true;
1814
}
19-
const prefixWithTrailingSlash = addTrailingSlash(prefix);
20-
if (currentPathname.startsWith(prefixWithTrailingSlash)) {
15+
16+
if (currentPathname.startsWith(pattern)) {
2117
return true;
2218
}
2319

2420
// be compatible with api-extractor
2521
// '/api/react': [
2622
// { link: '/api/react.use' }
2723
// ]
28-
const prefixWithDot = `${prefix}.`;
24+
const prefixWithDot = `${pattern}.`;
2925
return currentPathname.startsWith(prefixWithDot);
3026
};
3127

@@ -38,7 +34,6 @@ export const matchSidebar = (
3834
export const getSidebarDataGroup = (
3935
sidebar: NormalizedSidebar,
4036
currentPathname: string,
41-
base: string,
4237
): NormalizedSidebar[string] => {
4338
/**
4439
* why sort?
@@ -54,7 +49,7 @@ export const getSidebarDataGroup = (
5449
*/
5550
const navRoutes = Object.keys(sidebar).sort((a, b) => b.length - a.length);
5651
for (const name of navRoutes) {
57-
if (matchSidebar(name, currentPathname, base)) {
52+
if (matchSidebar(name, currentPathname)) {
5853
const sidebarGroup = sidebar[name];
5954
return sidebarGroup;
6055
}
@@ -65,9 +60,6 @@ export const getSidebarDataGroup = (
6560
export const matchNavbar = (
6661
item: NavItemWithLink,
6762
currentPathname: string,
68-
base: string,
6963
): boolean => {
70-
return new RegExp(item.activeMatch || item.link).test(
71-
withoutBase(currentPathname, base),
72-
);
64+
return new RegExp(item.activeMatch || item.link).test(currentPathname);
7365
};

packages/shared/src/runtime-utils/utils.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {
33
normalizeHref,
44
normalizePosixPath,
55
parseUrl,
6+
removeBase,
67
replaceLang,
78
replaceVersion,
89
withBase,
9-
withoutBase,
1010
withoutLang,
1111
} from './utils';
1212

@@ -29,10 +29,10 @@ describe('test shared utils', () => {
2929
expect(secondResult).toBe('/my-base/guide/');
3030
});
3131

32-
test('withoutBase', () => {
33-
expect(withoutBase('/zh/guide/', '/zh/')).toBe('/guide/');
34-
expect(withoutBase('/guide/', '/')).toBe('/guide/');
35-
expect(withoutBase('/guide/', '')).toBe('/guide/');
32+
test('removeBase', () => {
33+
expect(removeBase('/zh/guide/', '/zh/')).toBe('/guide/');
34+
expect(removeBase('/guide/', '/')).toBe('/guide/');
35+
expect(removeBase('/guide/', '')).toBe('/guide/');
3636
});
3737

3838
test('normalizePosix', () => {

0 commit comments

Comments
 (0)