@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
@@ -1 +1,8 @@
1
- export {};
1
+ export type RunCLIOptions = {
2
+ /**
3
+ * The command-line arguments to parse, matching the shape of Node.js `process.argv`
4
+ * @default process.argv
5
+ */
6
+ argv?: string[];
7
+ };
8
+ export declare function runCLI({ argv }?: RunCLIOptions): void;
package/dist/cli/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { __webpack_require__ } from "../0~rslib-runtime.js";
2
- import { node_path, logger, join, cac } from "../5580.js";
3
- import "../7986.js";
4
- import { package_namespaceObject } from "../9958.js";
2
+ import { node_path, logger, join, cac } from "../5871.js";
3
+ import "../4538.js";
4
+ import { package_namespaceObject } from "../3553.js";
5
5
  import { loadConfigFile, resolveDocRoot } from "../config/loadConfigFile.js";
6
6
  import { dev } from "../node/dev.js";
7
7
  import { build } from "../node/build.js";
@@ -14,115 +14,118 @@ const META_FILES = [
14
14
  '_meta.json',
15
15
  '_nav.json'
16
16
  ];
17
- const cli = cac('rspress').version(package_namespaceObject.rE).help();
18
- const landingMessage = `🔥 Rspress v${package_namespaceObject.rE}\n`;
19
- logger.greet(landingMessage);
20
17
  const setNodeEnv = (env)=>{
21
18
  process.env.NODE_ENV = env;
22
19
  };
