@rspress/core 2.0.16 → 2.0.18

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 (134) hide show
  1. package/bin/rspress.js +6 -1
  2. package/dist/0~execa.js +1 -1
  3. package/dist/{9882.js → 102.js} +1 -1
  4. package/dist/{9958.js → 3553.js} +2 -2
  5. package/dist/{5580.js → 5871.js} +2455 -6
  6. package/dist/cli/index.d.ts +8 -1
  7. package/dist/cli/index.js +105 -102
  8. package/dist/config/loadConfigFile.js +1 -1
  9. package/dist/eject-theme/components/DocContent/docComponents/title.tsx +1 -1
  10. package/dist/eject-theme/components/HomeFeature/index.scss +1 -0
  11. package/dist/eject-theme/components/HomeFeature/index.tsx +1 -1
  12. package/dist/eject-theme/components/HoverGroup/index.scss +9 -0
  13. package/dist/eject-theme/components/Link/index.tsx +1 -1
  14. package/dist/eject-theme/components/Link/useLinkNavigate.ts +17 -4
  15. package/dist/eject-theme/components/Llms/LlmsHiddenHint.test.tsx +23 -0
  16. package/dist/eject-theme/components/Llms/LlmsHiddenHint.tsx +15 -0
  17. package/dist/eject-theme/components/Llms/LlmsOpenRow.tsx +51 -64
  18. package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +65 -51
  19. package/dist/eject-theme/components/Llms/index.tsx +6 -1
  20. package/dist/eject-theme/components/Outline/index.tsx +1 -1
  21. package/dist/eject-theme/components/SocialLinks/GithubStars.test.tsx +48 -0
  22. package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +35 -20
  23. package/dist/index.d.ts +3 -2
  24. package/dist/index.js +2 -1
  25. package/dist/node/PluginDriver.js +1 -1
  26. package/dist/node/auto-nav-sidebar/index.js +1 -1
  27. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  28. package/dist/node/auto-nav-sidebar/normalize.js +2 -2
  29. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  30. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  31. package/dist/node/constants.js +1 -1
  32. package/dist/node/eject.js +2 -2
  33. package/dist/node/initRsbuild.js +19 -8
  34. package/dist/node/llms.d.ts +3 -0
  35. package/dist/node/llms.js +8 -0
  36. package/dist/node/logger/hint.js +1 -1
  37. package/dist/node/mdx/options.js +1 -1
  38. package/dist/node/mdx/processor.js +1 -1
  39. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  40. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  41. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  42. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  43. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +2 -2
  44. package/dist/node/mdx/remarkPlugins/image.js +2 -2
  45. package/dist/node/mdx/remarkPlugins/link.js +2 -2
  46. package/dist/node/mdx/remarkPlugins/toc.js +1 -1
  47. package/dist/node/medium-zoom/index.js +1 -1
  48. package/dist/node/route/RoutePage.js +5 -3
  49. package/dist/node/route/RouteService.js +8 -3
  50. package/dist/node/route/extractPageData.js +1 -1
  51. package/dist/node/route/normalizeRoutePath.js +1 -1
  52. package/dist/node/route/routeChunkAssets.d.ts +15 -0
  53. package/dist/node/route/routeChunkAssets.js +56 -0
  54. package/dist/node/runtimeModule/i18n.js +3 -3
  55. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  56. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  57. package/dist/node/runtimeModule/searchHooks.js +1 -1
  58. package/dist/node/runtimeModule/siteData/createSiteData.js +6 -2
  59. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  60. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  61. package/dist/node/serve.js +1 -1
  62. package/dist/node/ssg/alternateLinks.d.ts +7 -0
  63. package/dist/node/ssg/alternateLinks.js +40 -0
  64. package/dist/node/ssg/htmlFile.js +1 -1
  65. package/dist/node/ssg/renderHtmlTemplate.d.ts +3 -1
  66. package/dist/node/ssg/renderHtmlTemplate.js +25 -3
  67. package/dist/node/ssg/renderPage.d.ts +3 -1
  68. package/dist/node/ssg/renderPage.js +4 -4
  69. package/dist/node/ssg/renderPageWorker.js +5 -5
  70. package/dist/node/ssg/renderPages.d.ts +3 -2
  71. package/dist/node/ssg/renderPages.js +16 -11
  72. package/dist/node/ssg/rsbuildPluginCSR.d.ts +3 -1
  73. package/dist/node/ssg/rsbuildPluginCSR.js +2 -2
  74. package/dist/node/ssg/rsbuildPluginSSG.d.ts +3 -1
  75. package/dist/node/ssg/rsbuildPluginSSG.js +3 -3
  76. package/dist/node/ssg/ssgEnv.js +1 -1
  77. package/dist/node/ssg-md/llms/emitLlmsTxt.js +3 -3
  78. package/dist/node/ssg-md/llms/llmsTxt.d.ts +4 -4
  79. package/dist/node/ssg-md/llms/llmsTxt.js +54 -40
  80. package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
  81. package/dist/node/ssg-md/renderPage.js +2 -2
  82. package/dist/node/ssg-md/renderPages.js +3 -3
  83. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  84. package/dist/node/utils/checkLanguageParity.js +1 -1
  85. package/dist/node/utils/createHash.d.ts +1 -1
  86. package/dist/node/utils/createHash.js +3 -3
  87. package/dist/node/utils/error.js +1 -1
  88. package/dist/node/utils/flattenMdxContent.js +1 -1
  89. package/dist/node/utils/fs.js +1 -1
  90. package/dist/node/utils/getPageKey.js +1 -1
  91. package/dist/node/utils/normalizePath.js +1 -1
  92. package/dist/node/utils/reactAlias.js +2 -2
  93. package/dist/runtime/App.js +2 -0
  94. package/dist/runtime/ClientApp.js +3 -2
  95. package/dist/runtime/index.d.ts +1 -1
  96. package/dist/runtime/index.js +1 -1
  97. package/dist/runtime/route.js +2 -0
  98. package/dist/runtime/utils.d.ts +2 -1
  99. package/dist/runtime/utils.js +5 -2
  100. package/dist/theme/assets/anthropic.js +15 -0
  101. package/dist/theme/assets/open-in-chat.js +19 -0
  102. package/dist/theme/assets/openai.js +15 -0
  103. package/dist/theme/components/DocContent/docComponents/index.d.ts +25 -18
  104. package/dist/theme/components/DocContent/docComponents/title.js +1 -1
  105. package/dist/theme/components/HomeFeature/index.css +1 -0
  106. package/dist/theme/components/HomeFeature/index.js +32 -34
  107. package/dist/theme/components/HoverGroup/index.css +7 -0
  108. package/dist/theme/components/Link/index.d.ts +1 -1
  109. package/dist/theme/components/Link/useLinkNavigate.d.ts +1 -1
  110. package/dist/theme/components/Link/useLinkNavigate.js +13 -5
  111. package/dist/theme/components/Llms/LlmsHiddenHint.d.ts +1 -0
  112. package/dist/theme/components/Llms/LlmsHiddenHint.js +18 -0
  113. package/dist/theme/components/Llms/LlmsOpenRow.js +31 -57
  114. package/dist/theme/components/Llms/LlmsViewOptions.d.ts +6 -4
  115. package/dist/theme/components/Llms/LlmsViewOptions.js +28 -45
  116. package/dist/theme/components/Llms/index.d.ts +2 -1
  117. package/dist/theme/components/Llms/index.js +1 -0
  118. package/dist/theme/components/Outline/index.js +1 -1
  119. package/dist/theme/components/Search/SearchPanel.js +8 -8
  120. package/dist/theme/components/SocialLinks/GithubStars.js +27 -17
  121. package/dist/theme/icons.d.ts +4 -1
  122. package/dist/theme/icons.js +8 -2
  123. package/dist/theme/index.d.ts +1 -1
  124. package/dist/theme/index.js +1 -1
  125. package/dist/theme/logic/getCopyableText.js +1 -0
  126. package/package.json +11 -11
  127. package/dist/6010.js +0 -2461
  128. package/dist/{0~8787.js → 0~8016.js} +0 -0
  129. package/dist/{7986.js → 4538.js} +0 -0
  130. package/dist/{3358.js → 5357.js} +0 -0
  131. package/dist/{5580.js.LICENSE.txt → 5871.js.LICENSE.txt} +0 -0
  132. package/dist/{8005.js → 7748.js} +2 -2
  133. /package/dist/{6646.js → 9857.js} +0 -0
  134. /package/dist/{9283.js → 9940.js} +0 -0
