@rspress/core 2.1.0-beta.1 → 2.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/dist/cli/index.js +2 -2
  2. package/dist/config/loadConfigFile.js +1 -1
  3. package/dist/eject-theme/components/CdnTabs/index.test.tsx +71 -0
  4. package/dist/eject-theme/components/CdnTabs/index.tsx +175 -0
  5. package/dist/eject-theme/components/DocContent/index.tsx +0 -3
  6. package/dist/eject-theme/components/FallbackHeading/index.tsx +6 -1
  7. package/dist/eject-theme/components/Link/index.tsx +9 -18
  8. package/dist/eject-theme/components/Link/useLinkNavigate.ts +17 -3
  9. package/dist/eject-theme/components/NavTitle/index.test.tsx +78 -0
  10. package/dist/eject-theme/components/NavTitle/index.tsx +9 -5
  11. package/dist/eject-theme/components/PackageManagerTabs/index.test.tsx +79 -1
  12. package/dist/eject-theme/components/PackageManagerTabs/index.tsx +25 -12
  13. package/dist/eject-theme/components/Search/NoSearchResult.scss +1 -2
  14. package/dist/eject-theme/components/Search/SearchPanel.scss +75 -63
  15. package/dist/eject-theme/components/Search/SuggestItem.scss +28 -41
  16. package/dist/eject-theme/components/Sidebar/SidebarItem.scss +8 -0
  17. package/dist/eject-theme/components/Sidebar/SidebarSectionHeader.scss +3 -0
  18. package/dist/node/PluginDriver.d.ts +5 -0
  19. package/dist/node/PluginDriver.js +14 -5
  20. package/dist/node/auto-nav-sidebar/index.js +1 -1
  21. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  22. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  23. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  24. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  25. package/dist/node/constants.js +1 -1
  26. package/dist/node/eject.js +1 -1
  27. package/dist/node/initRsbuild.js +12 -4
  28. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -0
  29. package/dist/node/mdx/remarkPlugins/link.js +1 -1
  30. package/dist/node/route/RoutePage.js +1 -1
  31. package/dist/node/route/RouteService.js +1 -1
  32. package/dist/node/route/extractPageData.js +1 -1
  33. package/dist/node/route/normalizeRoutePath.js +1 -1
  34. package/dist/node/runtimeModule/i18n/getI18nData.d.ts +11 -0
  35. package/dist/node/runtimeModule/{i18n.js → i18n/getI18nData.js} +35 -22
  36. package/dist/node/runtimeModule/i18n/rsbuildPlugin.d.ts +5 -0
  37. package/dist/node/runtimeModule/i18n/rsbuildPlugin.js +21 -0
  38. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  39. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  40. package/dist/node/runtimeModule/searchHooks.js +1 -1
  41. package/dist/node/runtimeModule/siteData/createSiteData.d.ts +2 -1
  42. package/dist/node/runtimeModule/siteData/createSiteData.js +3 -3
  43. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.d.ts +2 -1
  44. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +3 -4
  45. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +2 -2
  46. package/dist/node/serve.js +1 -1
  47. package/dist/node/sitemap.d.ts +7 -2
  48. package/dist/node/sitemap.js +40 -57
  49. package/dist/node/ssg/alternateLinks.js +1 -1
  50. package/dist/node/ssg/htmlFile.js +1 -1
  51. package/dist/node/ssg/renderHtmlTemplate.js +1 -1
  52. package/dist/node/ssg/renderPage.js +1 -1
  53. package/dist/node/ssg/renderPageWorker.js +1 -1
  54. package/dist/node/ssg/renderPages.js +2 -2
  55. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  56. package/dist/node/ssg/ssgEnv.js +1 -1
  57. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  58. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  59. package/dist/node/ssg-md/renderPage.js +1 -1
  60. package/dist/node/ssg-md/renderPages.js +2 -2
  61. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  62. package/dist/node/utils/checkLanguageParity.js +1 -1
  63. package/dist/node/utils/createHash.js +1 -1
  64. package/dist/node/utils/flattenMdxContent.js +1 -1
  65. package/dist/node/utils/getPageKey.js +1 -1
  66. package/dist/node/utils/reactAlias.js +2 -2
  67. package/dist/{h~0.js → p~0.js} +6 -4
  68. package/dist/runtime/App.js +14 -10
  69. package/dist/runtime/BrowserOnly.d.ts +1 -1
  70. package/dist/runtime/BrowserOnly.js +53 -20
  71. package/dist/runtime/ClientApp.js +4 -0
  72. package/dist/runtime/NoSSR.d.ts +7 -3
  73. package/dist/runtime/NoSSR.js +30 -9
  74. package/dist/runtime/PageRoute.js +20 -8
  75. package/dist/runtime/index.d.ts +3 -2
  76. package/dist/runtime/index.js +3 -4
  77. package/dist/runtime/react.d.ts +5 -0
  78. package/dist/runtime/react.js +4 -0
  79. package/dist/runtime/reactDom.d.ts +6 -0
  80. package/dist/runtime/reactDom.js +2 -1
  81. package/dist/runtime/socialLinks.d.ts +1 -0
  82. package/dist/runtime/socialLinks.js +3 -0
  83. package/dist/theme/assets/bun.js +101 -0
  84. package/dist/theme/assets/deno.js +15 -0
  85. package/dist/theme/assets/jsdelivr.js +53 -0
  86. package/dist/theme/{components/PackageManagerTabs/icons/Npm.js → assets/npm.js} +4 -4
  87. package/dist/theme/{components/PackageManagerTabs/icons/Pnpm.js → assets/pnpm.js} +4 -4
  88. package/dist/theme/assets/unpkg.js +15 -0
  89. package/dist/theme/assets/yarn.js +22 -0
  90. package/dist/theme/components/CdnTabs/index.d.ts +10 -0
  91. package/dist/theme/components/CdnTabs/index.js +146 -0
  92. package/dist/theme/components/DocContent/index.js +1 -2
  93. package/dist/theme/components/FallbackHeading/index.js +1 -0
  94. package/dist/theme/components/Link/index.js +4 -13
  95. package/dist/theme/components/Link/useLinkNavigate.js +12 -4
  96. package/dist/theme/components/NavTitle/index.js +10 -5
  97. package/dist/theme/components/PackageManagerTabs/index.d.ts +2 -0
  98. package/dist/theme/components/PackageManagerTabs/index.js +22 -12
  99. package/dist/theme/components/Search/NoSearchResult.css +1 -2
  100. package/dist/theme/components/Search/SearchPanel.css +72 -51
  101. package/dist/theme/components/Search/SuggestItem.css +21 -34
  102. package/dist/theme/components/Sidebar/SidebarItem.css +5 -0
  103. package/dist/theme/components/Sidebar/SidebarSectionHeader.css +1 -0
  104. package/dist/theme/hooks/useDynamicToc.js +27 -34
  105. package/dist/theme/icons.d.ts +7 -0
  106. package/dist/theme/icons.js +15 -1
  107. package/dist/theme/index.d.ts +1 -2
  108. package/dist/theme/index.js +1 -2
  109. package/dist/theme/layout/Layout/index.js +1 -2
  110. package/dist/y~0.js +166 -0
  111. package/package.json +13 -13
  112. package/dist/b~0.js +0 -104
  113. package/dist/eject-theme/components/PackageManagerTabs/icons/Bun.tsx +0 -101
  114. package/dist/eject-theme/components/PackageManagerTabs/icons/Deno.tsx +0 -18
  115. package/dist/eject-theme/components/PackageManagerTabs/icons/Npm.tsx +0 -16
  116. package/dist/eject-theme/components/PackageManagerTabs/icons/Pnpm.tsx +0 -22
  117. package/dist/eject-theme/components/PackageManagerTabs/icons/Yarn.tsx +0 -18
  118. package/dist/node/runtimeModule/i18n.d.ts +0 -8
  119. package/dist/theme/components/PackageManagerTabs/icons/Bun.d.ts +0 -2
  120. package/dist/theme/components/PackageManagerTabs/icons/Bun.js +0 -137
  121. package/dist/theme/components/PackageManagerTabs/icons/Deno.d.ts +0 -2
  122. package/dist/theme/components/PackageManagerTabs/icons/Deno.js +0 -15
  123. package/dist/theme/components/PackageManagerTabs/icons/Npm.d.ts +0 -2
  124. package/dist/theme/components/PackageManagerTabs/icons/Pnpm.d.ts +0 -2
  125. package/dist/theme/components/PackageManagerTabs/icons/Yarn.d.ts +0 -2
  126. package/dist/theme/components/PackageManagerTabs/icons/Yarn.js +0 -22
  127. package/dist/theme/logic/useScrollAfterNav.d.ts +0 -5
  128. package/dist/theme/logic/useScrollAfterNav.js +0 -35
  129. package/dist/theme/logic/useScrollReset.d.ts +0 -5
  130. package/dist/theme/logic/useScrollReset.js +0 -12
  131. package/dist/tu~0.js +0 -3
  132. /package/dist/node/runtimeModule/{DEFAULT_I18N_TEXT.d.ts → i18n/DEFAULT_I18N_TEXT.d.ts} +0 -0
  133. /package/dist/node/runtimeModule/{DEFAULT_I18N_TEXT.js → i18n/DEFAULT_I18N_TEXT.js} +0 -0