23
- cli.option('-c, --config <config>', 'Set the configuration file (relative or absolute path)');
24
- cli.command('[root]', 'Start the dev server').alias('dev').option('--port <port>', 'Set the port number for the server').option('--host [host]', 'Set the host that the server listens to').option('--base <base>', 'Set the base path and override config.base').action(async (root, options)=>{
25
- setNodeEnv('development');
26
- let isRestarting = false;
27
- const cwd = process.cwd();
28
- let cliWatcher;
29
- let devServer;
30
- const startDevServer = async ()=>{
31
- const { port, host } = options || {};
32
- const { config, configFilePath } = await loadConfigFile(options?.config);
33
- config.root = resolveDocRoot(cwd, root, config.root);
34
- if (options?.base) config.base = options.base;
35
- const docDirectory = config.root;
36
- devServer = await dev({
37
- appDirectory: cwd,
38
- docDirectory,
39
- config,
40
- configFilePath,
41
- extraBuilderConfig: {
42
- server: {
43
- port,
44
- host
20
+ function runCLI({ argv = process.argv } = {}) {
21
+ const cli = cac('rspress').version(package_namespaceObject.rE).help();
22
+ const landingMessage = `🔥 Rspress v${package_namespaceObject.rE}\n`;
23
+ logger.greet(landingMessage);
24
+ cli.option('-c, --config <config>', 'Set the configuration file (relative or absolute path)');
25
+ cli.command('[root]', 'Start the dev server').alias('dev').option('--port <port>', 'Set the port number for the server').option('--host [host]', 'Set the host that the server listens to').option('--base <base>', 'Set the base path and override config.base').action(async (root, options)=>{
26
+ setNodeEnv('development');
27
+ let isRestarting = false;
28
+ const cwd = process.cwd();
29
+ let cliWatcher;
30
+ let devServer;
31
+ const startDevServer = async ()=>{
32
+ const { port, host } = options || {};
33
+ const { config, configFilePath } = await loadConfigFile(options?.config);
34
+ config.root = resolveDocRoot(cwd, root, config.root);
35
+ if (options?.base) config.base = options.base;
36
+ const docDirectory = config.root;
37
+ devServer = await dev({
38
+ appDirectory: cwd,
39
+ docDirectory,
40
+ config,
41
+ configFilePath,
42
+ extraBuilderConfig: {
43
+ server: {
44
+ port,
45
+ host
46
+ }
45
47
  }
46
- }
47
- });
48
- cliWatcher = chokidar.w([
49
- configFilePath,
50
- docDirectory
51
- ], {
52
- ignoreInitial: true,
53
- ignored: [
54
- '**/node_modules/**',
55
- '**/.git/**',
56
- '**/.DS_Store/**',
57
- join(docDirectory, "public")
58
- ]
59
- });
60
- cliWatcher.on('all', async (eventName, filepath)=>{
61
- const basename = node_path.basename(filepath);
62
- if ('change' === eventName && META_FILES.includes(basename)) return;
63
- if ('add' === eventName || 'unlink' === eventName || 'change' === eventName && filepath === configFilePath) {
64
- if (isRestarting) return;
65
- isRestarting = true;
66
- console.log(`\n✨ ${eventName} ${picocolors_default().green(node_path.relative(cwd, filepath))}, dev server will restart...\n`);
48
+ });
49
+ cliWatcher = chokidar.w([
50
+ configFilePath,
51
+ docDirectory
52
+ ], {
53
+ ignoreInitial: true,
54
+ ignored: [
55
+ '**/node_modules/**',
56
+ '**/.git/**',
57
+ '**/.DS_Store/**',
58
+ join(docDirectory, "public")
59
+ ]
60
+ });
61
+ cliWatcher.on('all', async (eventName, filepath)=>{
62
+ const basename = node_path.basename(filepath);
63
+ if ('change' === eventName && META_FILES.includes(basename)) return;
64
+ if ('add' === eventName || 'unlink' === eventName || 'change' === eventName && filepath === configFilePath) {
65
+ if (isRestarting) return;
66
+ isRestarting = true;
67
+ console.log(`\n✨ ${eventName} ${picocolors_default().green(node_path.relative(cwd, filepath))}, dev server will restart...\n`);
68
+ await devServer.close();
69
+ await cliWatcher.close();
70
+ await startDevServer();
71
+ isRestarting = false;
72
+ }
73
+ });
74
+ };
75
+ await startDevServer();
76
+ const exitProcess = async ()=>{
77
+ try {
67
78
  await devServer.close();
68
79
  await cliWatcher.close();
69
- await startDevServer();
70
- isRestarting = false;
80
+ } finally{
81
+ process.exit(0);
71
82
  }
72
- });
73
- };
74
- await startDevServer();
75
- const exitProcess = async ()=>{
83
+ };
84
+ process.on('SIGINT', exitProcess);
85
+ process.on('SIGTERM', exitProcess);
86
+ });
87
+ cli.command('build [root]', 'Build the documentation site for production').option('--base <base>', 'Set the base path and override config.base').action(async (root, options)=>{
88
+ setNodeEnv('production');
89
+ const cwd = process.cwd();
90
+ const { config, configFilePath } = await loadConfigFile(options.config);
91
+ config.root = resolveDocRoot(cwd, root, config.root);
92
+ if (options.base) config.base = options.base;
93
+ const docDirectory = config.root;
76
94
  try {
77
- await devServer.close();
78
- await cliWatcher.close();
79
- } finally{
80
- process.exit(0);
95
+ await build({
96
+ docDirectory,
97
+ config,
98
+ configFilePath
99
+ });
100
+ } catch (err) {
101
+ logger.error(err);
102
+ process.exit(1);
81
103
  }
82
- };
83
- process.on('SIGINT', exitProcess);
84
- process.on('SIGTERM', exitProcess);
85
- });
86
- cli.command('build [root]', 'Build the documentation site for production').option('--base <base>', 'Set the base path and override config.base').action(async (root, options)=>{
87
- setNodeEnv('production');
88
- const cwd = process.cwd();
89
- const { config, configFilePath } = await loadConfigFile(options.config);
90
- config.root = resolveDocRoot(cwd, root, config.root);
91
- if (options.base) config.base = options.base;
92
- const docDirectory = config.root;
93
- try {
94
- await build({
95
- docDirectory,
104
+ });
105
+ cli.command('preview [root]', 'Preview the production build locally').alias('serve').option('--port <port>', 'Set the port number for the server').option('--host [host]', 'Set the host that the server listens to').option('--base <base>', 'Set the base path and override config.base').action(async (root, options)=>{
106
+ setNodeEnv('production');
107
+ const cwd = process.cwd();
108
+ const { port, host } = options || {};
109
+ const { config, configFilePath } = await loadConfigFile(options?.config);
110
+ config.root = resolveDocRoot(cwd, root, config.root);
111
+ if (options?.base) config.base = options.base;
112
+ await serve({
96
113
  config,
114
+ host,
115
+ port,
97
116
  configFilePath
98
117
  });
99
- } catch (err) {
100
- logger.error(err);
101
- process.exit(1);
102
- }
103
- });
104
- cli.command('preview [root]', 'Preview the production build locally').alias('serve').option('--port <port>', 'Set the port number for the server').option('--host [host]', 'Set the host that the server listens to').option('--base <base>', 'Set the base path and override config.base').action(async (root, options)=>{
105
- setNodeEnv('production');
106
- const cwd = process.cwd();
107
- const { port, host } = options || {};
108
- const { config, configFilePath } = await loadConfigFile(options?.config);
109
- config.root = resolveDocRoot(cwd, root, config.root);
110
- if (options?.base) config.base = options.base;
111
- await serve({
112
- config,
113
- host,
114
- port,
115
- configFilePath
116
118
  });
117
- });
118
- cli.command('eject [component]', 'Eject a theme component for customization').action(async (component)=>{
119
- if (!component) return void await listComponents();
120
- const cwd = process.cwd();
121
- try {
122
- await ejectComponent(component, cwd);
123
- } catch (error) {
124
- logger.error(`Failed to eject component: ${error}`);
125
- process.exit(1);
126
- }
127
- });
128
- cli.parse();
119
+ cli.command('eject [component]', 'Eject a theme component for customization').action(async (component)=>{
120
+ if (!component) return void await listComponents();
121
+ const cwd = process.cwd();
122
+ try {
123
+ await ejectComponent(component, cwd);
124
+ } catch (error) {
125
+ logger.error(`Failed to eject component: ${error}`);
126
+ process.exit(1);
127
+ }
128
+ });
129
+ cli.parse(argv);
130
+ }
131
+ export { runCLI };
@@ -1,4 +1,4 @@
1
- import { node_fs, node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../5580.js";
1
+ import { node_fs, node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../5871.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();
@@ -25,7 +25,7 @@ export const H1 = (props: React.ComponentProps<'h1'>) => {
25
25
  <h1 className={clsx('rp-toc-include', className)} {...rest}>
26
26
  {children} <Tag tag={tag} />
27
27
  </h1>
28
- {process.env.ENABLE_LLMS_UI && placement === 'title' && (
28
+ {import.meta.env.ENABLE_LLMS_UI && placement === 'title' && (
29
29
  <LlmsContainer>
30
30
  <LlmsCopyButton />
31
31
  <LlmsViewOptions />
@@ -68,6 +68,7 @@
68
68
  // fill: var(--rp-home-feature-bg-fill);
69
69
  backdrop-filter: blur(10px);
70
70
  transition: all 0.3s;
71
+ overflow: hidden;
71
72
 
72
73
  &--clickable {
73
74
  cursor: pointer;
@@ -63,9 +63,9 @@ function HomeFeatureItem({ feature }: { feature: Feature }): JSX.Element {
63
63
  className="rp-home-feature__detail"
64
64
  {...renderHtmlOrText(details)}
65
65
  />
66
+ {shineDom}
66
67
  </article>
67
68
  </div>
68
- {shineDom}
69
69
  </div>
70
70
  );
71
71
  }
@@ -46,6 +46,15 @@
46
46
  visibility 0s linear 0.3s;
47
47
  }
48
48
 
49
+ // Keep navigation dropdowns usable before React hydration.
50
+ .rp-nav-menu__item:hover > &--hidden,
51
+ .rp-nav-hamburger:hover > &--hidden {
52
+ visibility: visible;
53
+ opacity: 1;
54
+ pointer-events: auto;
55
+ transition: opacity 0.3s ease-in-out;
56
+ }
57
+
49
58
  &__item {
50
59
  height: 32px;
51
60
  flex: 1;
@@ -41,7 +41,7 @@ nprogress.configure({ showSpinner: false });
41
41
  * Link can tell whether it's in current site or external site.
42
42
  * 1. If external, open a new page and navigate to it.
43
43
  * 2. If inCurrentPage, scroll to anchor.
44
- * 3. If inCurrentSite, it will navigate and scroll to anchor, preload the asyncChunk onHover the link
44
+ * 3. If inCurrentSite, it will navigate and scroll to anchor, prefetch route resources when hovering over the link.
45
45
  * 4. Link is styled.
46
46
  */
47
47
  export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
@@ -7,6 +7,7 @@ import {
7
7
  removeBase,
8
8
  useLocation,
9
9
  useNavigate as useNavigateInner,
10
+ useSite,
10
11
  warmPageData,
11
12
  withBase,
12
13
  } from '@rspress/core/runtime';
@@ -67,12 +68,16 @@ export function getHref(href: string): {
67
68
  * useNavigate with preload logic
68
69
  */
69
70
  export function useLinkNavigate(
70
- { startTransition }: { startTransition?: TransitionStartFunction } = {
71
+ {
72
+ startTransition = reactStartTransition,
73
+ }: { startTransition?: TransitionStartFunction } = {
71
74
  startTransition: reactStartTransition,
72
75
  },
73
76
  ): (href: string) => Promise<void> {
74
77
  const { pathname: currPagePathname } = useLocation();
75
78
  const navigate = useNavigateInner();
79
+ const { site } = useSite();
80
+ const useTransitions = site?.route?.useTransitions;
76
81
 
77
82
  return useCallback(
78
83
  async (href: string) => {
@@ -82,8 +87,10 @@ export function useLinkNavigate(
82
87
  return;
83
88
  }
84
89
 
90
+ const isTransitionable = !!(useTransitions && startTransition);
85
91
  const preloadChunkThenNavigate = async () => {
86
92
  const inCurrPage = isActive(removeBaseHref, currPagePathname);
93
+
87
94
  if (!import.meta.env.SSR && !inCurrPage) {
88
95
  const matchedRoute = pathnameToRouteService(removeBaseHref);
89
96
  if (matchedRoute) {
@@ -99,15 +106,21 @@ export function useLinkNavigate(
99
106
  return;
100
107
  }
101
108
  }
102
- await navigate(removeBaseHref, { replace: false });
109
+ if (isTransitionable) {
110
+ startTransition(() => {
111
+ return navigate(removeBaseHref, { replace: false });
112
+ });
113
+ } else {
114
+ navigate(removeBaseHref, { replace: false });
115
+ }
103
116
  };
104
117
 
105
- if (startTransition) {
118
+ if (isTransitionable) {
106
119
  startTransition(preloadChunkThenNavigate);
107
120
  } else {
108
121
  preloadChunkThenNavigate();
109
122
  }
110
123
  },
111
- [currPagePathname, navigate],
124
+ [useTransitions, currPagePathname, navigate, startTransition],
112
125
  );
113
126
  }
@@ -0,0 +1,23 @@
1
+ import { describe, expect, it, rs } from '@rstest/core';
2
+ import { renderToStaticMarkup } from 'react-dom/server';
3
+ import { LlmsHiddenHint } from './LlmsHiddenHint';
4
+
5
+ rs.mock('@rspress/core/runtime', () => ({
6
+ routePathToMdPath: (path: string) => `/docs${path}index.md`,
7
+ usePageData: () => ({ page: { routePath: '/guide/' } }),
8
+ withBase: (path: string) => `/docs${path}`,
9
+ withSiteOrigin: (path: string) => `https://example.com${path}`,
10
+ }));
11
+
12
+ describe('LlmsHiddenHint', () => {
13
+ it('renders hidden links to the LLM documentation files', () => {
14
+ const html = renderToStaticMarkup(<LlmsHiddenHint />);
15
+
16
+ expect(html).toContain('style="display:none"');
17
+ expect(html).toContain('hidden=""');
18
+ expect(html).toContain('aria-hidden="true"');
19
+ expect(html).toContain(
20
+ 'Are you an LLM? View https://example.com/docs/llms.txt for optimized Markdown documentation, or https://example.com/docs/llms-full.txt for full documentation bundle. This page is also available as Markdown at https://example.com/docs/guide/index.md',
21
+ );
22
+ });
23
+ });
@@ -0,0 +1,15 @@
1
+ import { withBase, withSiteOrigin } from '@rspress/core/runtime';
2
+ import { useMdUrl } from './useMdUrl';
3
+
4
+ export function LlmsHiddenHint() {
5
+ const { pathname } = useMdUrl();
6
+ const llmsTxtUrl = withSiteOrigin(withBase('/llms.txt'));
7
+ const llmsFullTxtUrl = withSiteOrigin(withBase('/llms-full.txt'));
8
+ const pageMdUrl = withSiteOrigin(pathname);
9
+
10
+ return (
11
+ <div style={{ display: 'none' }} hidden aria-hidden="true">
12
+ {`Are you an LLM? View ${llmsTxtUrl} for optimized Markdown documentation, or ${llmsFullTxtUrl} for full documentation bundle. This page is also available as Markdown at ${pageMdUrl}`}
13
+ </div>
14
+ );
15
+ }
@@ -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>