@rspress/core 2.0.17 → 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 (94) hide show
  1. package/dist/0~execa.js +1 -1
  2. package/dist/{7448.js → 3553.js} +2 -2
  3. package/dist/{8629.js → 5871.js} +3 -3
  4. package/dist/cli/index.js +2 -2
  5. package/dist/config/loadConfigFile.js +1 -1
  6. package/dist/eject-theme/components/DocContent/docComponents/title.tsx +1 -1
  7. package/dist/eject-theme/components/HomeFeature/index.scss +1 -0
  8. package/dist/eject-theme/components/HomeFeature/index.tsx +1 -1
  9. package/dist/eject-theme/components/HoverGroup/index.scss +9 -0
  10. package/dist/eject-theme/components/Llms/LlmsHiddenHint.test.tsx +23 -0
  11. package/dist/eject-theme/components/Llms/LlmsHiddenHint.tsx +15 -0
  12. package/dist/eject-theme/components/Llms/LlmsOpenRow.tsx +51 -64
  13. package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +65 -51
  14. package/dist/eject-theme/components/Llms/index.tsx +6 -1
  15. package/dist/eject-theme/components/Outline/index.tsx +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/node/PluginDriver.js +1 -1
  18. package/dist/node/auto-nav-sidebar/index.js +1 -1
  19. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  20. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  21. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  22. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  23. package/dist/node/constants.js +1 -1
  24. package/dist/node/eject.js +1 -1
  25. package/dist/node/initRsbuild.js +16 -5
  26. package/dist/node/llms.d.ts +3 -0
  27. package/dist/node/llms.js +8 -0
  28. package/dist/node/route/RoutePage.js +5 -3
  29. package/dist/node/route/RouteService.js +8 -3
  30. package/dist/node/route/extractPageData.js +1 -1
  31. package/dist/node/route/normalizeRoutePath.js +1 -1
  32. package/dist/node/route/routeChunkAssets.d.ts +15 -0
  33. package/dist/node/route/routeChunkAssets.js +56 -0
  34. package/dist/node/runtimeModule/i18n.js +1 -1
  35. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  36. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  37. package/dist/node/runtimeModule/searchHooks.js +1 -1
  38. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  39. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  40. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  41. package/dist/node/serve.js +1 -1
  42. package/dist/node/ssg/alternateLinks.d.ts +7 -0
  43. package/dist/node/ssg/alternateLinks.js +40 -0
  44. package/dist/node/ssg/htmlFile.js +1 -1
  45. package/dist/node/ssg/renderHtmlTemplate.d.ts +3 -1
  46. package/dist/node/ssg/renderHtmlTemplate.js +25 -3
  47. package/dist/node/ssg/renderPage.d.ts +3 -1
  48. package/dist/node/ssg/renderPage.js +3 -3
  49. package/dist/node/ssg/renderPageWorker.js +4 -4
  50. package/dist/node/ssg/renderPages.d.ts +3 -2
  51. package/dist/node/ssg/renderPages.js +15 -10
  52. package/dist/node/ssg/rsbuildPluginCSR.d.ts +3 -1
  53. package/dist/node/ssg/rsbuildPluginCSR.js +2 -2
  54. package/dist/node/ssg/rsbuildPluginSSG.d.ts +3 -1
  55. package/dist/node/ssg/rsbuildPluginSSG.js +3 -3
  56. package/dist/node/ssg/ssgEnv.js +1 -1
  57. package/dist/node/ssg-md/llms/emitLlmsTxt.js +2 -2
  58. package/dist/node/ssg-md/llms/llmsTxt.d.ts +2 -2
  59. package/dist/node/ssg-md/llms/llmsTxt.js +49 -35
  60. package/dist/node/ssg-md/renderPage.js +1 -1
  61. package/dist/node/ssg-md/renderPages.js +2 -2
  62. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  63. package/dist/node/utils/checkLanguageParity.js +1 -1
  64. package/dist/node/utils/createHash.d.ts +1 -1
  65. package/dist/node/utils/createHash.js +3 -3
  66. package/dist/node/utils/flattenMdxContent.js +1 -1
  67. package/dist/node/utils/getPageKey.js +1 -1
  68. package/dist/node/utils/reactAlias.js +1 -1
  69. package/dist/runtime/App.js +2 -0
  70. package/dist/runtime/index.d.ts +1 -1
  71. package/dist/runtime/index.js +1 -1
  72. package/dist/runtime/utils.d.ts +2 -1
  73. package/dist/runtime/utils.js +5 -2
  74. package/dist/theme/assets/anthropic.js +15 -0
  75. package/dist/theme/assets/open-in-chat.js +19 -0
  76. package/dist/theme/assets/openai.js +15 -0
  77. package/dist/theme/components/DocContent/docComponents/title.js +1 -1
  78. package/dist/theme/components/HomeFeature/index.css +1 -0
  79. package/dist/theme/components/HomeFeature/index.js +32 -34
  80. package/dist/theme/components/HoverGroup/index.css +7 -0
  81. package/dist/theme/components/Llms/LlmsHiddenHint.d.ts +1 -0
  82. package/dist/theme/components/Llms/LlmsHiddenHint.js +18 -0
  83. package/dist/theme/components/Llms/LlmsOpenRow.js +31 -57
  84. package/dist/theme/components/Llms/LlmsViewOptions.d.ts +6 -4
  85. package/dist/theme/components/Llms/LlmsViewOptions.js +28 -45
  86. package/dist/theme/components/Llms/index.d.ts +2 -1
  87. package/dist/theme/components/Llms/index.js +1 -0
  88. package/dist/theme/components/Outline/index.js +1 -1
  89. package/dist/theme/icons.d.ts +4 -1
  90. package/dist/theme/icons.js +8 -2
  91. package/dist/theme/index.d.ts +1 -1
  92. package/dist/theme/index.js +1 -1
  93. package/package.json +4 -4
  94. /package/dist/{8629.js.LICENSE.txt → 5871.js.LICENSE.txt} +0 -0