@@ -6,9 +6,11 @@
6
6
  import { useI18n, useSite } from '@rspress/core/runtime';
7
7
  import {
8
8
  copyToClipboard,
9
+ IconAnthropic,
9
10
  IconDown,
10
11
  IconExternalLink,
11
12
  IconLink,
13
+ IconOpenAI,
12
14
  SvgWrapper,
13
15
  } from '@rspress/core/theme';
14
16
  import type React from 'react';
@@ -17,7 +19,7 @@ import './index.scss';
17
19
  import './LlmsViewOptions.scss';
18
20
  import { useMdUrl } from './useMdUrl';
19
21
 
20
- type Option =
22
+ export type LlmsViewOptionsItem =
21
23
  | {
22
24
  title: string;
23
25
  icon?: React.ReactNode;
@@ -32,14 +34,24 @@ type Option =
32
34
  | 'chatgpt'
33
35
  | 'claude';
34
36
 
37
+ type MenuItem = {
38
+ title: string;
39
+ href?: string;
40
+ icon?: React.ReactNode;
41
+ onClick?: () => void;
42
+ };
43
+
35
44
  export interface LlmsViewOptionsProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
36
45
  /**
37
46
  * Default options for the dropdown.
38
47
  * @default ['markdownLink', 'chatgpt', 'claude']
39
48
  * - 'chatgpt': Open in ChatGPT
40
49
  * - 'claude': Open in Claude
50
+ *
51
+ * Unlike `themeConfig.llmsUI.viewOptions`, component options can use
52
+ * ReactNode icons and onClick callbacks.
41
53
  */
42
- options?: Option[];
54
+ options?: LlmsViewOptionsItem[];
43
55
  /**
44
56
  * Button text by language, used with `useLang`.
45
57
  * @default en: 'Open', zh: '\u6253\u5f00'
@@ -53,16 +65,21 @@ export interface LlmsViewOptionsProps extends React.ButtonHTMLAttributes<HTMLBut
53
65
  text?: string;
54
66
  }
55
67
 
56
- const DEFAULT_OPTIONS: Option[] = ['markdownLink', 'chatgpt', 'claude'];
68
+ const DEFAULT_OPTIONS: LlmsViewOptionsItem[] = [
69
+ 'markdownLink',
70
+ 'chatgpt',
71
+ 'claude',
72
+ ];
57
73
 
58
74
  export function LlmsViewOptions({
59
75
  options: propsOptions,
60
76
  }: LlmsViewOptionsProps) {
61
77
  const { site } = useSite();
62
78
  const llmsUI = site?.themeConfig?.llmsUI;
79
+ const configuredOptions =
80
+ typeof llmsUI === 'object' ? llmsUI?.viewOptions : propsOptions;
63
81
  const options =
64
- (typeof llmsUI === 'object' ? llmsUI?.viewOptions : propsOptions) ??
65
- DEFAULT_OPTIONS;
82
+ configuredOptions === false ? [] : (configuredOptions ?? DEFAULT_OPTIONS);
66
83
  const [isOpen, setIsOpen] = useState(false);
67
84
  const dropdownRef = useRef<HTMLButtonElement>(null);
68
85
 
@@ -111,39 +128,49 @@ export function LlmsViewOptions({
111
128
  hints: 'search',
112
129
  q,
113
130
  })}`,
114
- icon: (
115
- <svg
116
- role="img"
117
- viewBox="0 0 24 24"
118
- fill="currentColor"
119
- xmlns="http://www.w3.org/2000/svg"
120
- >
121
- <title>OpenAI</title>
122
- <path d="M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z" />
123
- <path d="M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z" />
124
- </svg>
125
- ),
131
+ icon: <SvgWrapper icon={IconOpenAI} />,
126
132
  },
127
133
  claude: {
128
134
  title: t('openInText', { name: 'Claude' }),
129
135
  href: `https://claude.ai/new?${new URLSearchParams({
130
136
  q,
131
137
  })}`,
132
- icon: (
133
- <svg
134
- fill="currentColor"
135
- role="img"
136
- viewBox="0 0 24 24"
137
- xmlns="http://www.w3.org/2000/svg"
138
- >
139
- <title>Anthropic</title>
140
- <path d="M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z" />
141
- </svg>
142
- ),
138
+ icon: <SvgWrapper icon={IconAnthropic} />,
143
139
  },
144
140
  };
145
141
  }, [pathname, t]);
146
142
 
143
+ const renderableItems = useMemo(
144
+ () =>
145
+ options
146
+ .map((option): MenuItem | null => {
147
+ if (option === 'markdownLink') {
148
+ return items.markdownLink;
149
+ }
150
+ if (option === 'chatgpt') {
151
+ return items.chatgpt;
152
+ }
153
+ if (option === 'claude') {
154
+ return items.claude;
155
+ }
156
+ if (
157
+ typeof option === 'object' &&
158
+ 'title' in option &&
159
+ typeof option.title === 'string' &&
160
+ ('href' in option || 'onClick' in option)
161
+ ) {
162
+ return option;
163
+ }
164
+ return null;
165
+ })
166
+ .filter((item): item is MenuItem => item !== null),
167
+ [items, options],
168
+ );
169
+
170
+ if (renderableItems.length === 0) {
171
+ return null;
172
+ }
173
+
147
174
  return (
148
175
  <>
149
176
  <button
@@ -159,33 +186,20 @@ export function LlmsViewOptions({
159
186
  />
160
187
  {isOpen && (
161
188
  <div className="rp-llms-view-options__menu">
162
- {options.map(item => {
163
- let displayItem = item as {
164
- title: string;
165
- href?: string;
166
- icon?: React.ReactNode;
167
- onClick?: () => void;
168
- };
169
- if (item === 'markdownLink') {
170
- displayItem = items.markdownLink;
171
- } else if (item === 'chatgpt') {
172
- displayItem = items.chatgpt;
173
- } else if (item === 'claude') {
174
- displayItem = items.claude;
175
- }
176
- if (displayItem.href) {
189
+ {renderableItems.map(item => {
190
+ if (item.href) {
177
191
  return (
178
192
  <a
179
- key={displayItem.title}
193
+ key={item.title}
180
194
  className="rp-llms-view-options__menu-item"
181
- href={displayItem.href}
195
+ href={item.href}
182
196
  target="_blank"
183
197
  rel="noopener noreferrer"
184
198
  >
185
199
  <span className="rp-llms-view-options__item-icon">
186
- {displayItem.icon}
200
+ {item.icon}
187
201
  </span>
188
- <span>{displayItem.title}</span>
202
+ <span>{item.title}</span>
189
203
  <span className="rp-llms-view-options__external-icon">
190
204
  <SvgWrapper icon={IconExternalLink} />
191
205
  </span>
@@ -194,14 +208,14 @@ export function LlmsViewOptions({
194
208
  }
195
209
  return (
196
210
  <div
197
- key={displayItem.title}
211
+ key={item.title}
198
212
  className="rp-llms-view-options__menu-item"
199
- onClick={displayItem.onClick}
213
+ onClick={item.onClick}
200
214
  >
201
215
  <span className="rp-llms-view-options__item-icon">
202
- {displayItem.icon}
216
+ {item.icon}
203
217
  </span>
204
- <span>{displayItem.title}</span>
218
+ <span>{item.title}</span>
205
219
  </div>
206
220
  );
207
221
  })}
@@ -1,4 +1,9 @@
1
1
  export { LlmsContainer, type LlmsContainerProps } from './LlmsContainer';
2
2
  export { LlmsCopyButton, type LlmsCopyButtonProps } from './LlmsCopyButton';
3
- export { LlmsViewOptions, type LlmsViewOptionsProps } from './LlmsViewOptions';
3
+ export { LlmsHiddenHint } from './LlmsHiddenHint';
4
+ export {
5
+ LlmsViewOptions,
6
+ type LlmsViewOptionsItem,
7
+ type LlmsViewOptionsProps,
8
+ } from './LlmsViewOptions';
4
9
  export { useMdUrl } from './useMdUrl';
@@ -33,7 +33,7 @@ export function Outline() {
33
33
  <div className="rp-outline__divider" />
34
34
  <div className="rp-outline__bottom">
35
35
  <EditLink isOutline />
36
- {process.env.ENABLE_LLMS_UI && placement === 'outline' && (
36
+ {import.meta.env.ENABLE_LLMS_UI && placement === 'outline' && (
37
37
  <>
38
38
  <LlmsCopyRow />
39
39
  <LlmsOpenRow />
@@ -0,0 +1,48 @@
1
+ import { afterEach, describe, expect, it } from '@rstest/core';
2
+ import { renderToStaticMarkup } from 'react-dom/server';
3
+ import { GithubStars } from './GithubStars';
4
+
5
+ const originalLocalStorage = Object.getOwnPropertyDescriptor(
6
+ globalThis,
7
+ 'localStorage',
8
+ );
9
+
10
+ afterEach(() => {
11
+ if (originalLocalStorage) {
12
+ Object.defineProperty(globalThis, 'localStorage', originalLocalStorage);
13
+ } else {
14
+ Reflect.deleteProperty(globalThis, 'localStorage');
15
+ }
16
+ });
17
+
18
+ function mockLocalStorage(cache: Record<string, string>) {
19
+ Object.defineProperty(globalThis, 'localStorage', {
20
+ configurable: true,
21
+ value: {
22
+ getItem: (key: string) => cache[key] ?? null,
23
+ setItem: () => {},
24
+ },
25
+ });
26
+ }
27
+
28
+ describe('GithubStars', () => {
29
+ it('does not render cached stars during the first render', () => {
30
+ mockLocalStorage({
31
+ 'rp-github-stars:web-infra-dev/rspress': JSON.stringify({
32
+ count: 12345,
33
+ fetchedAt: Date.now(),
34
+ }),
35
+ });
36
+
37
+ const markup = renderToStaticMarkup(
38
+ <GithubStars
39
+ content="https://github.com/web-infra-dev/rspress"
40
+ icon={<span data-icon="github" />}
41
+ />,
42
+ );
43
+
44
+ expect(markup).not.toContain('rp-social-links__github-stars-count');
45
+ expect(markup).not.toContain('12.3K');
46
+ expect(markup).toContain('aria-label="GitHub repository"');
47
+ });
48
+ });
@@ -1,4 +1,5 @@
1
1
  import { type ReactNode, useEffect, useState } from 'react';
2
+ import { useStorageValue } from '../../logic/useStorageValue';
2
3
 
3
4
  const TTL_MS = 60 * 60 * 1000;
4
5
 
@@ -21,10 +22,8 @@ function parseRepo(content: string): string | null {
21
22
  }
22
23
  }
23
24
 
24
- function readCache(repo: string): Cached | null {
25
- if (typeof localStorage === 'undefined') return null;
25
+ function parseCache(raw: string | null): Cached | null {
26
26
  try {
27
- const raw = localStorage.getItem(storageKey(repo));
28
27
  if (!raw) return null;
29
28
  const parsed = JSON.parse(raw) as Cached;
30
29
  if (
@@ -39,16 +38,8 @@ function readCache(repo: string): Cached | null {
39
38
  }
40
39
  }
41
40
 
42
- function writeCache(repo: string, count: number) {
43
- if (typeof localStorage === 'undefined') return;
44
- try {
45
- localStorage.setItem(
46
- storageKey(repo),
47
- JSON.stringify({ count, fetchedAt: Date.now() }),
48
- );
49
- } catch {
50
- // Storage may be full or disabled (private mode); ignore.
51
- }
41
+ function createCacheValue(count: number): string {
42
+ return JSON.stringify({ count, fetchedAt: Date.now() });
52
43
  }
53
44
 
54
45
  function formatCount(count: number): string {
@@ -70,14 +61,34 @@ export const GithubStars = (props: GithubStarsProps) => {
70
61
  const { content, icon } = props;
71
62
  const repo = parseRepo(content);
72
63
 
73
- const [count, setCount] = useState<number | null>(() =>
74
- repo ? (readCache(repo)?.count ?? null) : null,
64
+ const [rawCache, setRawCache] = useStorageValue<string | null>(
65
+ repo ? storageKey(repo) : '',
66
+ null,
75
67
  );
68
+ const [isMounted, setIsMounted] = useState(false);
69
+ const [count, setCount] = useState<number | null>(null);
70
+
71
+ useEffect(() => {
72
+ setIsMounted(true);
73
+ }, []);
76
74
 
77
75
  useEffect(() => {
78
- if (!repo) return;
79
- const cached = readCache(repo);
80
- if (cached && Date.now() - cached.fetchedAt < TTL_MS) return;
76
+ if (!repo) {
77
+ setCount(null);
78
+ return;
79
+ }
80
+
81
+ if (!isMounted) return;
82
+
83
+ const cached = parseCache(rawCache);
84
+ if (cached) {
85
+ setCount(cached.count);
86
+ if (Date.now() - cached.fetchedAt < TTL_MS) {
87
+ return;
88
+ }
89
+ } else {
90
+ setCount(null);
91
+ }
81
92
 
82
93
  let cancelled = false;
83
94
  fetch(`https://api.github.com/repos/${repo}`)
@@ -86,7 +97,11 @@ export const GithubStars = (props: GithubStarsProps) => {
86
97
  if (cancelled) return;
87
98
  if (typeof data?.stargazers_count === 'number') {
88
99
  setCount(data.stargazers_count);
89
- writeCache(repo, data.stargazers_count);
100
+ try {
101
+ setRawCache(createCacheValue(data.stargazers_count));
102
+ } catch {
103
+ // Storage may be full or disabled (private mode); ignore.
104
+ }
90
105
  }
91
106
  })
92
107
  .catch(() => {
@@ -95,7 +110,7 @@ export const GithubStars = (props: GithubStarsProps) => {
95
110
  return () => {
96
111
  cancelled = true;
97
112
  };
98
- }, [repo]);
113
+ }, [isMounted, rawCache, repo, setRawCache]);
99
114
 
100
115
  return (
101
116
  <a
package/dist/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- export type { DarkMode, EditLink, Feature, FrontMatterMeta, Header, Hero, I18nText, LocalSearchOptions, Nav, NavItem, NavItemWithChildren, NavItemWithLink, NavItemWithLinkAndChildren, NormalizedSidebarGroup, PageIndexInfo, RemotePageInfo, RouteMeta, RspressPlugin, Sidebar, SidebarData, SidebarDivider, SidebarGroup, SidebarItem, SidebarSectionHeader, SocialLink, UserConfig, } from '@rspress/shared';
2
- export { getSidebarDataGroup, normalizeHref, normalizePosixPath, RSPRESS_TEMP_DIR, removeTrailingSlash, withBase, } from '@rspress/shared';
1
+ export type { DarkMode, EditLink, Feature, FrontMatterMeta, Header, Hero, I18nText, LlmsTxtContext, LlmsTxtPage, LlmsTxtRenderer, LlmsTxtSection, LocalSearchOptions, Nav, NavItem, NavItemWithChildren, NavItemWithLink, NavItemWithLinkAndChildren, NormalizedSidebarGroup, PageIndexInfo, RemotePageInfo, RouteMeta, RspressPlugin, Sidebar, SidebarData, SidebarDivider, SidebarGroup, SidebarItem, SidebarSectionHeader, SocialLink, UserConfig, } from '@rspress/shared';
2
+ export { getSidebarDataGroup, normalizeHref, normalizePosixPath, RSPRESS_TEMP_DIR, removeTrailingSlash, withBase, withSiteOrigin, } from '@rspress/shared';
3
3
  export { logger } from '@rspress/shared/logger';
4
4
  export { getIconUrlPath, getNodeAttribute, mergeDocConfig, } from '@rspress/shared/node-utils';
5
5
  export { matchPath } from 'react-router-dom';
6
6
  export type { UserConfigAsyncFn } from './config/defineConfig.js';
7
7
  export { defineConfig } from './config/defineConfig.js';
8
+ export { type RunCLIOptions, runCLI } from './cli/index.js';
8
9
  export { build, dev, remarkFileCodeBlock, remarkImage, remarkLink, serve, } from './node/index.js';
9
10
  export type { CustomLinkMeta, DirSectionHeaderSideMeta, DirSideMeta, DividerSideMeta, FileSideMeta, MetaJson, NavJson, SectionHeaderMeta, SideMeta, SideMetaItem, } from './node/auto-nav-sidebar/type.js';
10
11
  export { PluginDriver } from './node/PluginDriver.js';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { PluginDriver } from "./node/PluginDriver.js";
2
- export { RSPRESS_TEMP_DIR, getIconUrlPath, getNodeAttribute, getSidebarDataGroup, logger, matchPath, mergeDocConfig, normalizeHref, normalizePosixPath, removeTrailingSlash, withBase } from "./9882.js";
2
+ export { RSPRESS_TEMP_DIR, getIconUrlPath, getNodeAttribute, getSidebarDataGroup, logger, matchPath, mergeDocConfig, normalizeHref, normalizePosixPath, removeTrailingSlash, withBase, withSiteOrigin } from "./102.js";
3
3
  export { RouteService } from "./node/route/RouteService.js";
4
4
  export { build } from "./node/build.js";
5
5
  export { defineConfig } from "./config/defineConfig.js";
@@ -7,4 +7,5 @@ export { dev } from "./node/dev.js";
7
7
  export { remarkFileCodeBlock } from "./node/mdx/remarkPlugins/fileCodeBlock.js";
8
8
  export { remarkImage } from "./node/mdx/remarkPlugins/image.js";
9
9
  export { remarkLink } from "./node/mdx/remarkPlugins/link.js";
10
+ export { runCLI } from "./cli/index.js";
10
11
  export { serve } from "./node/serve.js";
@@ -1,4 +1,4 @@
1
- import { addTrailingSlash, node_path, addLeadingSlash } from "../6010.js";
1
+ import { addTrailingSlash, node_path, addLeadingSlash } from "../5871.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 "../../6010.js";
1
+ import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../5871.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 "../../6010.js";
1
+ import { node_path } from "../../5871.js";
2
2
  import { walk } from "./walk.js";
3
3
  function combineWalkResult(walks, versions) {
4
4
  return walks.reduce((acc, cur, curIndex)=>({
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../0~rslib-runtime.js";
2
- import "../../7986.js";
3
- import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../6010.js";
2
+ import "../../4538.js";
3
+ import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../5871.js";
4
4
  import { createError } from "../utils/error.js";
5
5
  import { pathExists, extractInfoFromFrontmatterWithAbsolutePath, readJson } from "./utils.js";
6
6
  import { absolutePathToRoutePath, addRoutePrefix } from "../route/RoutePage.js";
@@ -1,4 +1,4 @@
1
- import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../6010.js";
1
+ import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../5871.js";
2
2
  import { createError } from "../utils/error.js";
3
3
  async function pathExists(path) {
4
4
  try {
@@ -1,4 +1,4 @@
1
- import { isExternalUrl, node_path, promises } from "../../6010.js";
1
+ import { isExternalUrl, node_path, promises } from "../../5871.js";
2
2
  import { pathExists } from "../utils/fs.js";
3
3
  import { readJson } from "./utils.js";
4
4
  import { addRoutePrefix } from "../route/RoutePage.js";
@@ -1,4 +1,4 @@
1
- import { isDarkModeSwitchEnabled, node_path, package_namespaceObject, getDefaultDarkModeValue, createRequire } from "../9958.js";
1
+ import { isDarkModeSwitchEnabled, node_path, package_namespaceObject, getDefaultDarkModeValue, createRequire } from "../3553.js";
2
2
  const constants_require = createRequire(import.meta.url);
3
3
  const RSPRESS_VERSION = package_namespaceObject.rE;
4
4
  const APPEARANCE_KEY = 'rspress-theme-appearance';
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../0~rslib-runtime.js";
2
- import "../7986.js";
3
- import { node_path, logger, promises } from "../5580.js";
2
+ import "../4538.js";
3
+ import { node_path, logger, promises } from "../5871.js";
4
4
  import { EJECTED_THEME } from "./constants.js";
5
5
  const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
6
6
  var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
@@ -1,6 +1,8 @@
1
- import { external_node_process_cwd, node_path, external_node_url_fileURLToPath, addTrailingSlash, PLUGIN_REACT_NAME, external_node_module_createRequire, removeTrailingSlash, normalizeDarkMode, pluginReact, pluginVirtualModule, MDX_OR_MD_REGEXP } from "../6010.js";
1
+ import { external_node_process_cwd, node_path, fileURLToPath, addTrailingSlash, PLUGIN_REACT_NAME, removeTrailingSlash, normalizeDarkMode, pluginVirtualModule, pluginReact, createRequire, MDX_OR_MD_REGEXP } from "../5871.js";
2
2
  import { createError } from "./utils/error.js";
3
3
  import { CSR_CLIENT_ENTRY, SSR_CLIENT_ENTRY, OUTPUT_DIR, SSG_MD_SERVER_ENTRY, NODE_SSG_BUNDLE_FOLDER, isProduction, PACKAGE_ROOT, SSR_SERVER_ENTRY, TEMPLATE_PATH, NODE_SSG_MD_BUNDLE_FOLDER, DEFAULT_THEME, NODE_SSG_MD_BUNDLE_NAME, getInlineThemeScript, DEFAULT_TITLE, NODE_SSG_BUNDLE_NAME } from "./constants.js";
4
+ import { isLlmsUIEnabled, isLlmsHintEnabled } from "./llms.js";
5
+ import { RouteChunkAssetsPlugin } from "./route/routeChunkAssets.js";
4
6
  import { hintBuilderPluginsBreakingChange, hintThemeBreakingChange } from "./logger/hint.js";
5
7
  import { resolveReactRouterDomAlias, resolveReactRenderToMarkdownAlias, resolveReactAlias } from "./utils/reactAlias.js";
6
8
  import { rsbuildPluginDocVM } from "./runtimeModule/pageData/rsbuildPlugin.js";
@@ -14,11 +16,11 @@ import { siteDataVMPlugin } from "./runtimeModule/siteData/rsbuildPlugin.js";
14
16
  import { rsbuildPluginSSG } from "./ssg/rsbuildPluginSSG.js";
15
17
  import { rsbuildPluginCSR } from "./ssg/rsbuildPluginCSR.js";
16
18
  import { rsbuildPluginSSGMD } from "./ssg-md/rsbuildPluginSSGMD.js";
17
- import { package_namespaceObject } from "../9958.js";
19
+ import { package_namespaceObject } from "../3553.js";
18
20
  function isPluginIncluded(config, pluginName) {
19
21
  return Boolean(config.builderConfig?.plugins?.some((plugin)=>plugin && plugin.name === pluginName));
20
22
  }
21
- const initRsbuild_require = external_node_module_createRequire(import.meta.url);
23
+ const initRsbuild_require = createRequire(import.meta.url);
22
24
  const RAW_QUERY_REGEXP = /[?&]raw(?:&|=|$)/;
23
25
  const NODE_RSPACK_OPTIMIZATION = {
24
26
  concatenateModules: false,
@@ -39,11 +41,14 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
39
41
  const CUSTOM_THEME_DIR = node_path.isAbsolute(config.themeDir) ? config.themeDir : node_path.join(external_node_process_cwd(), config.themeDir);
40
42
  const outDir = config?.outDir ?? OUTPUT_DIR;
41
43
  const base = config?.base ?? '/';
44
+ const enableLlmsUI = isLlmsUIEnabled(config);
45
+ const enableLlmsHint = isLlmsHintEnabled(config, enableSSG);
42
46
  const assetPrefix = isProduction() ? addTrailingSlash(config?.builderConfig?.output?.assetPrefix ?? base) : '/';
47
+ const routeChunkAssets = new RouteChunkAssetsPlugin(routeService);
43
48
  const normalizeIcon = (icon)=>{
44
49
  if (!icon) return;
45
50
  icon = icon.toString();
46
- if (icon.startsWith('file://')) icon = external_node_url_fileURLToPath(icon);
51
+ if (icon.startsWith('file://')) icon = fileURLToPath(icon);
47
52
  else if (node_path.isAbsolute(icon)) return node_path.join(userDocRoot, "public", icon);
48
53
  return icon;
49
54
  };
@@ -86,10 +91,12 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
86
91
  }),
87
92
  enableSSG && config.ssg ? rsbuildPluginSSG({
88
93
  routeService,
89
- config
94
+ config,
95
+ routeChunkAssets
90
96
  }) : rsbuildPluginCSR({
91
97
  routeService,
92
- config
98
+ config,
99
+ routeChunkAssets
93
100
  }),
94
101
  enableSSG && config.llms ? rsbuildPluginSSGMD({
95
102
  routeService,
@@ -158,7 +165,8 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
158
165
  ],
159
166
  define: {
160
167
  'process.env.TEST': JSON.stringify(process.env.TEST),
161
- 'process.env.ENABLE_LLMS_UI': JSON.stringify(Boolean(config.themeConfig?.llmsUI ?? config.llms))
168
+ 'import.meta.env.ENABLE_LLMS_UI': JSON.stringify(enableLlmsUI),
169
+ 'import.meta.env.ENABLE_LLMS_HINT': JSON.stringify(enableLlmsHint)
162
170
  }
163
171
  },
164
172
  performance: {
@@ -212,7 +220,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
212
220
  chain.module.rule('mdx').test(MDX_OR_MD_REGEXP).resolve.merge({
213
221
  conditionNames: jsModuleRule.resolve.conditionNames.values(),
214
222
  mainFields: jsModuleRule.resolve.mainFields.values()
215
- }).end().oneOf('mdx-raw').type('asset/source').resourceQuery(RAW_QUERY_REGEXP).end().oneOf('mdx').type("javascript/auto").use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(external_node_url_fileURLToPath(new URL('./mdx/loader.js', import.meta.url))).options({
223
+ }).end().oneOf('mdx-raw').type('asset/source').resourceQuery(RAW_QUERY_REGEXP).end().oneOf('mdx').type("javascript/auto").use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(fileURLToPath(new URL('./mdx/loader.js', import.meta.url))).options({
216
224
  config,
217
225
  docDirectory: userDocRoot,
218
226
  routeService,
@@ -271,6 +279,9 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
271
279
  },
272
280
  tools: {
273
281
  rspack: {
282
+ plugins: [
283
+ routeChunkAssets
284
+ ],
274
285
  node: {
275
286
  __dirname: 'mock',
276
287
  __filename: 'mock'
@@ -0,0 +1,3 @@
1
+ import type { UserConfig } from '@rspress/shared';
2
+ export declare function isLlmsUIEnabled(config: UserConfig): boolean;
3
+ export declare function isLlmsHintEnabled(config: UserConfig, enableSSG: boolean): boolean;
@@ -0,0 +1,8 @@
1
+ function isLlmsUIEnabled(config) {
2
+ return Boolean(config.themeConfig?.llmsUI ?? config.llms);
3
+ }
4
+ function isLlmsHintEnabled(config, enableSSG) {
5
+ const llmsUI = config.themeConfig?.llmsUI;
6
+ return enableSSG && false !== config.ssg && isLlmsUIEnabled(config) && ('object' != typeof llmsUI || false !== llmsUI.injectLlmsHint);
7
+ }
8
+ export { isLlmsHintEnabled, isLlmsUIEnabled };
@@ -1,5 +1,5 @@
1
1
  import { __webpack_require__ } from "../../0~rslib-runtime.js";
2
- import { relative, logger, join, readFile } from "../../7986.js";
2
+ import { relative, logger, join, readFile } from "../../4538.js";
3
3
  import { pathExists } from "../utils/fs.js";
4
4
  const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
5
5
  var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
@@ -1,4 +1,4 @@
1
- import { node_path, rehype_external_links, rehype_raw, remark_cjk_friendly, nodeTypes, remark_gfm, rehype, remark_cjk_friendly_gfm_strikethrough } from "../../9283.js";
1
+ import { node_path, rehype_external_links, rehype_raw, remark_cjk_friendly, nodeTypes, remark_gfm, rehype, remark_cjk_friendly_gfm_strikethrough } from "../../9940.js";
2
2
  import { remarkToc } from "./remarkPlugins/toc.js";
3
3
  import { remarkContainerSyntax } from "./remarkPlugins/containerSyntax.js";
4
4
  import { remarkFileCodeBlock } from "./remarkPlugins/fileCodeBlock.js";
@@ -1,4 +1,4 @@
1
- import { node_path, extractTextAndId, createProcessor, loadFrontMatter } from "../../9283.js";
1
+ import { node_path, extractTextAndId, createProcessor, loadFrontMatter } from "../../9940.js";
2
2
  import { createMDXOptions } from "./options.js";
3
3
  import { applyReplaceRules } from "../utils/applyReplaceRules.js";
4
4
  import { escapeMarkdownHeadingIds } from "../utils/escapeHeadingIds.js";
@@ -1,4 +1,4 @@
1
- import { visit } from "../../../9283.js";
1
+ import { visit } from "../../../9940.js";
2
2
  const rehypeCodeMeta = ()=>(tree)=>{
3
3
  visit(tree, 'element', (node)=>{
4
4
  if ('pre' === node.tagName && node.children[0]?.type === 'element' && 'code' === node.children[0].tagName) {
@@ -1,4 +1,4 @@
1
- import { visit, extractTextAndId, github_slugger, headingRank } from "../../../9283.js";
1
+ import { visit, extractTextAndId, github_slugger, headingRank } from "../../../9940.js";
2
2
  const rehypeHeaderAnchor = ()=>{
3
3
  const slugger = new github_slugger();
4
4
  return (tree)=>{
@@ -1,4 +1,4 @@
1
- import { transformerAddLang, transformerAddLineNumbers, transformerAddTitle, transformerAddFold, createCssVariablesTheme, transformerAddWrapCode } from "../../../9283.js";
1
+ import { transformerAddLang, transformerAddLineNumbers, transformerAddTitle, transformerAddFold, createCssVariablesTheme, transformerAddWrapCode } from "../../../9940.js";
2
2
  const cssVariablesTheme = createCssVariablesTheme({
3
3
  name: 'css-variables',
4
4
  variablePrefix: '--shiki-',
@@ -1,4 +1,4 @@
1
- import { node_path } from "../../../9283.js";
1
+ import { node_path } from "../../../9940.js";
2
2
  import { getDefaultImportAstNode } from "../../utils/getImportAstNode.js";
3
3
  const remarkBuiltin = ({ globalComponents })=>(tree)=>{
4
4
  const demos = globalComponents.map((componentPath)=>{
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../../0~rslib-runtime.js";
2
- import "../../../7986.js";
3
- import { visit, node_path, logger, cwd, readFile } from "../../../3358.js";
2
+ import "../../../4538.js";
3
+ import { visit, node_path, logger, cwd, readFile } from "../../../5357.js";
4
4
  import { createError } from "../../utils/error.js";
5
5
  const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
6
6
  var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../../0~rslib-runtime.js";
2
- import "../../../7986.js";
3
- import { visit, node_path, logger, isDataUrl, existsSync, getNodeAttribute, isExternalUrl, isProduction, parseUrl } from "../../../3358.js";
2
+ import "../../../4538.js";
3
+ import { visit, node_path, logger, isDataUrl, existsSync, getNodeAttribute, isExternalUrl, isProduction, parseUrl } from "../../../5357.js";
4
4
  import { createError } from "../../utils/error.js";
5
5
  import { getDefaultImportAstNode } from "../../utils/getImportAstNode.js";
6
6
  const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");