@rspress/core 2.0.19 → 2.0.21

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 (92) hide show
  1. package/dist/{6305~0.js → 2711~0.js} +1 -1
  2. package/dist/5357~0.js +1 -1
  3. package/dist/8472~0.js +2 -2
  4. package/dist/864~0.js +1 -1
  5. package/dist/cli/index.js +1 -1
  6. package/dist/config/loadConfigFile.js +2 -3
  7. package/dist/eject-theme/components/Banner/index.tsx +50 -9
  8. package/dist/eject-theme/components/Callout/index.scss +6 -1
  9. package/dist/eject-theme/components/CodeBlock/index.scss +2 -0
  10. package/dist/eject-theme/components/DocContent/doc.scss +2 -2
  11. package/dist/eject-theme/components/Link/getHref.test.ts +33 -0
  12. package/dist/eject-theme/components/Link/getHref.ts +60 -0
  13. package/dist/eject-theme/components/Link/index.tsx +7 -6
  14. package/dist/eject-theme/components/Link/useLinkNavigate.ts +6 -51
  15. package/dist/eject-theme/components/Llms/LlmsHint.test.tsx +1 -1
  16. package/dist/eject-theme/components/Llms/LlmsHint.tsx +10 -6
  17. package/dist/eject-theme/components/Nav/NavMenu.scss +16 -4
  18. package/dist/eject-theme/components/Nav/hooks.tsx +1 -2
  19. package/dist/eject-theme/components/Nav/index.scss +3 -1
  20. package/dist/eject-theme/components/Prompt/index.scss +2 -1
  21. package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +1 -1
  22. package/dist/eject-theme/components/SwitchAppearance/global.scss +18 -0
  23. package/dist/eject-theme/components/SwitchAppearance/index.tsx +4 -9
  24. package/dist/node/PluginDriver.js +1 -1
  25. package/dist/node/auto-nav-sidebar/index.js +1 -1
  26. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  27. package/dist/node/auto-nav-sidebar/normalize.js +2 -3
  28. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  29. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  30. package/dist/node/constants.js +1 -1
  31. package/dist/node/eject.js +1 -1
  32. package/dist/node/initRsbuild.js +3 -3
  33. package/dist/node/last-updated/index.js +2 -2
  34. package/dist/node/mdx/options.js +2 -1
  35. package/dist/node/mdx/remarkPlugins/link.d.ts +2 -1
  36. package/dist/node/mdx/remarkPlugins/link.js +6 -5
  37. package/dist/node/route/RoutePage.d.ts +0 -1
  38. package/dist/node/route/RoutePage.js +4 -6
  39. package/dist/node/route/RouteService.js +1 -1
  40. package/dist/node/route/extractPageData.js +1 -1
  41. package/dist/node/route/normalizeRoutePath.js +2 -3
  42. package/dist/node/runtimeModule/i18n.js +1 -1
  43. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  44. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  45. package/dist/node/runtimeModule/searchHooks.js +1 -1
  46. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  47. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  48. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  49. package/dist/node/serve.js +1 -1
  50. package/dist/node/ssg/alternateLinks.js +1 -1
  51. package/dist/node/ssg/renderPages.js +2 -2
  52. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  53. package/dist/node/ssg/ssgEnv.js +1 -1
  54. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  55. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  56. package/dist/node/ssg-md/renderPage.js +1 -1
  57. package/dist/node/ssg-md/renderPages.js +1 -1
  58. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  59. package/dist/node/utils/checkLanguageParity.js +1 -1
  60. package/dist/node/utils/createHash.js +1 -1
  61. package/dist/node/utils/flattenMdxContent.js +2 -2
  62. package/dist/node/utils/getPageKey.js +1 -1
  63. package/dist/node/utils/reactAlias.js +1 -1
  64. package/dist/runtime/csrClientEntry.js +7 -2
  65. package/dist/runtime/route.d.ts +10 -0
  66. package/dist/runtime/route.js +13 -2
  67. package/dist/runtime/ssrClientEntry.js +2 -0
  68. package/dist/theme/components/Banner/index.js +53 -9
  69. package/dist/theme/components/Callout/index.css +6 -1
  70. package/dist/theme/components/CodeBlock/index.css +2 -0
  71. package/dist/theme/components/DocContent/doc.css +2 -2
  72. package/dist/theme/components/Link/getHref.d.ts +8 -0
  73. package/dist/theme/components/Link/getHref.js +33 -0
  74. package/dist/theme/components/Link/index.js +7 -6
  75. package/dist/theme/components/Link/useLinkNavigate.d.ts +0 -7
  76. package/dist/theme/components/Link/useLinkNavigate.js +7 -31
  77. package/dist/theme/components/Llms/LlmsHint.js +6 -2
  78. package/dist/theme/components/Nav/NavMenu.css +15 -7
  79. package/dist/theme/components/Nav/hooks.js +1 -2
  80. package/dist/theme/components/Nav/index.css +3 -1
  81. package/dist/theme/components/Prompt/index.css +2 -1
  82. package/dist/theme/components/Search/logic/providers/LocalProvider.js +1 -1
  83. package/dist/theme/components/SwitchAppearance/global.css +10 -11
  84. package/dist/theme/components/SwitchAppearance/index.js +2 -8
  85. package/dist/theme/logic/applyThemeToDOM.d.ts +2 -0
  86. package/dist/theme/logic/applyThemeToDOM.js +17 -0
  87. package/dist/theme/logic/useThemeState.d.ts +1 -2
  88. package/dist/theme/logic/useThemeState.js +1 -7
  89. package/dist/theme/logic/utils.d.ts +4 -0
  90. package/dist/theme/logic/utils.js +23 -2
  91. package/dist/theme/styles/preflight.css +0 -2
  92. package/package.json +13 -13