package/dist/cli/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { logger, cac } from "../h~0.js";
2
- import { package_namespaceObject } from "../b~0.js";
1
+ import { logger, cac } from "../p~0.js";
2
+ import { package_namespaceObject } from "../y~0.js";
3
3
  import { loadConfigFile, resolveDocRoot } from "../config/loadConfigFile.js";
4
4
  import { dev } from "../node/dev.js";
5
5
  import { build } from "../node/build.js";
@@ -1,4 +1,4 @@
1
- import { node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../h~0.js";
1
+ import { node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../p~0.js";
2
2
  async function loadConfigFile(customConfigFile) {
3
3
  const { loadConfig } = await import("@rsbuild/core");
4
4
  const result = await loadConfig({
@@ -0,0 +1,71 @@
1
+ import { afterEach, describe, expect, it, rs } from '@rstest/core';
2
+ import type { ReactNode } from 'react';
3
+ import { renderToMarkdownString } from 'react-render-to-markdown';
4
+ import { CdnTabs } from './index';
5
+
6
+ rs.mock('@rspress/core/theme', () => ({
7
+ getCustomMDXComponent: () => ({
8
+ pre: 'pre',
9
+ }),
10
+ Tab: ({ children }: { children: ReactNode }) => children,
11
+ Tabs: ({ children }: { children: ReactNode }) => children,
12
+ }));
13
+
14
+ const originalSsgMd = import.meta.env.SSG_MD;
15
+
16
+ const setSsgMd = (value: boolean | undefined) => {
17
+ if (value === undefined) {
18
+ delete (import.meta.env as unknown as Record<string, unknown>).SSG_MD;
19
+ return;
20
+ }
21
+
22
+ (import.meta.env as unknown as Record<string, unknown>).SSG_MD = value;
23
+ };
24
+
25
+ afterEach(() => {
26
+ setSsgMd(originalSsgMd);
27
+ });
28
+
29
+ describe('CdnTabs', () => {
30
+ it('renders CSS and JavaScript tags for the default CDNs in SSG markdown', async () => {
31
+ setSsgMd(true);
32
+
33
+ const markdown = await renderToMarkdownString(
34
+ <CdnTabs
35
+ package="bootstrap@5"
36
+ files={['dist/css/bootstrap.min.css', 'dist/js/bootstrap.min.js']}
37
+ />,
38
+ );
39
+
40
+ expect(markdown).toContain('```html [jsDelivr]');
41
+ expect(markdown).toContain(
42
+ '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5/dist/css/bootstrap.min.css" />',
43
+ );
44
+ expect(markdown).toContain(
45
+ '<script src="https://unpkg.com/bootstrap@5/dist/js/bootstrap.min.js"></script>',
46
+ );
47
+ expect(markdown).toContain('```html [unpkg]');
48
+ });
49
+
50
+ it('supports scoped packages and a custom CDN order', async () => {
51
+ setSsgMd(true);
52
+
53
+ const markdown = await renderToMarkdownString(
54
+ <CdnTabs
55
+ package="@scope/package@5"
56
+ files={['dist/bundle.js']}
57
+ cdns={['unpkg', 'jsdelivr']}
58
+ />,
59
+ );
60
+
61
+ expect(markdown.indexOf('```html [unpkg]')).toBeLessThan(
62
+ markdown.indexOf('```html [jsDelivr]'),
63
+ );
64
+ expect(markdown).toContain(
65
+ '<script src="https://unpkg.com/@scope/package@5/dist/bundle.js"></script>',
66
+ );
67
+ expect(markdown).toContain(
68
+ '<script src="https://cdn.jsdelivr.net/npm/@scope/package@5/dist/bundle.js"></script>',
69
+ );
70
+ });
71
+ });
@@ -0,0 +1,175 @@
1
+ import {
2
+ getCustomMDXComponent,
3
+ IconJsdelivr,
4
+ IconUnpkg,
5
+ SvgWrapper,
6
+ Tab,
7
+ Tabs,
8
+ } from '@rspress/core/theme';
9
+ import { Fragment, useMemo } from 'react';
10
+
11
+ export type CdnName = 'jsdelivr' | 'unpkg';
12
+
13
+ export type CdnTabsProps = {
14
+ /** Package name and version, e.g. `bootstrap@5`. */
15
+ package: string;
16
+ /** CSS and JavaScript asset paths within the package. */
17
+ files: ReadonlyArray<string>;
18
+ /** CDNs to display, in tab order. Defaults to jsDelivr and unpkg. */
19
+ cdns?: ReadonlyArray<CdnName>;
20
+ };
21
+
22
+ const DEFAULT_CDNS: ReadonlyArray<CdnName> = ['jsdelivr', 'unpkg'];
23
+
24
+ const CDN_INFO: Record<CdnName, { label: string; baseUrl: string }> = {
25
+ jsdelivr: {
26
+ label: 'jsDelivr',
27
+ baseUrl: 'https://cdn.jsdelivr.net/npm/',
28
+ },
29
+ unpkg: {
30
+ label: 'unpkg',
31
+ baseUrl: 'https://unpkg.com/',
32
+ },
33
+ };
34
+
35
+ function encodePath(path: string): string {
36
+ return path
37
+ .split('/')
38
+ .map(segment => encodeURIComponent(segment).replace(/%40/gi, '@'))
39
+ .join('/');
40
+ }
41
+
42
+ function getAssetUrl(cdn: CdnName, packageName: string, file: string): string {
43
+ return `${CDN_INFO[cdn].baseUrl}${encodePath(packageName)}/${encodePath(file)}`;
44
+ }
45
+
46
+ type AssetTag = {
47
+ tag: 'link' | 'script';
48
+ attributes: Record<string, string>;
49
+ };
50
+
51
+ function getAssetTags(
52
+ cdn: CdnName,
53
+ packageName: string,
54
+ files: ReadonlyArray<string>,
55
+ ): AssetTag[] {
56
+ return files.flatMap<AssetTag>(file => {
57
+ const url = getAssetUrl(cdn, packageName, file);
58
+ if (file.toLowerCase().endsWith('.css')) {
59
+ return [{ tag: 'link', attributes: { rel: 'stylesheet', href: url } }];
60
+ }
61
+ if (file.toLowerCase().endsWith('.js')) {
62
+ return [{ tag: 'script', attributes: { src: url } }];
63
+ }
64
+ return [];
65
+ });
66
+ }
67
+
68
+ function getHtmlSnippet(tags: AssetTag[]): string {
69
+ return tags
70
+ .map(({ tag, attributes }) => {
71
+ const attrs = Object.entries(attributes)
72
+ .map(([name, value]) => `${name}="${value}"`)
73
+ .join(' ');
74
+ return tag === 'link'
75
+ ? `<${tag} ${attrs} />`
76
+ : `<${tag} ${attrs}></${tag}>`;
77
+ })
78
+ .join('\n');
79
+ }
80
+
81
+ export function CdnTabs({
82
+ package: packageName,
83
+ files,
84
+ cdns = DEFAULT_CDNS,
85
+ }: CdnTabsProps) {
86
+ const Pre = useMemo(
87
+ () => getCustomMDXComponent().pre,
88
+ [getCustomMDXComponent],
89
+ );
90
+ const tabs = cdns.map(cdn => ({
91
+ cdn,
92
+ label: CDN_INFO[cdn].label,
93
+ tags: getAssetTags(cdn, packageName, files),
94
+ }));
95
+
96
+ if (import.meta.env.SSG_MD) {
97
+ return tabs
98
+ .map(
99
+ ({ label, tags }) =>
100
+ `\n\`\`\`html [${label}]\n${getHtmlSnippet(tags)}\n\`\`\`\n`,
101
+ )
102
+ .join('');
103
+ }
104
+
105
+ return (
106
+ <Tabs groupId="cdn">
107
+ {tabs.map(({ cdn, label, tags }) => (
108
+ <Tab
109
+ key={cdn}
110
+ value={cdn}
111
+ label={
112
+ <span style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
113
+ <SvgWrapper
114
+ icon={cdn === 'jsdelivr' ? IconJsdelivr : IconUnpkg}
115
+ width="1em"
116
+ height="1em"
117
+ aria-hidden="true"
118
+ />
119
+ {label}
120
+ </span>
121
+ }
122
+ >
123
+ <Pre
124
+ lang="html"
125
+ className="shiki css-variables"
126
+ style={{
127
+ backgroundColor: 'var(--shiki-background)',
128
+ color: 'var(--shiki-foreground)',
129
+ }}
130
+ >
131
+ <code style={{ whiteSpace: 'pre' }}>
132
+ {/* These generated tags have a fixed grammar, so highlight them directly. */}
133
+ {tags.map(({ tag, attributes }, index) => (
134
+ <Fragment key={index}>
135
+ {index > 0 ? '\n' : null}
136
+ <span className="line">
137
+ {'<'}
138
+ <span style={{ color: 'var(--shiki-token-keyword)' }}>
139
+ {tag}
140
+ </span>
141
+ {Object.entries(attributes).map(([name, value]) => (
142
+ <Fragment key={name}>
143
+ {' '}
144
+ <span style={{ color: 'var(--shiki-token-function)' }}>
145
+ {name}
146
+ </span>
147
+ {'='}
148
+ <span
149
+ style={{
150
+ color: 'var(--shiki-token-string-expression)',
151
+ }}
152
+ >{`"${value}"`}</span>
153
+ </Fragment>
154
+ ))}
155
+ {tag === 'link' ? (
156
+ ' />'
157
+ ) : (
158
+ <>
159
+ {'></'}
160
+ <span style={{ color: 'var(--shiki-token-keyword)' }}>
161
+ {tag}
162
+ </span>
163
+ {'>'}
164
+ </>
165
+ )}
166
+ </span>
167
+ </Fragment>
168
+ ))}
169
+ </code>
170
+ </Pre>
171
+ </Tab>
172
+ ))}
173
+ </Tabs>
174
+ );
175
+ }
@@ -4,7 +4,6 @@ import {
4
4
  Callout,
5
5
  FallbackHeading,
6
6
  getCustomMDXComponent,
7
- useScrollAfterNav,
8
7
  } from '@rspress/core/theme';
9
8
  import './doc.scss';
10
9
 
@@ -38,8 +37,6 @@ export function DocContent({
38
37
  */
39
38
  afterDocContent?: React.ReactNode;
40
39
  }) {
41
- useScrollAfterNav();
42
-
43
40
  const mdxComponents = {
44
41
  ...getCustomMDXComponent(),
45
42
  ...components,
@@ -50,7 +50,12 @@ export function FallbackHeading({
50
50
  titleSlug && (
51
51
  <Element id={titleSlug}>
52
52
  <span {...renderInlineMarkdown(title)}></span>
53
- <A className="rp-header-anchor" href={`#${titleSlug}`} aria-hidden>
53
+ <A
54
+ className="rp-header-anchor"
55
+ href={`#${titleSlug}`}
56
+ aria-hidden
57
+ tabIndex={-1}
58
+ >
54
59
  #
55
60
  </A>
56
61
  </Element>
@@ -73,22 +73,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
73
73
  );
74
74
  }
75
75
 
76
- if (linkType === 'hashOnly') {
77
- return (
78
- <a
79
- ref={ref}
80
- href={href}
81
- className={clsx(className, 'rp-link')}
82
- onClick={onClick}
83
- onMouseEnter={onMouseEnter}
84
- {...otherProps}
85
- >
86
- {children}
87
- </a>
88
- );
89
- }
90
-
91
- if (linkType === 'relative') {
76
+ if (linkType === 'hashOnly' || linkType === 'relative') {
92
77
  return (
93
78
  <a
94
79
  ref={ref}
@@ -96,14 +81,20 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
96
81
  className={clsx(className, 'rp-link')}
97
82
  onMouseEnter={event => {
98
83
  onMouseEnter?.(event);
99
- preloadLink(routePath);
84
+ if (linkType === 'relative') {
85
+ preloadLink(routePath);
86
+ }
100
87
  }}
101
88
  onTouchStart={() => {
102
- preloadLink(routePath);
89
+ if (linkType === 'relative') {
90
+ preloadLink(routePath);
91
+ }
103
92
  }}
104
93
  onClick={e => {
105
94
  onClick?.(e);
106
95
  if (
96
+ e.defaultPrevented ||
97
+ e.currentTarget.hasAttribute('download') ||
107
98
  // left click only
108
99
  e.button !== 0 ||
109
100
  // `target` are usually used for open link in new window/tab
@@ -26,13 +26,14 @@ export function useLinkNavigate({
26
26
  async (href: string) => {
27
27
  const { linkType, removeBaseHref, routePath, withBaseHref } =
28
28
  getHref(href);
29
- if (linkType === 'external' || linkType === 'hashOnly') {
29
+ if (linkType === 'external') {
30
30
  window.location.assign(href);
31
31
  return;
32
32
  }
33
33
  // Keep same-page links client-side, including on a 404 page, so clicking
34
34
  // a parent menu link does not reload the document and close its submenu.
35
35
  if (
36
+ linkType !== 'hashOnly' &&
36
37
  !isActive(removeBaseHref, pathname) &&
37
38
  !pathnameToRouteService(routePath)
38
39
  ) {
@@ -40,15 +41,28 @@ export function useLinkNavigate({
40
41
  return;
41
42
  }
42
43
 
44
+ // Native hash navigation creates history entries without router keys.
45
+ // Preserve the current query and let the router track each anchor visit.
46
+ const hashUrl =
47
+ linkType === 'hashOnly'
48
+ ? new URL(href, window.location.href)
49
+ : undefined;
50
+ const to = hashUrl
51
+ ? { search: hashUrl.search, hash: hashUrl.hash }
52
+ : removeBaseHref;
53
+ const options = hashUrl
54
+ ? { replace: hashUrl.href === window.location.href }
55
+ : undefined;
56
+
43
57
  if (useTransitions && startTransition) {
44
58
  let navigation: void | Promise<void> = undefined;
45
59
  startTransition(() => {
46
- navigation = navigate(removeBaseHref);
60
+ navigation = navigate(to, options);
47
61
  return navigation;
48
62
  });
49
63
  await navigation;
50
64
  } else {
51
- await navigate(removeBaseHref);
65
+ await navigate(to, options);
52
66
  }
53
67
  },
54
68
  [useTransitions, pathname, navigate, startTransition],
@@ -0,0 +1,78 @@
1
+ import type React from 'react';
2
+ import { afterEach, describe, expect, it, rs } from '@rstest/core';
3
+ import { renderToStaticMarkup } from 'react-dom/server';
4
+ import { NavTitle } from './index';
5
+
6
+ type Logo =
7
+ string | { dark: string; light: string; width?: number; height?: number };
8
+
9
+ const defaultSite = {
10
+ title: 'Rspress',
11
+ lang: 'en',
12
+ themeConfig: { locales: [] as { lang: string; title?: string }[] },
13
+ logo: '/logo.svg' as Logo,
14
+ logoText: '',
15
+ logoHref: '',
16
+ };
17
+
18
+ let site = defaultSite;
19
+ let lang = 'en';
20
+
21
+ rs.mock('@rspress/core/runtime', () => ({
22
+ addLeadingSlash: (path: string) => (path.startsWith('/') ? path : `/${path}`),
23
+ addTrailingSlash: (path: string) => (path.endsWith('/') ? path : `${path}/`),
24
+ normalizeImagePath: (path: string) => path,
25
+ useLang: () => lang,
26
+ useSite: () => ({ site }),
27
+ }));
28
+
29
+ rs.mock('@rspress/core/theme', () => ({
30
+ Link: ({
31
+ children,
32
+ className,
33
+ href,
34
+ }: {
35
+ children: React.ReactNode;
36
+ className?: string;
37
+ href: string;
38
+ }) => (
39
+ <a className={className} href={href}>
40
+ {children}
41
+ </a>
42
+ ),
43
+ }));
44
+
45
+ afterEach(() => {
46
+ site = defaultSite;
47
+ lang = 'en';
48
+ });
49
+
50
+ describe('NavTitle', () => {
51
+ it('uses the site title as the logo alt and applies configured image dimensions', () => {
52
+ site = {
53
+ ...defaultSite,
54
+ logo: {
55
+ light: '/logo-light.png',
56
+ dark: '/logo-dark.png',
57
+ width: 120,
58
+ height: 32,
59
+ },
60
+ };
61
+
62
+ const markup = renderToStaticMarkup(<NavTitle />);
63
+
64
+ expect(markup).toContain('alt="Rspress"');
65
+ expect(markup.match(/id="logo"/g)).toHaveLength(1);
66
+ expect(markup.match(/width="120"/g)).toHaveLength(2);
67
+ expect(markup.match(/height="32"/g)).toHaveLength(2);
68
+ });
69
+
70
+ it('marks the logo decorative when adjacent logo text names the link', () => {
71
+ site = { ...defaultSite, logoText: 'Rspress docs' };
72
+ const markup = renderToStaticMarkup(<NavTitle />);
73
+
74
+ expect(markup).toContain('alt=""');
75
+ expect(markup).toContain('>Rspress docs</span>');
76
+ expect(markup).not.toContain('alt="logo"');
77
+ });
78
+ });
@@ -22,6 +22,7 @@ export const NavTitle = () => {
22
22
  const langRoutePrefix = lang === defaultLang ? '/' : addTrailingSlash(lang);
23
23
 
24
24
  const { logo: rawLogo, logoText, logoHref } = site;
25
+ const alt = logoText ? '' : title;
25
26
  const logo = useMemo(() => {
26
27
  if (!rawLogo) {
27
28
  return null;
@@ -30,7 +31,7 @@ export const NavTitle = () => {
30
31
  return (
31
32
  <img
32
33
  src={normalizeImagePath(rawLogo)}
33
- alt="logo"
34
+ alt={alt}
34
35
  id="logo"
35
36
  className="rspress-logo rp-nav__title__logo-image"
36
37
  />
@@ -40,19 +41,22 @@ export const NavTitle = () => {
40
41
  <>
41
42
  <img
42
43
  src={normalizeImagePath(rawLogo.light)}
43
- alt="logo"
44
+ alt={alt}
44
45
  id="logo"
46
+ width={rawLogo.width}
47
+ height={rawLogo.height}
45
48
  className="rspress-logo rp-nav__title__logo-image rp-nav__title__logo-image--light"
46
49
  />
47
50
  <img
48
51
  src={normalizeImagePath(rawLogo.dark)}
49
- alt="logo"
50
- id="logo"
52
+ alt={alt}
53
+ width={rawLogo.width}
54
+ height={rawLogo.height}
51
55
  className="rspress-logo rp-nav__title__logo-image rp-nav__title__logo-image--dark"
52
56
  />
53
57
  </>
54
58
  );
55
- }, [rawLogo]);
59
+ }, [rawLogo, alt]);
56
60
 
57
61
  return (
58
62
  <div className="rp-nav__title">
@@ -1,12 +1,18 @@
1
1
  import { afterEach, describe, expect, it, rs } from '@rstest/core';
2
2
  import type { ReactNode } from 'react';
3
3
  import { renderToMarkdownString } from 'react-render-to-markdown';
4
- import { PackageManagerTabs } from './index';
4
+ import { PackageManagerTabs, type PackageManagerTabProps } from './index';
5
5
 
6
6
  rs.mock('@rspress/core/theme', () => ({
7
7
  getCustomMDXComponent: () => ({
8
8
  pre: 'pre',
9
9
  }),
10
+ IconBun: 'bun',
11
+ IconDeno: 'deno',
12
+ IconNpm: 'npm',
13
+ IconPnpm: 'pnpm',
14
+ IconYarn: 'yarn',
15
+ SvgWrapper: () => null,
10
16
  Tab: ({ children }: { children: ReactNode }) => children,
11
17
  Tabs: ({ children }: { children: ReactNode }) => children,
12
18
  }));
@@ -27,6 +33,78 @@ afterEach(() => {
27
33
  });
28
34
 
29
35
  describe('PackageManagerTabs', () => {
36
+ it.each<PackageManagerTabProps>([
37
+ { command: 'install -D @rspress/core' },
38
+ { command: 'rspress --help', exec: true },
39
+ { command: 'rspress --help', dlx: true },
40
+ ])('renders an additional tab command as written with %j', async props => {
41
+ setSsgMd(true);
42
+
43
+ const markdown = await renderToMarkdownString(
44
+ <PackageManagerTabs
45
+ {...props}
46
+ additionalTabs={[
47
+ { tool: 'custom', command: 'corepack pnpm add --dev @rspress/core' },
48
+ ]}
49
+ />,
50
+ );
51
+
52
+ expect(markdown).toContain(
53
+ '```sh [corepack]\ncorepack pnpm add --dev @rspress/core\n```',
54
+ );
55
+ expect(markdown).not.toContain('custom ');
56
+ });
57
+
58
+ it('keeps generating commands for additional tabs without an explicit command', async () => {
59
+ setSsgMd(true);
60
+
61
+ const markdown = await renderToMarkdownString(
62
+ <PackageManagerTabs
63
+ command="install -D @rspress/core"
64
+ additionalTabs={[{ tool: 'custom' }]}
65
+ />,
66
+ );
67
+
68
+ expect(markdown).toContain(
69
+ '```sh [custom]\ncustom install -D @rspress/core\n```',
70
+ );
71
+ expect(markdown).toContain('```sh [yarn]\nyarn add -D @rspress/core\n```');
72
+ });
73
+
74
+ it('adds commands to an object command without mutating it', async () => {
75
+ setSsgMd(true);
76
+ const command = Object.freeze({ npm: 'npm install @rspress/core' });
77
+
78
+ const markdown = await renderToMarkdownString(
79
+ <PackageManagerTabs
80
+ command={command}
81
+ additionalTabs={[
82
+ { tool: 'custom', command: 'custom add @rspress/core' },
83
+ { tool: 'unused' },
84
+ ]}
85
+ />,
86
+ );
87
+
88
+ expect(markdown).toContain('```sh [npm]\nnpm install @rspress/core\n```');
89
+ expect(markdown).toContain('```sh [custom]\ncustom add @rspress/core\n```');
90
+ expect(markdown).not.toContain('unused');
91
+ expect(command).toEqual({ npm: 'npm install @rspress/core' });
92
+ });
93
+
94
+ it('does not normalize an explicit command for a built-in tool', async () => {
95
+ setSsgMd(true);
96
+
97
+ const markdown = await renderToMarkdownString(
98
+ <PackageManagerTabs
99
+ command="install -D @rspress/core"
100
+ additionalTabs={[{ tool: 'yarn', command: 'yarn install --immutable' }]}
101
+ />,
102
+ );
103
+
104
+ expect(markdown).toContain('```sh [yarn]\nyarn install --immutable\n```');
105
+ expect(markdown).not.toContain('yarn add');
106
+ });
107
+
30
108
  it('renders install commands as markdown code fences when SSG_MD is enabled', async () => {
31
109
  setSsgMd(true);
32
110
 
@@ -1,10 +1,15 @@
1
- import { getCustomMDXComponent, Tab, Tabs } from '@rspress/core/theme';
1
+ import {
2
+ getCustomMDXComponent,
3
+ IconBun,
4
+ IconDeno,
5
+ IconNpm,
6
+ IconPnpm,
7
+ IconYarn,
8
+ SvgWrapper,
9
+ Tab,
10
+ Tabs,
11
+ } from '@rspress/core/theme';
2
12
  import { type ReactNode, useMemo } from 'react';
3
- import { Bun } from './icons/Bun';
4
- import { Deno } from './icons/Deno';
5
- import { Npm } from './icons/Npm';
6
- import { Pnpm } from './icons/Pnpm';
7
- import { Yarn } from './icons/Yarn';
8
13
 
9
14
  export type PackageManagerTabProps = (
10
15
  | {
@@ -35,6 +40,8 @@ export type PackageManagerTabProps = (
35
40
  ) & {
36
41
  additionalTabs?: {
37
42
  tool: string;
43
+ /** Full command for this tab, rendered as written. */
44
+ command?: string;
38
45
  icon?: ReactNode;
39
46
  }[];
40
47
  };
@@ -143,11 +150,11 @@ export function PackageManagerTabs({
143
150
  let commandInfo: Record<string, string>;
144
151
  // Init Icons
145
152
  const packageMangerToIcon: Record<string, ReactNode> = {
146
- npm: <Npm />,
147
- yarn: <Yarn />,
148
- pnpm: <Pnpm />,
149
- bun: <Bun />,
150
- deno: <Deno />,
153
+ npm: <SvgWrapper icon={IconNpm} />,
154
+ yarn: <SvgWrapper icon={IconYarn} />,
155
+ pnpm: <SvgWrapper icon={IconPnpm} />,
156
+ bun: <SvgWrapper icon={IconBun} />,
157
+ deno: <SvgWrapper icon={IconDeno} />,
151
158
  };
152
159
  additionalTabs.forEach(tab => {
153
160
  packageMangerToIcon[tab.tool] = tab.icon;
@@ -215,9 +222,15 @@ export function PackageManagerTabs({
215
222
  commandInfo.deno = normalizeCommand(commandInfo.deno);
216
223
  } else {
217
224
  // When using { "yarn": "", "pnpm": "", "bun": "", "deno": "" } as command we don't normalize anything
218
- commandInfo = command;
225
+ commandInfo = { ...command };
219
226
  }
220
227
 
228
+ additionalTabs.forEach(tab => {
229
+ if (tab.command !== undefined) {
230
+ commandInfo[tab.tool] = tab.command;
231
+ }
232
+ });
233
+
221
234
  if (import.meta.env.SSG_MD) {
222
235
  return Object.values(commandInfo).reduce((previous, current) => {
223
236
  const [packageManager, command] = splitTo2Parts(current);
@@ -2,8 +2,7 @@
2
2
  display: flex;
3
3
  flex-direction: column;
4
4
  align-items: center;
5
- padding-top: 2rem;
6
- padding-bottom: 0.5rem;
5
+ padding: 2rem 1rem;
7
6
 
8
7
  &__icon {
9
8
  margin-bottom: 1rem;