@rspress/core 2.0.17 → 2.0.19

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 (173) hide show
  1. package/dist/{4538.js → 4538~0.js} +1 -1
  2. package/dist/6305~0.js +3007 -0
  3. package/dist/{7448.js → 8472~0.js} +3 -3
  4. package/dist/{0~execa.js → 864~0.js} +11 -11
  5. package/dist/cli/index.js +13 -40
  6. package/dist/config/defineConfig.d.ts +15 -15
  7. package/dist/config/loadConfigFile.js +1 -1
  8. package/dist/eject-theme/components/DocContent/docComponents/title.tsx +1 -1
  9. package/dist/eject-theme/components/HomeFeature/index.scss +1 -0
  10. package/dist/eject-theme/components/HomeFeature/index.tsx +1 -1
  11. package/dist/eject-theme/components/HoverGroup/index.scss +25 -0
  12. package/dist/eject-theme/components/HoverGroup/index.tsx +22 -1
  13. package/dist/eject-theme/components/Llms/LlmsCopyButton.tsx +2 -6
  14. package/dist/eject-theme/components/Llms/LlmsCopyRow.tsx +2 -5
  15. package/dist/eject-theme/components/Llms/LlmsHint.test.tsx +104 -0
  16. package/dist/eject-theme/components/Llms/LlmsHint.tsx +70 -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/getLlmsCopyContent.test.ts +21 -0
  20. package/dist/eject-theme/components/Llms/getLlmsCopyContent.ts +20 -0
  21. package/dist/eject-theme/components/Llms/index.tsx +6 -1
  22. package/dist/eject-theme/components/Nav/NavMenu.scss +16 -0
  23. package/dist/eject-theme/components/Nav/NavMenu.tsx +12 -0
  24. package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.scss +18 -2
  25. package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.tsx +27 -19
  26. package/dist/eject-theme/components/NavScreen/index.scss +4 -0
  27. package/dist/eject-theme/components/Outline/index.scss +4 -0
  28. package/dist/eject-theme/components/Outline/index.tsx +1 -1
  29. package/dist/eject-theme/components/Sidebar/SidebarGroup.tsx +3 -0
  30. package/dist/eject-theme/components/Sidebar/SidebarItem.scss +16 -0
  31. package/dist/eject-theme/components/Sidebar/SidebarItem.test.tsx +51 -0
  32. package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +10 -1
  33. package/dist/eject-theme/components/Sidebar/SidebarSectionHeader.scss +15 -0
  34. package/dist/eject-theme/components/Sidebar/SidebarSectionHeader.tsx +6 -1
  35. package/dist/eject-theme/components/Sidebar/index.tsx +1 -0
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.js +1 -1
  38. package/dist/node/PluginDriver.js +1 -1
  39. package/dist/node/auto-nav-sidebar/index.js +1 -1
  40. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  41. package/dist/node/auto-nav-sidebar/normalize.js +39 -10
  42. package/dist/node/auto-nav-sidebar/type.d.ts +7 -0
  43. package/dist/node/auto-nav-sidebar/utils.d.ts +1 -0
  44. package/dist/node/auto-nav-sidebar/utils.js +2 -1
  45. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  46. package/dist/node/constants.d.ts +2 -1
  47. package/dist/node/constants.js +50 -2
  48. package/dist/node/dev.d.ts +2 -1
  49. package/dist/node/dev.js +7 -2
  50. package/dist/node/eject.js +3 -3
  51. package/dist/node/initRsbuild.d.ts +6 -2
  52. package/dist/node/initRsbuild.js +49 -14
  53. package/dist/node/last-updated/index.js +112 -15
  54. package/dist/node/llms.d.ts +3 -0
  55. package/dist/node/llms.js +8 -0
  56. package/dist/node/logger/hint.js +2 -2
  57. package/dist/node/mdx/options.js +1 -1
  58. package/dist/node/mdx/processor.js +1 -1
  59. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  60. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  61. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  62. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  63. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +3 -3
  64. package/dist/node/mdx/remarkPlugins/image.js +3 -3
  65. package/dist/node/mdx/remarkPlugins/link.js +3 -3
  66. package/dist/node/mdx/remarkPlugins/toc.js +1 -1
  67. package/dist/node/medium-zoom/index.js +1 -1
  68. package/dist/node/route/RoutePage.js +5 -3
  69. package/dist/node/route/RouteService.js +8 -3
  70. package/dist/node/route/extractPageData.js +3 -15
  71. package/dist/node/route/normalizeRoutePath.js +1 -1
  72. package/dist/node/route/routeChunkAssets.d.ts +15 -0
  73. package/dist/node/route/routeChunkAssets.js +56 -0
  74. package/dist/node/runtimeModule/i18n.js +3 -3
  75. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  76. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  77. package/dist/node/runtimeModule/searchHooks.js +1 -1
  78. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  79. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  80. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  81. package/dist/node/serve.js +1 -1
  82. package/dist/node/ssg/alternateLinks.d.ts +7 -0
  83. package/dist/node/ssg/alternateLinks.js +40 -0
  84. package/dist/node/ssg/htmlFile.js +1 -1
  85. package/dist/node/ssg/renderHtmlTemplate.d.ts +3 -1
  86. package/dist/node/ssg/renderHtmlTemplate.js +25 -3
  87. package/dist/node/ssg/renderPage.d.ts +3 -1
  88. package/dist/node/ssg/renderPage.js +5 -5
  89. package/dist/node/ssg/renderPageWorker.js +5 -5
  90. package/dist/node/ssg/renderPages.d.ts +3 -2
  91. package/dist/node/ssg/renderPages.js +18 -13
  92. package/dist/node/ssg/rsbuildPluginCSR.d.ts +3 -1
  93. package/dist/node/ssg/rsbuildPluginCSR.js +2 -2
  94. package/dist/node/ssg/rsbuildPluginSSG.d.ts +3 -1
  95. package/dist/node/ssg/rsbuildPluginSSG.js +3 -3
  96. package/dist/node/ssg/ssgEnv.js +1 -1
  97. package/dist/node/ssg-md/llms/emitLlmsTxt.js +2 -2
  98. package/dist/node/ssg-md/llms/llmsTxt.d.ts +2 -2
  99. package/dist/node/ssg-md/llms/llmsTxt.js +49 -35
  100. package/dist/node/ssg-md/remarkSplitMdx.js +8 -10
  101. package/dist/node/ssg-md/renderPage.js +3 -3
  102. package/dist/node/ssg-md/renderPages.js +4 -4
  103. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  104. package/dist/node/utils/checkLanguageParity.js +1 -1
  105. package/dist/node/utils/createHash.d.ts +1 -1
  106. package/dist/node/utils/createHash.js +3 -3
  107. package/dist/node/utils/error.js +2 -2
  108. package/dist/node/utils/flattenMdxContent.js +1 -1
  109. package/dist/node/utils/fs.js +1 -1
  110. package/dist/node/utils/getPageKey.js +1 -1
  111. package/dist/node/utils/normalizePath.js +1 -1
  112. package/dist/node/utils/reactAlias.js +3 -3
  113. package/dist/runtime/App.js +7 -2
  114. package/dist/runtime/index.d.ts +2 -1
  115. package/dist/runtime/index.js +2 -1
  116. package/dist/runtime/reactDom.d.ts +19 -0
  117. package/dist/runtime/reactDom.js +5 -0
  118. package/dist/runtime/utils.d.ts +2 -1
  119. package/dist/runtime/utils.js +5 -2
  120. package/dist/theme/assets/anthropic.js +15 -0
  121. package/dist/theme/assets/open-in-chat.js +19 -0
  122. package/dist/theme/assets/openai.js +15 -0
  123. package/dist/theme/components/DocContent/docComponents/title.js +1 -1
  124. package/dist/theme/components/HomeFeature/index.css +1 -0
  125. package/dist/theme/components/HomeFeature/index.js +32 -34
  126. package/dist/theme/components/HoverGroup/index.css +22 -0
  127. package/dist/theme/components/HoverGroup/index.js +17 -1
  128. package/dist/theme/components/Llms/LlmsCopyButton.js +3 -4
  129. package/dist/theme/components/Llms/LlmsCopyRow.js +2 -3
  130. package/dist/theme/components/Llms/LlmsHint.d.ts +2 -0
  131. package/dist/theme/components/Llms/LlmsHint.js +40 -0
  132. package/dist/theme/components/Llms/LlmsOpenRow.js +31 -57
  133. package/dist/theme/components/Llms/LlmsViewOptions.d.ts +6 -4
  134. package/dist/theme/components/Llms/LlmsViewOptions.js +28 -45
  135. package/dist/theme/components/Llms/getLlmsCopyContent.d.ts +1 -0
  136. package/dist/theme/components/Llms/getLlmsCopyContent.js +14 -0
  137. package/dist/theme/components/Llms/index.d.ts +2 -1
  138. package/dist/theme/components/Llms/index.js +1 -0
  139. package/dist/theme/components/Nav/NavMenu.css +15 -0
  140. package/dist/theme/components/Nav/NavMenu.js +8 -0
  141. package/dist/theme/components/NavScreen/NavScreenMenuItem.css +17 -2
  142. package/dist/theme/components/NavScreen/NavScreenMenuItem.js +21 -22
  143. package/dist/theme/components/NavScreen/index.css +4 -0
  144. package/dist/theme/components/Outline/index.css +4 -0
  145. package/dist/theme/components/Outline/index.js +1 -1
  146. package/dist/theme/components/Sidebar/SidebarGroup.js +4 -1
  147. package/dist/theme/components/Sidebar/SidebarItem.css +15 -0
  148. package/dist/theme/components/Sidebar/SidebarItem.d.ts +2 -1
  149. package/dist/theme/components/Sidebar/SidebarItem.js +7 -2
  150. package/dist/theme/components/Sidebar/SidebarSectionHeader.css +14 -0
  151. package/dist/theme/components/Sidebar/SidebarSectionHeader.d.ts +2 -1
  152. package/dist/theme/components/Sidebar/SidebarSectionHeader.js +12 -6
  153. package/dist/theme/components/Sidebar/index.js +1 -0
  154. package/dist/theme/icons.d.ts +4 -1
  155. package/dist/theme/icons.js +8 -2
  156. package/dist/theme/index.d.ts +1 -2
  157. package/dist/theme/index.js +1 -2
  158. package/dist/theme/layout/Layout/index.js +1 -2
  159. package/meta-json-schema.json +33 -3
  160. package/nav-json-schema.json +9 -0
  161. package/package.json +16 -21
  162. package/dist/8629.js +0 -7275
  163. package/dist/8629.js.LICENSE.txt +0 -41
  164. package/dist/theme/logic/useRedirect4FirstVisit.d.ts +0 -5
  165. package/dist/theme/logic/useRedirect4FirstVisit.js +0 -31
  166. /package/dist/{102.js → 102~0.js} +0 -0
  167. /package/dist/{5357.js → 5357~0.js} +0 -0
  168. /package/dist/{7748.js → 7748~0.js} +0 -0
  169. /package/dist/{0~8016.js → 8016~0.js} +0 -0
  170. /package/dist/{9857.js → 9857~0.js} +0 -0
  171. /package/dist/{9940.js → 9940~0.js} +0 -0
  172. /package/dist/{0~rslib-runtime.js → rslib-runtime~0.js} +0 -0
  173. /package/dist/{0~tinypool.js → tinypool~0.js} +0 -0