package/dist/0~execa.js CHANGED
@@ -8,7 +8,7 @@ import { createReadStream, createWriteStream, readFileSync } from "node:fs";
8
8
  import { setTimeout as promises_setTimeout } from "node:timers/promises";
9
9
  import { debuglog } from "node:util";
10
10
  import { __webpack_require__ } from "./0~rslib-runtime.js";
11
- import "./8629.js";
11
+ import "./5871.js";
12
12
  __webpack_require__.add({
13
13
  "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js" (module, __unused_rspack_exports, __webpack_require__) {
14
14
  const cp = __webpack_require__("child_process");
@@ -1,5 +1,5 @@
1
1
  var package_namespaceObject = {
2
- rE: "2.0.17"
2
+ rE: "2.0.18"
3
3
  };
4
4
  async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true, signal } = {}) {
5
5
  return new Promise((resolve_, reject_)=>{
@@ -94,7 +94,7 @@ async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true,
94
94
  const pMapSkip = Symbol('skip');
95
95
  export { getDefaultDarkModeValue, isDarkModeSwitchEnabled } from "@rspress/shared";
96
96
  export { createRequire } from "node:module";
97
- export { default as node_path, isAbsolute, relative, resolve as external_node_path_resolve } from "node:path";
97
+ export { default as node_path, isAbsolute, posix, relative, resolve as external_node_path_resolve } from "node:path";
98
98
  export { pathToFileURL } from "node:url";
99
99
  export { logger } from "@rspress/shared/logger";
100
100
  export { createHead, transformHtmlTemplate } from "@unhead/react/server";
@@ -1,4 +1,4 @@
1
- /*! LICENSE: 8629.js.LICENSE.txt */
1
+ /*! LICENSE: 5871.js.LICENSE.txt */
2
2
  import node_path, { extname, join, relative as external_node_path_relative } from "node:path";
3
3
  import { __webpack_require__ } from "./0~rslib-runtime.js";
4
4
  import { fileURLToPath as external_url_fileURLToPath } from "url";
@@ -7259,7 +7259,8 @@ export { createRequire } from "node:module";
7259
7259
  export { cwd as external_node_process_cwd } from "node:process";
7260
7260
  export { fileURLToPath, pathToFileURL } from "node:url";
7261
7261
  export { PLUGIN_REACT_NAME, pluginReact } from "@rsbuild/plugin-react";
7262
- export { MDX_OR_MD_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, getSidebarDataGroup, isDebugMode, isExternalUrl, isProduction, normalizeDarkMode, normalizeHref, removeLeadingSlash, removeTrailingSlash, slash, withBase, withSiteOrigin } from "@rspress/shared";
7262
+ export { MDX_OR_MD_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, getSidebarDataGroup, isDebugMode, isExternalUrl, isProduction, normalizeDarkMode, normalizeHref, normalizePosixPath, removeLeadingSlash, removeTrailingSlash, slash, withBase, withSiteOrigin } from "@rspress/shared";
7263
+ export { createHash } from "node:crypto";
7263
7264
  export { chunk, groupBy } from "@rspress/shared/lodash-es";
7264
7265
  export { extractTextAndId, getIconUrlPath, loadFrontMatter } from "@rspress/shared/node-utils";
7265
7266
  export { default as remark_gfm } from "remark-gfm";
@@ -7268,7 +7269,6 @@ export { unified } from "unified";
7268
7269
  export { remove } from "unist-util-remove";
7269
7270
  export { createProcessor } from "@mdx-js/mdx";
7270
7271
  export { mergeRsbuildConfig, rspack as core_rspack } from "@rsbuild/core";
7271
- export { createHash } from "node:crypto";
7272
7272
  export { default as node_os } from "node:os";
7273
7273
  export { matchPath } from "react-router-dom";
7274
7274
  export { createHead } from "@unhead/react/server";
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 "../8629.js";
2
+ import { node_path, logger, join, cac } from "../5871.js";
3
3
  import "../4538.js";
4
- import { package_namespaceObject } from "../7448.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";
@@ -1,4 +1,4 @@
1
- import { node_fs, node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../8629.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;
@@ -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>
@@ -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 />
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
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';
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
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';
@@ -1,4 +1,4 @@
1
- import { addTrailingSlash, node_path, addLeadingSlash } from "../8629.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 "../../8629.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 "../../8629.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
2
  import "../../4538.js";
3
- import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../8629.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 "../../8629.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 "../../8629.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 "../7448.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
2
  import "../4538.js";
3
- import { node_path, logger, promises } from "../8629.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);