@@ -2809,7 +2809,7 @@ function isDynamicPattern(pattern, options) {
2809
2809
  return scan.isGlob || scan.negated;
2810
2810
  }
2811
2811
  function log(...tasks) {
2812
- console.log(`[tinyglobby ${/* @__PURE__ */ new Date().toLocaleTimeString("es")}]`, ...tasks);
2812
+ console.log(`[tinyglobby ${(/* @__PURE__ */ new Date()).toLocaleTimeString("es")}]`, ...tasks);
2813
2813
  }
2814
2814
  function ensureStringArray(value) {
2815
2815
  return "string" == typeof value ? [
package/dist/5357~0.js CHANGED
@@ -4,5 +4,5 @@ export { cwd } from "node:process";
4
4
  export { logger } from "@rspress/shared/logger";
5
5
  export { visit } from "unist-util-visit";
6
6
  export { existsSync } from "node:fs";
7
- export { MDX_OR_MD_REGEXP, addLeadingSlash, isDataUrl, isExternalUrl, isProduction, normalizeHref, parseUrl, withBase } from "@rspress/shared";
7
+ export { MDX_OR_MD_REGEXP, addLeadingSlash, isDataUrl, isExternalUrl, isProduction, normalizeHref, parseUrl, withBase, withSiteOrigin } from "@rspress/shared";
8
8
  export { getNodeAttribute } from "@rspress/shared/node-utils";
package/dist/8472~0.js CHANGED
@@ -1,11 +1,11 @@
1
1
  var package_namespaceObject = {
2
- rE: "2.0.19"
2
+ rE: "2.0.21"
3
3
  };
4
4
  async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true, signal } = {}) {
5
5
  return new Promise((resolve_, reject_)=>{
6
6
  if (void 0 === iterable[Symbol.iterator] && void 0 === iterable[Symbol.asyncIterator]) throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
7
7
  if ('function' != typeof mapper) throw new TypeError('Mapper function is required');
8
- if (!(Number.isSafeInteger(concurrency) && concurrency >= 1 || concurrency === 1 / 0)) throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
8
+ if (!(Number.isSafeInteger(concurrency) && concurrency >= 1 || 1 / 0 === concurrency)) throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
9
9
  const result = [];
10
10
  const errors = [];
11
11
  const skippedIndexesMap = new Map();
package/dist/864~0.js CHANGED
@@ -8,7 +8,7 @@ import { createReadStream, createWriteStream, readFileSync } from "node:fs";
8
8
  import { setTimeout as promises_setTimeout } from "node:timers/promises";
9
9
  import { debuglog } from "node:util";
10
10
  import { __webpack_require__ } from "./rslib-runtime~0.js";
11
- import "./6305~0.js";
11
+ import "./2711~0.js";
12
12
  __webpack_require__.add({
13
13
  "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js" (module, __unused_rspack_exports, __webpack_require__) {
14
14
  const cp = __webpack_require__("child_process");
package/dist/cli/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { logger, cac } from "../6305~0.js";
1
+ import { logger, cac } from "../2711~0.js";
2
2
  import { package_namespaceObject } from "../8472~0.js";
3
3
  import { loadConfigFile, resolveDocRoot } from "../config/loadConfigFile.js";
4
4
  import { dev } from "../node/dev.js";
@@ -1,9 +1,8 @@
1
- import { node_fs, node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../6305~0.js";
1
+ import { node_fs, node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../2711~0.js";
2
2
  const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
3
3
  async function loadConfigFile(customConfigFile) {
4
4
  const baseDir = process.cwd();
5
- let configFilePath = '';
6
- configFilePath = customConfigFile ? node_path.isAbsolute(customConfigFile) ? customConfigFile : node_path.join(baseDir, customConfigFile) : findConfig(node_path.join(baseDir, DEFAULT_CONFIG_NAME));
5
+ const configFilePath = customConfigFile ? node_path.isAbsolute(customConfigFile) ? customConfigFile : node_path.join(baseDir, customConfigFile) : findConfig(node_path.join(baseDir, DEFAULT_CONFIG_NAME));
7
6
  if (!configFilePath) {
8
7
  logger.info(`No config file found in ${baseDir}`);
9
8
  return {
@@ -1,8 +1,21 @@
1
1
  import { IconClose, Link, mergeRefs, SvgWrapper } from '@rspress/core/theme';
2
2
  import clsx from 'clsx';
3
- import { forwardRef, type ReactNode, useEffect, useState } from 'react';
3
+ import { forwardRef, type ReactNode, useEffect, useId, useState } from 'react';
4
4
  import './index.scss';
5
5
 
6
+ const inlineStorageScript = `(function () {
7
+ var script = document.currentScript;
8
+ if (!script) return;
9
+ try {
10
+ var storage = window[script.dataset.rpBannerStorage];
11
+ var storageKey = script.dataset.rpBannerStorageKey;
12
+ var hiddenClass = script.dataset.rpBannerHiddenClass;
13
+ if (storage && storageKey && hiddenClass && storage.getItem(storageKey)) {
14
+ document.documentElement.classList.add(hiddenClass);
15
+ }
16
+ } catch (e) {}
17
+ })();`;
18
+
6
19
  export type BannerProps = {
7
20
  /**
8
21
  * @default true
@@ -71,6 +84,7 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
71
84
  storage?: 'localStorage' | 'sessionStorage' | false;
72
85
  customChildren?: ReactNode;
73
86
  };
87
+ const isCustom = 'customChildren' in props;
74
88
 
75
89
  const [height, setHeight] = useState(36);
76
90
  const ref = mergeRefs(forwardedRef, element => {
@@ -79,14 +93,27 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
79
93
  }
80
94
  });
81
95
  const [disable, setDisable] = useState(false);
96
+ const bannerId = useId().replace(/[^a-zA-Z0-9_-]/g, '');
97
+ const bannerClass = `rp-banner-${bannerId}`;
98
+ const hiddenClass = `${bannerClass}-hidden`;
82
99
 
83
- // TODO: support SSR
84
100
  useEffect(() => {
85
- if (typeof window === 'undefined' || !storage || !storageKey) {
86
- return;
101
+ let isDisabled = false;
102
+ if (!isCustom && typeof window !== 'undefined' && storage && storageKey) {
103
+ try {
104
+ isDisabled = Boolean(window[storage].getItem(storageKey));
105
+ } catch {
106
+ isDisabled = false;
107
+ }
87
108
  }
88
- setDisable(Boolean(window[storage].getItem(storageKey)));
89
- }, []);
109
+
110
+ document.documentElement.classList.toggle(hiddenClass, isDisabled);
111
+ setDisable(isDisabled);
112
+
113
+ return () => {
114
+ document.documentElement.classList.remove(hiddenClass);
115
+ };
116
+ }, [hiddenClass, isCustom, storage, storageKey]);
90
117
 
91
118
  if (!display || disable) {
92
119
  return null;
@@ -94,7 +121,17 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
94
121
 
95
122
  return (
96
123
  <>
97
- <div className={clsx('rp-banner', className)} ref={ref}>
124
+ {!isCustom && storage && storageKey ? (
125
+ <script
126
+ data-rp-banner-hidden-class={hiddenClass}
127
+ data-rp-banner-storage={storage}
128
+ data-rp-banner-storage-key={storageKey}
129
+ suppressHydrationWarning
130
+ dangerouslySetInnerHTML={{ __html: inlineStorageScript }}
131
+ />
132
+ ) : null}
133
+ <style>{`:root {--rp-banner-height: ${height}px;} :root.${hiddenClass} {--rp-banner-height: 0px;} :root.${hiddenClass} .${bannerClass} {display: none;}`}</style>
134
+ <div className={clsx('rp-banner', bannerClass, className)} ref={ref}>
98
135
  {customChildren ?? (
99
136
  <>
100
137
  <Link
@@ -107,9 +144,14 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
107
144
  <SvgWrapper
108
145
  icon={IconClose}
109
146
  onClick={() => {
147
+ document.documentElement.classList.add(hiddenClass);
110
148
  setDisable(true);
111
149
  if (storage) {
112
- window[storage].setItem(storageKey, 'true');
150
+ try {
151
+ window[storage].setItem(storageKey, 'true');
152
+ } catch {
153
+ return;
154
+ }
113
155
  }
114
156
  }}
115
157
  className="rp-banner__close"
@@ -117,7 +159,6 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
117
159
  </>
118
160
  )}
119
161
  </div>
120
- <style>{`:root {--rp-banner-height: ${height}px;}`}</style>
121
162
  </>
122
163
  );
123
164
  },
@@ -111,7 +111,12 @@
111
111
  }
112
112
 
113
113
  a {
114
- border-bottom: 1px solid currentColor;
114
+ text-decoration: underline;
115
+ text-underline-offset: 4px;
116
+
117
+ &:hover {
118
+ opacity: 0.85;
119
+ }
115
120
  }
116
121
  }
117
122
  }
@@ -52,6 +52,8 @@
52
52
  position: relative;
53
53
  z-index: 1;
54
54
  margin: 0;
55
+ width: fit-content;
56
+ min-width: 100%;
55
57
  background: transparent;
56
58
  }
57
59
 
@@ -36,8 +36,8 @@
36
36
  overflow-wrap: break-word;
37
37
 
38
38
  &:hover {
39
- border-bottom: 1px solid currentColor;
40
- opacity: 0.85;
39
+ text-decoration: underline;
40
+ text-underline-offset: 4px;
41
41
  }
42
42
  &[target='_blank'] {
43
43
  &::after {
@@ -0,0 +1,33 @@
1
+ import { describe, expect, it, rs } from '@rstest/core';
2
+ import { getHref } from './getHref';
3
+
4
+ rs.mock('virtual-site-data', () => ({
5
+ default: {
6
+ base: '/docs/',
7
+ route: {
8
+ cleanUrls: true,
9
+ },
10
+ },
11
+ }));
12
+
13
+ describe('getHref', () => {
14
+ it('preserves search and hash for an internal link with a base', () => {
15
+ expect(getHref('/guide?tab=api#install')).toEqual({
16
+ linkType: 'internal',
17
+ withBaseHref: '/docs/guide?tab=api#install',
18
+ removeBaseHref: '/guide?tab=api#install',
19
+ routePath: '/guide',
20
+ });
21
+ });
22
+
23
+ it('preserves search and hash when resolving a relative link', () => {
24
+ expect(
25
+ getHref('./guide?tab=api#install', 'https://example.com/docs/source'),
26
+ ).toEqual({
27
+ linkType: 'relative',
28
+ withBaseHref: '/docs/guide?tab=api#install',
29
+ removeBaseHref: '/guide?tab=api#install',
30
+ routePath: '/guide',
31
+ });
32
+ });
33
+ });
@@ -0,0 +1,60 @@
1
+ import { cleanUrl, isExternalUrl } from '@rspress/shared';
2
+ import { cleanUrlByConfig, removeBase, withBase } from '../../../runtime/utils';
3
+
4
+ type LinkType = 'external' | 'hashOnly' | 'relative' | 'internal';
5
+
6
+ function isAbsoluteUrl(url: string): boolean {
7
+ return url.startsWith('/');
8
+ }
9
+
10
+ function getLinkType(href: string): LinkType {
11
+ if (isExternalUrl(href)) {
12
+ return 'external';
13
+ }
14
+ if (href.startsWith('#')) {
15
+ return 'hashOnly';
16
+ }
17
+
18
+ if (!isAbsoluteUrl(href)) {
19
+ return 'relative';
20
+ }
21
+
22
+ return 'internal';
23
+ }
24
+
25
+ export function getHref(
26
+ href: string,
27
+ currentUrl = typeof window === 'undefined' ? undefined : window.location.href,
28
+ ): {
29
+ withBaseHref: string;
30
+ removeBaseHref: string;
31
+ routePath: string;
32
+ linkType: LinkType;
33
+ } {
34
+ let withBaseHref;
35
+ const linkType = getLinkType(href);
36
+
37
+ if (linkType === 'external' || linkType === 'hashOnly') {
38
+ return {
39
+ linkType,
40
+ withBaseHref: href,
41
+ removeBaseHref: href,
42
+ routePath: cleanUrl(href),
43
+ };
44
+ }
45
+
46
+ if (linkType === 'relative' && currentUrl) {
47
+ const url = new URL(href, currentUrl);
48
+ withBaseHref = `${url.pathname}${url.search}${url.hash}`;
49
+ } else {
50
+ withBaseHref = withBase(cleanUrlByConfig(href));
51
+ }
52
+ const removeBaseHref = removeBase(withBaseHref);
53
+
54
+ return {
55
+ withBaseHref,
56
+ removeBaseHref,
57
+ routePath: cleanUrl(removeBaseHref),
58
+ linkType,
59
+ };
60
+ }
@@ -5,7 +5,8 @@ import type React from 'react';
5
5
  import type { ComponentProps, TransitionStartFunction } from 'react';
6
6
  import { forwardRef } from 'react';
7
7
  import './index.scss';
8
- import { getHref, useLinkNavigate } from './useLinkNavigate';
8
+ import { getHref } from './getHref';
9
+ import { useLinkNavigate } from './useLinkNavigate';
9
10
 
10
11
  export interface LinkProps extends ComponentProps<'a'> {
11
12
  href?: string;
@@ -55,7 +56,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
55
56
  ...otherProps
56
57
  } = props;
57
58
 
58
- const { linkType, removeBaseHref, withBaseHref } = getHref(href);
59
+ const { linkType, removeBaseHref, routePath, withBaseHref } = getHref(href);
59
60
  const navigate = useLinkNavigate({ startTransition });
60
61
 
61
62
  if (linkType === 'external') {
@@ -98,10 +99,10 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
98
99
  className={clsx(className, 'rp-link')}
99
100
  onMouseEnter={event => {
100
101
  onMouseEnter?.(event);
101
- preloadLink(removeBaseHref);
102
+ preloadLink(routePath);
102
103
  }}
103
104
  onTouchStart={() => {
104
- preloadLink(removeBaseHref);
105
+ preloadLink(routePath);
105
106
  }}
106
107
  onClick={e => {
107
108
  onClick?.(e);
@@ -135,10 +136,10 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
135
136
  className={clsx(className, 'rp-link')}
136
137
  onMouseEnter={event => {
137
138
  onMouseEnter?.(event);
138
- preloadLink(removeBaseHref);
139
+ preloadLink(routePath);
139
140
  }}
140
141
  onTouchStart={() => {
141
- preloadLink(removeBaseHref);
142
+ preloadLink(routePath);
142
143
  }}
143
144
  onClick={e => {
144
145
  onClick?.(e);
@@ -1,15 +1,11 @@
1
1
  import {
2
- cleanUrlByConfig,
3
2
  initPageData,
4
3
  isActive,
5
- isExternalUrl,
6
4
  pathnameToRouteService,
7
- removeBase,
8
5
  useLocation,
9
6
  useNavigate as useNavigateInner,
10
7
  useSite,
11
8
  warmPageData,
12
- withBase,
13
9
  } from '@rspress/core/runtime';
14
10
  import nprogress from 'nprogress';
15
11
  import {
@@ -17,52 +13,10 @@ import {
17
13
  type TransitionStartFunction,
18
14
  useCallback,
19
15
  } from 'react';
16
+ import { getHref } from './getHref';
20
17
 
21
18
  nprogress.configure({ showSpinner: false });
22
19
 
23
- function isAbsoluteUrl(url: string): boolean {
24
- return url.startsWith('/');
25
- }
26
-
27
- type LinkType = 'external' | 'hashOnly' | 'relative' | 'internal';
28
-
29
- function getLinkType(href: string): LinkType {
30
- if (isExternalUrl(href)) {
31
- return 'external';
32
- }
33
- if (href.startsWith('#')) {
34
- return 'hashOnly';
35
- }
36
-
37
- if (!isAbsoluteUrl(href)) {
38
- return 'relative';
39
- }
40
-
41
- return 'internal';
42
- }
43
-
44
- export function getHref(href: string): {
45
- withBaseHref: string;
46
- removeBaseHref: string;
47
- linkType: LinkType;
48
- } {
49
- let withBaseHref;
50
- const linkType = getLinkType(href);
51
-
52
- if (linkType === 'external' || linkType === 'hashOnly') {
53
- return { linkType: linkType, withBaseHref: href, removeBaseHref: href };
54
- }
55
-
56
- if (linkType === 'relative' && !import.meta.env.SSR) {
57
- withBaseHref = new URL(href, window.location.href).pathname;
58
- } else {
59
- withBaseHref = withBase(cleanUrlByConfig(href));
60
- }
61
- const removeBaseHref = removeBase(withBaseHref);
62
-
63
- return { withBaseHref, removeBaseHref, linkType };
64
- }
65
-
66
20
  /**
67
21
  * For import { Link } from '@rspress/core/theme';
68
22
  * useNavigate with preload logic
@@ -81,7 +35,8 @@ export function useLinkNavigate(
81
35
 
82
36
  return useCallback(
83
37
  async (href: string) => {
84
- const { linkType, removeBaseHref, withBaseHref } = getHref(href);
38
+ const { linkType, removeBaseHref, routePath, withBaseHref } =
39
+ getHref(href);
85
40
  if (linkType === 'external' || linkType === 'hashOnly') {
86
41
  window.location.assign(href);
87
42
  return;
@@ -92,13 +47,13 @@ export function useLinkNavigate(
92
47
  const inCurrPage = isActive(removeBaseHref, currPagePathname);
93
48
 
94
49
  if (!import.meta.env.SSR && !inCurrPage) {
95
- const matchedRoute = pathnameToRouteService(removeBaseHref);
50
+ const matchedRoute = pathnameToRouteService(routePath);
96
51
  if (matchedRoute) {
97
52
  const timer = setTimeout(() => {
98
53
  nprogress.start();
99
54
  }, 200);
100
- const data = await initPageData(removeBaseHref);
101
- warmPageData(removeBaseHref, data);
55
+ const data = await initPageData(routePath);
56
+ warmPageData(routePath, data);
102
57
  clearTimeout(timer);
103
58
  nprogress.done();
104
59
  } else {
@@ -64,7 +64,7 @@ describe('LlmsHint', () => {
64
64
  setSsgMd(true);
65
65
 
66
66
  expect(await renderToMarkdownString(<LlmsHint />)).toBe(
67
- '> For AI agents: the complete documentation index is available at https://example.com/docs/llms.txt, the full documentation bundle is available at https://example.com/docs/llms-full.txt, and this page is available as Markdown at https://example.com/docs/guide/index.md.\n\n',
67
+ '> For AI agents: the complete documentation index is available at https://example.com/docs/llms.txt, the full documentation bundle is available at https://example.com/docs/llms-full.txt.\n\n',
68
68
  );
69
69
  });
70
70
 
@@ -27,9 +27,12 @@ function createLlmsHintText({
27
27
  }: {
28
28
  llmsTxtUrl: string;
29
29
  llmsFullTxtUrl: string;
30
- pageMdUrl: string;
30
+ pageMdUrl?: string;
31
31
  }) {
32
- return `For AI agents: the complete documentation index is available at ${llmsTxtUrl}, the full documentation bundle is available at ${llmsFullTxtUrl}, and this page is available as Markdown at ${pageMdUrl}.`;
32
+ const text = `For AI agents: the complete documentation index is available at ${llmsTxtUrl}, the full documentation bundle is available at ${llmsFullTxtUrl}`;
33
+ return pageMdUrl
34
+ ? `${text}, and this page is available as Markdown at ${pageMdUrl}.`
35
+ : `${text}.`;
33
36
  }
34
37
 
35
38
  export function LlmsHint() {
@@ -51,6 +54,11 @@ export function LlmsHint() {
51
54
  const llmsFullTxtUrl = withSiteOrigin(
52
55
  withBase(`/${versionPrefix}${langPrefix}llms-full.txt`),
53
56
  );
57
+
58
+ if (import.meta.env.SSG_MD) {
59
+ return `> ${createLlmsHintText({ llmsTxtUrl, llmsFullTxtUrl })}\n\n`;
60
+ }
61
+
54
62
  const pageMdUrl = withSiteOrigin(routePathToMdPath(page.routePath));
55
63
  const hintText = createLlmsHintText({
56
64
  llmsTxtUrl,
@@ -58,10 +66,6 @@ export function LlmsHint() {
58
66
  pageMdUrl,
59
67
  });
60
68
 
61
- if (import.meta.env.SSG_MD) {
62
- return `> ${hintText}\n\n`;
63
- }
64
-
65
69
  return (
66
70
  <div className="rp-llms-hint" style={visuallyHiddenStyle}>
67
71
  {hintText}
@@ -1,15 +1,17 @@
1
1
  .rp-nav-menu {
2
+ --rp-nav-menu-item-gap: 32px;
3
+
2
4
  display: inline-flex;
3
5
  align-items: center;
4
6
  height: 100%;
5
7
  list-style: none;
6
8
 
7
- @media (min-width: 1280px) {
8
- gap: 32px;
9
+ @media (max-width: 1279px) {
10
+ --rp-nav-menu-item-gap: 24px;
9
11
  }
10
12
 
11
- @media (max-width: 1279px) {
12
- gap: 24px;
13
+ &--left {
14
+ margin: 0 0 0 24px;
13
15
  }
14
16
 
15
17
  &__item {
@@ -26,6 +28,8 @@
26
28
  align-items: center;
27
29
  height: 100%;
28
30
  gap: 4px;
31
+ padding: 0 calc(var(--rp-nav-menu-item-gap) / 2) 0
32
+ calc(var(--rp-nav-menu-item-gap) / 2);
29
33
 
30
34
  // text
31
35
  text-align: center;
@@ -35,6 +39,14 @@
35
39
  line-height: 22px;
36
40
  }
37
41
 
42
+ &:first-child > .rp-nav-menu__item__container {
43
+ padding-left: 0;
44
+ }
45
+
46
+ &:last-child > .rp-nav-menu__item__container {
47
+ padding-right: 0;
48
+ }
49
+
38
50
  &__icon {
39
51
  display: flex;
40
52
  justify-content: center;
@@ -32,7 +32,6 @@ function replaceLang(
32
32
 
33
33
  let versionPart = '';
34
34
  let langPart = '';
35
- let purePathPart = '';
36
35
 
37
36
  const parts = url.split('/').filter(Boolean);
38
37
 
@@ -51,7 +50,7 @@ function replaceLang(
51
50
  parts.shift();
52
51
  }
53
52
 
54
- purePathPart = parts.join('/') || '';
53
+ let purePathPart = parts.join('/') || '';
55
54
 
56
55
  if ((versionPart || langPart) && !purePathPart) {
57
56
  purePathPart = cleanUrls ? 'index' : 'index.html';
@@ -1,7 +1,7 @@
1
1
  .rp-nav {
2
2
  transition:
3
3
  background-color 0.2s ease-in-out,
4
- border-bottom 0.2s ease-in-out;
4
+ border-bottom-color 0.2s ease-in-out;
5
5
  display: flex;
6
6
  height: var(--rp-nav-height);
7
7
  flex-shrink: 0;
@@ -39,6 +39,8 @@
39
39
 
40
40
  &__left {
41
41
  display: flex;
42
+ align-items: center;
43
+ height: 100%;
42
44
  }
43
45
 
44
46
  &__title {
@@ -394,7 +394,8 @@
394
394
 
395
395
  a {
396
396
  color: var(--rp-prompt-accent, var(--rp-c-brand-dark));
397
- border-bottom: 1px solid currentColor;
397
+ text-decoration: underline;
398
+ text-underline-offset: 4px;
398
399
 
399
400
  & > code {
400
401
  color: inherit;
@@ -50,7 +50,7 @@ const cyrillicRegex = /[\u0400-\u04FF]/g;
50
50
 
51
51
  function tokenize(str: string, regex: RegExp) {
52
52
  const words: string[] = [];
53
- let m: RegExpExecArray | null = null;
53
+ let m: RegExpExecArray | null;
54
54
  do {
55
55
  m = regex.exec(str);
56
56
  if (m) {
@@ -4,6 +4,24 @@
4
4
  mix-blend-mode: normal;
5
5
  }
6
6
 
7
+ /* Toggled by applyThemeToDOM for one frame while the theme class flips, so
8
+ every themed surface switches in sync instead of fading at its own pace.
9
+ A static rule toggled via a root class (rather than an injected <style>)
10
+ stays compatible with strict CSP. */
11
+ html.rp-theme-switching *,
12
+ html.rp-theme-switching *::before,
13
+ html.rp-theme-switching *::after,
14
+ html.rp-theme-switching *::-webkit-scrollbar-thumb {
15
+ transition: none !important;
16
+ }
17
+
18
+ /* Toggled by SwitchAppearance while the appearance view transition runs; the
19
+ 'flip' and 'root' view-transition names conflict otherwise, see
20
+ https://github.com/web-infra-dev/rspress/pull/1272 */
21
+ html.rp-appearance-transition .rspress-doc {
22
+ view-transition-name: none !important;
23
+ }
24
+
7
25
  ::view-transition-old(root),
8
26
  .dark::view-transition-new(root) {
9
27
  z-index: 1;
@@ -12,17 +12,12 @@ const supportAppearanceTransition = () => {
12
12
  );
13
13
  };
14
14
 
15
- // two view-transition name is conflicted, 'flip' and 'root', see https://github.com/web-infra-dev/rspress/pull/1272
15
+ // Toggles the `html.rp-appearance-transition` rule in global.scss — see the
16
+ // comment there and https://github.com/web-infra-dev/rspress/pull/1272
16
17
  const removeClipViewTransition = () => {
17
- const styleDom = document.createElement('style');
18
- styleDom.innerHTML = `
19
- .rspress-doc {
20
- view-transition-name: none !important;
21
- }
22
- `;
23
- document.head.appendChild(styleDom);
18
+ document.documentElement.classList.add('rp-appearance-transition');
24
19
  return () => {
25
- document.head.removeChild(styleDom);
20
+ document.documentElement.classList.remove('rp-appearance-transition');
26
21
  };
27
22
  };
28
23
 
@@ -1,4 +1,4 @@
1
- import { addTrailingSlash, node_path, addLeadingSlash } from "../6305~0.js";
1
+ import { addTrailingSlash, node_path, addLeadingSlash } from "../2711~0.js";
2
2
  import { createError } from "./utils/error.js";
3
3
  import { haveNavSidebarConfig as auto_nav_sidebar_haveNavSidebarConfig } from "./auto-nav-sidebar/index.js";
4
4
  class PluginDriver {
@@ -1,4 +1,4 @@
1
- import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../6305~0.js";
1
+ import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../2711~0.js";
2
2
  import { processLocales, combineWalkResult } from "./locales.js";
3
3
  import { walk } from "./walk.js";
4
4
  async function runAutoNavSide(config, metaFileSet, mdFileSet) {
@@ -1,4 +1,4 @@
1
- import { node_path } from "../../6305~0.js";
1
+ import { node_path } from "../../2711~0.js";
2
2
  import { walk } from "./walk.js";
3
3
  function combineWalkResult(walks, versions) {
4
4
  return walks.reduce((acc, cur, curIndex)=>({