@@ -1,10 +1,28 @@
1
1
  import { useI18n, useSite } from '@rspress/core/runtime';
2
- import { IconExternalLink, SvgWrapper } from '@rspress/core/theme';
2
+ import {
3
+ copyToClipboard,
4
+ IconAnthropic,
5
+ IconExternalLink,
6
+ IconLink,
7
+ IconOpenAI,
8
+ IconOpenInChat,
9
+ SvgWrapper,
10
+ } from '@rspress/core/theme';
11
+ import type { ReactNode } from 'react';
3
12
  import { useEffect, useMemo, useRef, useState } from 'react';
4
13
  import './LlmsOpenRow.scss';
5
14
  import './LlmsViewOptions.scss';
6
15
  import { useMdUrl } from './useMdUrl';
7
16
 
17
+ type MenuItem = {
18
+ title: string;
19
+ href?: string;
20
+ icon?: ReactNode;
21
+ onClick?: () => void;
22
+ };
23
+
24
+ const DEFAULT_OPTIONS = ['markdownLink', 'chatgpt', 'claude'] as const;
25
+
8
26
  export function LlmsOpenRow() {
9
27
  const t = useI18n();
10
28
  const { pathname } = useMdUrl();
@@ -14,9 +32,11 @@ export function LlmsOpenRow() {
14
32
  const containerRef = useRef<HTMLDivElement>(null);
15
33
 
16
34
  const options =
17
- typeof llmsUI === 'object' && llmsUI?.viewOptions
18
- ? llmsUI.viewOptions
19
- : (['chatgpt', 'claude'] as const);
35
+ typeof llmsUI === 'object'
36
+ ? llmsUI.viewOptions === false
37
+ ? []
38
+ : (llmsUI.viewOptions ?? DEFAULT_OPTIONS)
39
+ : DEFAULT_OPTIONS;
20
40
 
21
41
  useEffect(() => {
22
42
  const handleClickOutside = (event: MouseEvent) => {
@@ -44,48 +64,40 @@ export function LlmsOpenRow() {
44
64
 
45
65
  const q = `Read ${fullMarkdownUrl}, I want to ask questions about it.`;
46
66
 
47
- const builtinItems: Record<
48
- string,
49
- { title: string; href: string; icon: React.ReactNode }
50
- > = useMemo(
67
+ const builtinItems: Record<string, MenuItem> = useMemo(
51
68
  () => ({
69
+ markdownLink: {
70
+ title: t('copyMarkdownLinkText'),
71
+ icon: <SvgWrapper icon={IconLink} />,
72
+ onClick: () => {
73
+ void copyToClipboard(fullMarkdownUrl);
74
+ },
75
+ },
52
76
  chatgpt: {
53
77
  title: t('openInText', { name: 'ChatGPT' }),
54
78
  href: `https://chatgpt.com/?${new URLSearchParams({ hints: 'search', q })}`,
55
- icon: (
56
- <svg
57
- role="img"
58
- viewBox="0 0 24 24"
59
- fill="currentColor"
60
- xmlns="http://www.w3.org/2000/svg"
61
- width="16"
62
- height="16"
63
- >
64
- <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" />
65
- </svg>
66
- ),
79
+ icon: <SvgWrapper icon={IconOpenAI} />,
67
80
  },
68
81
  claude: {
69
82
  title: t('openInText', { name: 'Claude' }),
70
83
  href: `https://claude.ai/new?${new URLSearchParams({ q })}`,
71
- icon: (
72
- <svg
73
- fill="currentColor"
74
- role="img"
75
- viewBox="0 0 24 24"
76
- xmlns="http://www.w3.org/2000/svg"
77
- width="16"
78
- height="16"
79
- >
80
- <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" />
81
- </svg>
82
- ),
84
+ icon: <SvgWrapper icon={IconAnthropic} />,
83
85
  },
84
86
  }),
85
- [t, q],
87
+ [fullMarkdownUrl, t, q],
86
88
  );
87
89
 
88
- if (!pathname) {
90
+ const renderableItems = useMemo(
91
+ () =>
92
+ options
93
+ .map((option): MenuItem | null => {
94
+ return builtinItems[option] ?? null;
95
+ })
96
+ .filter((item): item is MenuItem => item !== null),
97
+ [options, builtinItems],
98
+ );
99
+
100
+ if (!pathname || renderableItems.length === 0) {
89
101
  return null;
90
102
  }
91
103
 
@@ -95,38 +107,12 @@ export function LlmsOpenRow() {
95
107
  className="rp-outline__action-row"
96
108
  onClick={() => setIsOpen(!isOpen)}
97
109
  >
98
- <svg
99
- width="16"
100
- height="16"
101
- viewBox="0 0 24 24"
102
- fill="none"
103
- stroke="currentColor"
104
- strokeWidth="2"
105
- strokeLinecap="round"
106
- strokeLinejoin="round"
107
- >
108
- <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" />
109
- <polyline points="15 3 21 3 21 9" />
110
- <line x1="10" y1="14" x2="21" y2="3" />
111
- </svg>
110
+ <SvgWrapper icon={IconOpenInChat} />
112
111
  <span>{t('openInText', { name: 'chat' })}</span>
113
112
  </button>
114
113
  {isOpen && (
115
114
  <div className="rp-llms-view-options__menu">
116
- {options.map(option => {
117
- let item: {
118
- title: string;
119
- href?: string;
120
- icon?: React.ReactNode;
121
- onClick?: () => void;
122
- };
123
- if (typeof option === 'string' && builtinItems[option]) {
124
- item = builtinItems[option];
125
- } else if (typeof option === 'object' && 'title' in option) {
126
- item = option;
127
- } else {
128
- return null;
129
- }
115
+ {renderableItems.map(item => {
130
116
  if (item.href) {
131
117
  return (
132
118
  <a
@@ -148,7 +134,8 @@ export function LlmsOpenRow() {
148
134
  );
149
135
  }
150
136
  return (
151
- <div
137
+ <button
138
+ type="button"
152
139
  key={item.title}
153
140
  className="rp-llms-view-options__menu-item"
154
141
  onClick={() => {
@@ -160,7 +147,7 @@ export function LlmsOpenRow() {
160
147
  {item.icon}
161
148
  </span>
162
149
  <span>{item.title}</span>
163
- </div>
150
+ </button>
164
151
  );
165
152
  })}
166
153
  </div>
@@ -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
  })}
@@ -0,0 +1,21 @@
1
+ import { afterEach, describe, expect, it, rs } from '@rstest/core';
2
+ import { getLlmsCopyContent } from './getLlmsCopyContent';
3
+
4
+ afterEach(() => {
5
+ rs.restoreAllMocks();
6
+ });
7
+
8
+ describe('getLlmsCopyContent', () => {
9
+ it('fetches Markdown content in production mode', async () => {
10
+ const warnSpy = rs.spyOn(console, 'warn').mockImplementation(() => {});
11
+ const fetchSpy = rs
12
+ .spyOn(globalThis, 'fetch')
13
+ .mockResolvedValue(new Response('# Hello'));
14
+
15
+ await expect(getLlmsCopyContent('/guide/production.md')).resolves.toBe(
16
+ '# Hello',
17
+ );
18
+ expect(fetchSpy).toHaveBeenCalledWith('/guide/production.md');
19
+ expect(warnSpy).not.toHaveBeenCalled();
20
+ });
21
+ });
@@ -0,0 +1,20 @@
1
+ const cache = new Map<string, string>();
2
+
3
+ const DEV_COPY_WARNING =
4
+ 'Warning: Markdown content is unavailable in development mode; run `rspress build` to use this feature.';
5
+
6
+ export async function getLlmsCopyContent(url: string): Promise<string> {
7
+ if (import.meta.env.DEV) {
8
+ console.warn(DEV_COPY_WARNING);
9
+ return DEV_COPY_WARNING;
10
+ }
11
+
12
+ const cachedContent = cache.get(url);
13
+ if (cachedContent !== undefined) {
14
+ return cachedContent;
15
+ }
16
+
17
+ const content = await fetch(url).then(response => response.text());
18
+ cache.set(url, content);
19
+ return content;
20
+ }
@@ -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 { LlmsHint } from './LlmsHint';
4
+ export {
5
+ LlmsViewOptions,
6
+ type LlmsViewOptionsItem,
7
+ type LlmsViewOptionsProps,
8
+ } from './LlmsViewOptions';
4
9
  export { useMdUrl } from './useMdUrl';
@@ -44,6 +44,22 @@
44
44
  transition: transform 0.3s ease-in-out;
45
45
  }
46
46
 
47
+ &__leading-icon {
48
+ width: 16px;
49
+ height: 16px;
50
+ flex: 0 0 16px;
51
+ font-size: 16px;
52
+ line-height: 16px;
53
+ object-fit: contain;
54
+
55
+ > svg,
56
+ > img {
57
+ width: 100%;
58
+ height: 100%;
59
+ object-fit: contain;
60
+ }
61
+ }
62
+
47
63
  &:hover {
48
64
  .rp-nav-menu__item__container {
49
65
  color: var(--rp-c-brand);
@@ -41,12 +41,24 @@ export function NavMenuItemInner({
41
41
  lang={menuItem.lang}
42
42
  rel={menuItem.rel}
43
43
  >
44
+ {menuItem.icon && (
45
+ <SvgWrapper
46
+ icon={menuItem.icon}
47
+ className="rp-nav-menu__item__leading-icon"
48
+ />
49
+ )}
44
50
  {menuItem.text}
45
51
  {menuItem.tag && <Tag tag={menuItem.tag} />}
46
52
  {children}
47
53
  </Link>
48
54
  ) : (
49
55
  <div className="rp-nav-menu__item__container">
56
+ {menuItem.icon && (
57
+ <SvgWrapper
58
+ icon={menuItem.icon}
59
+ className="rp-nav-menu__item__leading-icon"
60
+ />
61
+ )}
50
62
  {menuItem.text}
51
63
  {menuItem.tag && <Tag tag={menuItem.tag} />}
52
64
  {children}
@@ -36,13 +36,29 @@
36
36
  line-height: 22px;
37
37
  }
38
38
 
39
- &__icon {
39
+ &__arrow {
40
40
  transform: rotate(-90deg);
41
41
  transition: transform 0.25s ease-in;
42
42
  }
43
43
 
44
+ &__icon {
45
+ width: 16px;
46
+ height: 16px;
47
+ flex: 0 0 16px;
48
+ font-size: 16px;
49
+ line-height: 16px;
50
+ object-fit: contain;
51
+
52
+ > svg,
53
+ > img {
54
+ width: 100%;
55
+ height: 100%;
56
+ object-fit: contain;
57
+ }
58
+ }
59
+
44
60
  &--open {
45
- .rp-nav-screen-menu-item__icon {
61
+ .rp-nav-screen-menu-item__arrow {
46
62
  transform: rotate(0deg);
47
63
  }
48
64
  }
@@ -19,6 +19,29 @@ export const SvgDown = (props: React.SVGProps<SVGSVGElement>) => {
19
19
  return <SvgWrapper icon={IconArrowDown} {...props} />;
20
20
  };
21
21
 
22
+ function NavScreenMenuItemContent({
23
+ menuItem,
24
+ }: {
25
+ menuItem: {
26
+ icon?: string;
27
+ tag?: string;
28
+ text?: string;
29
+ };
30
+ }) {
31
+ return (
32
+ <>
33
+ {menuItem.icon && (
34
+ <SvgWrapper
35
+ icon={menuItem.icon}
36
+ className="rp-nav-screen-menu-item__icon"
37
+ />
38
+ )}
39
+ {menuItem.text}
40
+ {menuItem.tag && <Tag tag={menuItem.tag} />}
41
+ </>
42
+ );
43
+ }
44
+
22
45
  export function NavScreenMenuItemRaw({
23
46
  left,
24
47
  right,
@@ -79,12 +102,7 @@ export function NavScreenMenuItemWithLink({
79
102
 
80
103
  return (
81
104
  <NavScreenMenuItemRaw
82
- left={
83
- <>
84
- {menuItem.text}
85
- {menuItem.tag && <Tag tag={menuItem.tag} />}
86
- </>
87
- }
105
+ left={<NavScreenMenuItemContent menuItem={menuItem} />}
88
106
  right={null}
89
107
  href={menuItem.link}
90
108
  download={menuItem.download}
@@ -105,13 +123,8 @@ export function NavScreenMenuItemWithChildren({
105
123
  return (
106
124
  <>
107
125
  <NavScreenMenuItemRaw
108
- left={
109
- <>
110
- {menuItem.text}
111
- {menuItem.tag && <Tag tag={menuItem.tag} />}
112
- </>
113
- }
114
- right={<SvgDown className="rp-nav-screen-menu-item__icon" />}
126
+ left={<NavScreenMenuItemContent menuItem={menuItem} />}
127
+ right={<SvgDown className="rp-nav-screen-menu-item__arrow" />}
115
128
  isOpen={isOpen}
116
129
  onClick={() => setIsOpen(!isOpen)}
117
130
  href={'link' in menuItem ? menuItem.link : undefined}
@@ -155,12 +168,7 @@ export function NavScreenMenuItem({ menuItem }: NavScreenMenuItemProps) {
155
168
 
156
169
  return (
157
170
  <NavScreenMenuItemRaw
158
- left={
159
- <>
160
- {menuItem.text}
161
- {menuItem.tag && <Tag tag={menuItem.tag} />}
162
- </>
163
- }
171
+ left={<NavScreenMenuItemContent menuItem={menuItem} />}
164
172
  right={null}
165
173
  />
166
174
  );
@@ -34,4 +34,8 @@
34
34
  height: 1px;
35
35
  background-color: var(--rp-c-divider-light);
36
36
  margin: 1rem 0;
37
+
38
+ &:last-child {
39
+ display: none;
40
+ }
37
41
  }
@@ -35,6 +35,10 @@
35
35
  background: var(--rp-c-divider-light);
36
36
  margin-top: 16px;
37
37
  margin-bottom: 16px;
38
+
39
+ &:has(+ .rp-outline__bottom:empty) {
40
+ display: none;
41
+ }
38
42
  }
39
43
 
40
44
  &__toc {
@@ -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 />
@@ -82,6 +82,7 @@ export function SidebarGroup(props: SidebarGroupProps) {
82
82
  <SidebarItemRaw
83
83
  active={Boolean(active)}
84
84
  link={item.link}
85
+ icon={item.icon}
85
86
  tag={item.tag}
86
87
  text={item.text}
87
88
  context={item.context}
@@ -132,7 +133,9 @@ export function SidebarGroup(props: SidebarGroupProps) {
132
133
  />
133
134
  ) : isSidebarSectionHeader(item) ? (
134
135
  <SidebarSectionHeader
136
+ icon={item.icon}
135
137
  sectionHeaderText={item.sectionHeaderText}
138
+ tag={item.tag}
136
139
  key={index}
137
140
  />
138
141
  ) : (
@@ -76,6 +76,22 @@
76
76
  gap: 4px;
77
77
  }
78
78
 
79
+ &__icon {
80
+ width: 16px;
81
+ height: 16px;
82
+ flex: 0 0 16px;
83
+ font-size: 16px;
84
+ line-height: 16px;
85
+ object-fit: contain;
86
+
87
+ > svg,
88
+ > img {
89
+ width: 100%;
90
+ height: 100%;
91
+ object-fit: contain;
92
+ }
93
+ }
94
+
79
95
  &__right {
80
96
  display: flex;
81
97
  align-items: center;