@rspress/core 2.0.0-rc.4 → 2.0.0-rc.6

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 (181) hide show
  1. package/dist/{0~7675.723d12b2.js → 0~7675.d236b058.js} +3 -3
  2. package/dist/{5485.9fc7f63d.js → 5485.7586c86a.js} +1 -1
  3. package/dist/{3521.9eb6b114.js → 7786.421b464f.js} +2 -2
  4. package/dist/9348.1beb3e25.js +11 -0
  5. package/dist/_private/react/render.js +1 -1
  6. package/dist/cli/index.js +2 -2
  7. package/dist/config/defineConfig.d.ts +40 -0
  8. package/dist/{cli/config → config}/loadConfigFile.js +2 -2
  9. package/dist/eject-theme/components/Callout/index.scss +6 -6
  10. package/dist/eject-theme/components/CodeBlock/index.tsx +1 -1
  11. package/dist/eject-theme/components/DocContent/docComponents/title.tsx +21 -2
  12. package/dist/eject-theme/components/FallbackHeading/index.tsx +4 -0
  13. package/dist/eject-theme/components/HomeBackground/useNavTransparent.tsx +2 -1
  14. package/dist/eject-theme/components/HomeHero/index.scss +8 -0
  15. package/dist/eject-theme/components/HomeHero/index.tsx +11 -2
  16. package/dist/eject-theme/components/Llms/LlmsContainer.scss +6 -0
  17. package/dist/eject-theme/components/Llms/LlmsContainer.tsx +9 -0
  18. package/dist/eject-theme/components/Llms/LlmsCopyButton.scss +57 -0
  19. package/dist/eject-theme/components/Llms/LlmsCopyButton.tsx +94 -0
  20. package/dist/eject-theme/components/Llms/LlmsViewOptions.scss +98 -0
  21. package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +259 -0
  22. package/dist/eject-theme/components/Llms/index.scss +42 -0
  23. package/dist/eject-theme/components/Llms/index.tsx +4 -0
  24. package/dist/eject-theme/components/Llms/useMdUrl.ts +14 -0
  25. package/dist/eject-theme/components/Nav/index.scss +3 -0
  26. package/dist/eject-theme/components/Nav/index.tsx +7 -2
  27. package/dist/eject-theme/components/{Nav/NavTitle.tsx → NavTitle/index.tsx} +15 -6
  28. package/dist/eject-theme/components/Overview/index.tsx +8 -62
  29. package/dist/eject-theme/components/OverviewGroup/index.tsx +46 -0
  30. package/dist/eject-theme/components/Steps/index.scss +1 -0
  31. package/dist/index.d.ts +2 -1
  32. package/dist/index.js +3 -4
  33. package/dist/node/PluginDriver.js +1 -1
  34. package/dist/node/auto-nav-sidebar/index.js +1 -1
  35. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  36. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  37. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  38. package/dist/node/constants.js +1 -1
  39. package/dist/node/eject.js +1 -0
  40. package/dist/node/initRsbuild.js +6 -6
  41. package/dist/node/last-updated/index.js +1 -1
  42. package/dist/node/mdx/{loader.7c249a26.js → loader.15e0b2d2.js} +0 -5
  43. package/dist/node/mdx/options.js +2 -2
  44. package/dist/node/mdx/processor.js +1 -1
  45. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  46. package/dist/node/mdx/rehypePlugins/headerAnchor.js +2 -3
  47. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  48. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +1 -2
  49. package/dist/node/mdx/remarkPlugins/image.js +1 -3
  50. package/dist/node/mdx/remarkPlugins/link.js +1 -2
  51. package/dist/node/mdx/remarkPlugins/toc.d.ts +4 -3
  52. package/dist/node/mdx/remarkPlugins/toc.js +14 -11
  53. package/dist/node/route/RoutePage.d.ts +3 -1
  54. package/dist/node/route/RoutePage.js +4 -0
  55. package/dist/node/route/RouteService.js +2 -2
  56. package/dist/node/route/extractPageData.d.ts +5 -0
  57. package/dist/node/route/extractPageData.js +88 -58
  58. package/dist/node/route/normalizeRoutePath.js +2 -2
  59. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +21 -0
  60. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +21 -0
  61. package/dist/node/runtimeModule/i18n.js +4 -3
  62. package/dist/node/runtimeModule/pageData/createPageData.js +9 -6
  63. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +20 -14
  64. package/dist/node/runtimeModule/siteData/createSiteData.js +2 -1
  65. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  66. package/dist/node/serve.js +1 -1
  67. package/dist/node/ssg/renderPage.js +1 -1
  68. package/dist/node/ssg/renderPageWorker.js +1 -1
  69. package/dist/node/ssg/renderPages.js +7 -3
  70. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  71. package/dist/node/ssg/ssgEnv.js +1 -1
  72. package/dist/node/ssg-md/llms/emitLlmsTxt.js +2 -2
  73. package/dist/node/ssg-md/llms/llmsTxt.js +12 -2
  74. package/dist/node/ssg-md/remarkSplitMdx.js +2 -2
  75. package/dist/node/ssg-md/renderPage.js +1 -1
  76. package/dist/node/ssg-md/renderPages.js +1 -1
  77. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  78. package/dist/node/utils/createHash.js +1 -1
  79. package/dist/node/utils/flattenMdxContent.js +2 -3
  80. package/dist/node/utils/getPageKey.js +1 -1
  81. package/dist/node/utils/normalizePath.js +1 -1
  82. package/dist/node/utils/reactAlias.js +1 -1
  83. package/dist/runtime/Content.d.ts +4 -0
  84. package/dist/runtime/Content.js +18 -0
  85. package/dist/runtime/NoSSR.d.ts +3 -0
  86. package/dist/runtime/NoSSR.js +14 -0
  87. package/dist/runtime/getSidebarDataGroup.test.js +68 -0
  88. package/dist/runtime/hooks/useActiveMatcher.d.ts +1 -0
  89. package/dist/runtime/hooks/useActiveMatcher.js +14 -0
  90. package/dist/runtime/hooks/useDark.d.ts +7 -0
  91. package/dist/runtime/hooks/useDark.js +7 -0
  92. package/dist/runtime/hooks/useFrontmatter.d.ts +4 -0
  93. package/dist/runtime/hooks/useFrontmatter.js +9 -0
  94. package/dist/runtime/hooks/useI18n.d.ts +2 -0
  95. package/dist/runtime/hooks/useI18n.js +14 -0
  96. package/dist/runtime/hooks/useLang.d.ts +1 -0
  97. package/dist/runtime/hooks/useLang.js +6 -0
  98. package/dist/runtime/hooks/useLocaleSiteData.d.ts +18 -0
  99. package/dist/runtime/hooks/useLocaleSiteData.js +20 -0
  100. package/dist/runtime/hooks/useNav.d.ts +1 -0
  101. package/dist/runtime/hooks/useNav.js +12 -0
  102. package/dist/runtime/hooks/usePage.d.ts +10 -0
  103. package/dist/runtime/hooks/usePage.js +9 -0
  104. package/dist/runtime/hooks/usePageData.d.ts +5 -0
  105. package/dist/runtime/hooks/usePageData.js +16 -0
  106. package/dist/runtime/hooks/usePages.d.ts +4 -0
  107. package/dist/runtime/hooks/usePages.js +7 -0
  108. package/dist/runtime/hooks/useSidebar.d.ts +16 -0
  109. package/dist/runtime/hooks/useSidebar.js +67 -0
  110. package/dist/runtime/hooks/useSite.d.ts +4 -0
  111. package/dist/runtime/hooks/useSite.js +7 -0
  112. package/dist/runtime/hooks/useVersion.d.ts +1 -0
  113. package/dist/runtime/hooks/useVersion.js +6 -0
  114. package/dist/runtime/hooks/useWindowSize.d.ts +9 -0
  115. package/dist/runtime/hooks/useWindowSize.js +31 -0
  116. package/dist/runtime/hooks/useWindowSize.test.js +36 -0
  117. package/dist/runtime/index.d.ts +21 -0
  118. package/dist/runtime/index.js +22 -0
  119. package/dist/runtime/route.d.ts +36 -0
  120. package/dist/runtime/route.js +53 -0
  121. package/dist/runtime/route.test.js +154 -0
  122. package/dist/runtime/ssrMdServerEntry.js +1 -1
  123. package/dist/runtime/utils.d.ts +12 -0
  124. package/dist/runtime/utils.js +34 -0
  125. package/dist/runtime/utils.test.js +34 -0
  126. package/dist/theme/components/Callout/index.css +6 -6
  127. package/dist/theme/components/CodeBlock/index.js +1 -1
  128. package/dist/theme/components/DocContent/docComponents/title.js +25 -5
  129. package/dist/theme/components/FallbackHeading/index.js +4 -1
  130. package/dist/theme/components/HomeBackground/useNavTransparent.js +1 -1
  131. package/dist/theme/components/HomeHero/index.css +16 -10
  132. package/dist/theme/components/HomeHero/index.js +10 -3
  133. package/dist/theme/components/Llms/LlmsContainer.css +7 -0
  134. package/dist/theme/components/Llms/LlmsContainer.d.ts +5 -0
  135. package/dist/theme/components/Llms/LlmsContainer.js +9 -0
  136. package/dist/theme/components/Llms/LlmsCopyButton.css +57 -0
  137. package/dist/theme/components/Llms/LlmsCopyButton.d.ts +20 -0
  138. package/dist/theme/components/Llms/LlmsCopyButton.js +73 -0
  139. package/dist/theme/components/Llms/LlmsCopyButton.js.LICENSE.txt +5 -0
  140. package/dist/theme/components/Llms/LlmsViewOptions.css +93 -0
  141. package/dist/theme/components/Llms/LlmsViewOptions.d.ts +34 -0
  142. package/dist/theme/components/Llms/LlmsViewOptions.js +206 -0
  143. package/dist/theme/components/Llms/LlmsViewOptions.js.LICENSE.txt +5 -0
  144. package/dist/theme/components/Llms/index.css +32 -0
  145. package/dist/theme/components/Llms/index.d.ts +4 -0
  146. package/dist/theme/components/Llms/index.js +5 -0
  147. package/dist/theme/components/Llms/useMdUrl.d.ts +6 -0
  148. package/dist/theme/components/Llms/useMdUrl.js +15 -0
  149. package/dist/theme/components/Nav/index.css +1 -0
  150. package/dist/theme/components/Nav/index.js +1 -2
  151. package/dist/theme/components/{Nav/NavTitle.d.ts → NavTitle/index.d.ts} +1 -1
  152. package/dist/theme/components/{Nav/NavTitle.js → NavTitle/index.js} +11 -6
  153. package/dist/theme/components/Overview/index.js +11 -43
  154. package/dist/theme/components/OverviewGroup/index.js +33 -0
  155. package/dist/theme/components/PageTabs/index.css +1 -1
  156. package/dist/theme/components/Steps/index.css +1 -0
  157. package/dist/theme/components/Tabs/index.css +4 -4
  158. package/dist/theme/hooks/useDynamicToc.d.ts +2 -0
  159. package/dist/theme/hooks/useDynamicToc.js +3 -1
  160. package/dist/theme/index.d.ts +3 -1
  161. package/dist/theme/index.js +4 -2
  162. package/dist/theme/layout/Layout/index.js +1 -1
  163. package/dist/theme/logic/useScrollAfterNav.js +2 -2
  164. package/dist/theme/logic/useScrollReset.js +2 -2
  165. package/dist/theme/logic/{useAppearance.d.ts → useThemeState.d.ts} +4 -1
  166. package/dist/theme/logic/useThemeState.js +50 -0
  167. package/dist/theme/styles/scrollbar.css +14 -2
  168. package/package.json +18 -20
  169. package/static/MediumZoom.tsx +1 -1
  170. package/dist/4669.69cb6b18.js +0 -1
  171. package/dist/8813.4b28f4bb.js +0 -1
  172. package/dist/9643.2dff683e.js +0 -4
  173. package/dist/cli/config/index.d.ts +0 -2
  174. package/dist/runtime.72d450ac.js +0 -1
  175. package/dist/runtime.d.ts +0 -2
  176. package/dist/runtime.js +0 -3
  177. package/dist/theme/logic/useAppearance.js +0 -64
  178. /package/dist/{cli/config/index.js → config/defineConfig.js} +0 -0
  179. /package/dist/{cli/config → config}/loadConfigFile.d.ts +0 -0
  180. /package/dist/eject-theme/components/{Nav/NavTitle.scss → NavTitle/index.scss} +0 -0
  181. /package/dist/theme/components/{Nav/NavTitle.css → NavTitle/index.css} +0 -0
@@ -1,8 +1,7 @@
1
- import { createRequire, fileURLToPath, package_namespaceObject } from "../5485.9fc7f63d.js";
1
+ import { createRequire, fileURLToPath, package_namespaceObject } from "../5485.7586c86a.js";
2
2
  import { node_path } from "../6289.29817fb4.js";
3
- import { cwd } from "../9643.2dff683e.js";
4
- import { PLUGIN_REACT_NAME, pluginReact, pluginVirtualModule } from "../3521.9eb6b114.js";
5
- import { removeTrailingSlash, MDX_OR_MD_REGEXP } from "../4669.69cb6b18.js";
3
+ import { removeTrailingSlash, MDX_OR_MD_REGEXP, cwd } from "../9348.1beb3e25.js";
4
+ import { PLUGIN_REACT_NAME, pluginReact, pluginVirtualModule } from "../7786.421b464f.js";
6
5
  import { createError } from "./utils/error.js";
7
6
  import { PUBLIC_DIR, CSR_CLIENT_ENTRY, SSR_CLIENT_ENTRY, OUTPUT_DIR, SSG_MD_SERVER_ENTRY, inlineThemeScript, NODE_SSG_BUNDLE_FOLDER, isProduction, PACKAGE_ROOT, SSR_SERVER_ENTRY, TEMPLATE_PATH, NODE_SSG_MD_BUNDLE_FOLDER, DEFAULT_THEME, NODE_SSG_MD_BUNDLE_NAME, DEFAULT_TITLE, NODE_SSG_BUNDLE_NAME } from "./constants.js";
8
7
  import { hintBuilderPluginsBreakingChange, hintThemeBreakingChange } from "./logger/hint.js";
@@ -138,7 +137,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
138
137
  ],
139
138
  '@theme-original': DEFAULT_THEME,
140
139
  '@rspress/core/theme-original': DEFAULT_THEME,
141
- '@rspress/core/runtime': node_path.join(PACKAGE_ROOT, 'dist/runtime.js'),
140
+ '@rspress/core/runtime': node_path.join(PACKAGE_ROOT, 'dist/runtime/index.js'),
142
141
  '@rspress/core/shiki-transformers': node_path.join(PACKAGE_ROOT, 'dist/shiki-transformers.js')
143
142
  }
144
143
  },
@@ -152,7 +151,8 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
152
151
  PACKAGE_ROOT
153
152
  ],
154
153
  define: {
155
- 'process.env.TEST': JSON.stringify(process.env.TEST)
154
+ 'process.env.TEST': JSON.stringify(process.env.TEST),
155
+ 'process.env.ENABLE_LLMS_UI': JSON.stringify(Boolean(config.themeConfig?.llmsUI ?? config.llms))
156
156
  }
157
157
  },
158
158
  performance: {
@@ -1,4 +1,4 @@
1
- import { execa } from "../../0~7675.723d12b2.js";
1
+ import { execa } from "../../0~7675.d236b058.js";
2
2
  function transform(timestamp, lang) {
3
3
  return new Date(timestamp).toLocaleString(lang || 'zh');
4
4
  }
@@ -1,12 +1,7 @@
1
1
  export { default as rehype } from "@shikijs/rehype";
2
2
  export { default as rehype_external_links } from "rehype-external-links";
3
3
  export { default as rehype_raw } from "rehype-raw";
4
- export { default as remark_gfm } from "remark-gfm";
5
4
  export { default as remark_mdx } from "remark-mdx";
6
- export { default as remark_stringify } from "remark-stringify";
7
- export { unified } from "unified";
8
- export { default as github_slugger } from "github-slugger";
9
5
  export { headingRank } from "hast-util-heading-rank";
10
6
  export { transformerAddLang, transformerAddLineNumbers, transformerAddTitle, transformerAddWrapCode } from "@rspress/core/shiki-transformers";
11
7
  export { createCssVariablesTheme } from "shiki";
12
- export { visitChildren } from "unist-util-visit-children";
@@ -1,6 +1,6 @@
1
1
  import { node_path } from "../../6289.29817fb4.js";
2
- import { nodeTypes } from "../../9643.2dff683e.js";
3
- import { rehype_external_links, rehype_raw, remark_gfm, rehype } from "./loader.7c249a26.js";
2
+ import { remark_gfm, nodeTypes } from "../../9348.1beb3e25.js";
3
+ import { rehype, rehype_external_links, rehype_raw } from "./loader.15e0b2d2.js";
4
4
  import { remarkToc } from "./remarkPlugins/toc.js";
5
5
  import { remarkContainerSyntax } from "./remarkPlugins/containerSyntax.js";
6
6
  import { remarkFileCodeBlock } from "./remarkPlugins/fileCodeBlock.js";
@@ -1,5 +1,5 @@
1
1
  import { node_path } from "../../6289.29817fb4.js";
2
- import { createProcessor, loadFrontMatter, extractTextAndId } from "../../9643.2dff683e.js";
2
+ import { createProcessor, loadFrontMatter, extractTextAndId } from "../../9348.1beb3e25.js";
3
3
  import { createMDXOptions } from "./options.js";
4
4
  import { applyReplaceRules } from "../utils/applyReplaceRules.js";
5
5
  import { escapeMarkdownHeadingIds } from "../utils/escapeHeadingIds.js";
@@ -1,4 +1,4 @@
1
- import { visit } from "../../../8813.4b28f4bb.js";
1
+ import { visit } from "../../../9348.1beb3e25.js";
2
2
  const rehypeCodeMeta = ()=>(tree)=>{
3
3
  visit(tree, 'element', (node)=>{
4
4
  if ('pre' === node.tagName && node.children[0]?.type === 'element' && 'code' === node.children[0].tagName) {
@@ -1,6 +1,5 @@
1
- import { extractTextAndId } from "../../../9643.2dff683e.js";
2
- import { github_slugger, headingRank } from "../loader.7c249a26.js";
3
- import { visit } from "../../../8813.4b28f4bb.js";
1
+ import { visit, github_slugger, extractTextAndId } from "../../../9348.1beb3e25.js";
2
+ import { headingRank } from "../loader.15e0b2d2.js";
4
3
  const rehypeHeaderAnchor = ()=>{
5
4
  const slugger = new github_slugger();
6
5
  return (tree)=>{
@@ -1,4 +1,4 @@
1
- import { transformerAddLang, transformerAddLineNumbers, transformerAddTitle, createCssVariablesTheme, transformerAddWrapCode } from "../loader.7c249a26.js";
1
+ import { transformerAddLang, transformerAddLineNumbers, transformerAddTitle, createCssVariablesTheme, transformerAddWrapCode } from "../loader.15e0b2d2.js";
2
2
  const cssVariablesTheme = createCssVariablesTheme({
3
3
  name: 'css-variables',
4
4
  variablePrefix: '--shiki-',
@@ -1,6 +1,5 @@
1
1
  import { node_path, logger, picocolors, readFile } from "../../../6289.29817fb4.js";
2
- import { cwd } from "../../../9643.2dff683e.js";
3
- import { visit } from "../../../8813.4b28f4bb.js";
2
+ import { visit, cwd } from "../../../9348.1beb3e25.js";
4
3
  import { createError } from "../../utils/error.js";
5
4
  const ERROR_PREFIX = '[remarkFileCodeBlock]';
6
5
  function parseFileFromMeta(meta) {
@@ -1,6 +1,4 @@
1
- import { isExternalUrl } from "../../../4669.69cb6b18.js";
2
- import { getNodeAttribute } from "../../../9643.2dff683e.js";
3
- import { visit } from "../../../8813.4b28f4bb.js";
1
+ import { isExternalUrl, getNodeAttribute, visit } from "../../../9348.1beb3e25.js";
4
2
  import { getDefaultImportAstNode } from "../../utils/getImportAstNode.js";
5
3
  const normalizeImageUrl = (imageUrl)=>{
6
4
  if (isExternalUrl(imageUrl) || imageUrl.startsWith('/')) return '';
@@ -1,6 +1,5 @@
1
1
  import { node_path, logger, picocolors } from "../../../6289.29817fb4.js";
2
- import { isExternalUrl, isProduction, addLeadingSlash, parseUrl, normalizeHref, withBase } from "../../../4669.69cb6b18.js";
3
- import { visit } from "../../../8813.4b28f4bb.js";
2
+ import { isExternalUrl, isProduction, addLeadingSlash, parseUrl, normalizeHref, visit, withBase } from "../../../9348.1beb3e25.js";
4
3
  import { hintRelativeMarkdownLink } from "../../logger/hint.js";
5
4
  import { createError } from "../../utils/error.js";
6
5
  function link_checkDeadLinks(checkDeadLinks, internalLinks, file, lint) {
@@ -1,12 +1,13 @@
1
- import type { Root } from 'hast';
1
+ import type { Root as HastRoot } from 'hast';
2
+ import type { Root as MdastRoot } from 'mdast';
2
3
  import type { Plugin } from 'unified';
3
4
  export interface TocItem {
4
5
  id: string;
5
6
  text: string;
6
7
  depth: number;
7
8
  }
8
- export declare const parseToc: (tree: Root) => {
9
+ export declare const parseToc: (tree: MdastRoot | HastRoot) => {
9
10
  title: string;
10
11
  toc: TocItem[];
11
12
  };
12
- export declare const remarkToc: Plugin<[], Root>;
13
+ export declare const remarkToc: Plugin<[], HastRoot>;
@@ -1,5 +1,13 @@
1
- import { extractTextAndId } from "../../../9643.2dff683e.js";
2
- import { github_slugger, visitChildren } from "../loader.7c249a26.js";
1
+ import { github_slugger, visitChildren, extractTextAndId } from "../../../9348.1beb3e25.js";
2
+ const extractChildText = (child)=>{
3
+ if ('link' === child.type) return child.children?.map(extractChildText).join('') ?? '';
4
+ if ('strong' === child.type) return `**${child.children?.map(extractChildText).join('') ?? ''}**`;
5
+ if ('emphasis' === child.type) return `*${child.children?.map(extractChildText).join('') ?? ''}*`;
6
+ if ('delete' === child.type) return `~~${child.children?.map(extractChildText).join('') ?? ''}~~`;
7
+ if ('text' === child.type) return child.value;
8
+ if ('inlineCode' === child.type) return `\`${child.value}\``;
9
+ return '';
10
+ };
3
11
  const parseToc = (tree)=>{
4
12
  let title = '';
5
13
  const toc = [];
@@ -9,22 +17,17 @@ const parseToc = (tree)=>{
9
17
  if (node.depth >= 1 && node.depth < 5) {
10
18
  let customId = '';
11
19
  const text = node.children.map((child)=>{
12
- if ('link' === child.type) return child.children?.map((item)=>item.value).join('');
13
- if ('strong' === child.type) return `**${child.children?.map((item)=>item.value).join('')}**`;
14
- if ('emphasis' === child.type) return `*${child.children?.map((item)=>item.value).join('')}*`;
15
- if ('delete' === child.type) return `~~${child.children?.map((item)=>item.value).join('')}~~`;
16
20
  if ('text' === child.type) {
17
21
  const [textPart, idPart] = extractTextAndId(child.value);
18
22
  customId = idPart;
19
23
  return textPart;
20
24
  }
21
- if ('inlineCode' === child.type) return `\`${child.value}\``;
22
- return '';
23
- }).join('');
25
+ return extractChildText(child);
26
+ }).join('').trim();
24
27
  if (1 === node.depth) {
25
28
  if (!title) title = text;
26
29
  } else {
27
- const id = customId ? customId : slugger.slug(text.trim());
30
+ const id = customId ? customId : slugger.slug(text);
28
31
  const { depth } = node;
29
32
  toc.push({
30
33
  id,
@@ -47,4 +50,4 @@ const remarkToc = function() {
47
50
  if (title) data.pageMeta.title = title;
48
51
  };
49
52
  };
50
- export { remarkToc };
53
+ export { parseToc, remarkToc };
@@ -1,8 +1,10 @@
1
- import type { RouteMeta } from '@rspress/shared';
1
+ import type { PageIndexInfo, RouteMeta } from '@rspress/shared';
2
2
  import { RouteService } from './RouteService.js';
3
3
  export declare class RoutePage {
4
4
  #private;
5
5
  routeMeta: RouteMeta;
6
+ pageIndexInfo?: PageIndexInfo;
7
+ setPageIndexInfo(info: PageIndexInfo): void;
6
8
  static create(absolutePath: string, docsDir: string): RoutePage;
7
9
  static createFromExternal(routePath: string, filepath: string, docDir: string): RoutePage;
8
10
  private constructor();
@@ -5,6 +5,10 @@ import { getPageKey } from "../utils/getPageKey.js";
5
5
  class RoutePage {
6
6
  routeMeta;
7
7
  #docDir;
8
+ pageIndexInfo;
9
+ setPageIndexInfo(info) {
10
+ this.pageIndexInfo = info;
11
+ }
8
12
  static create(absolutePath, docsDir) {
9
13
  const routeMeta = absolutePathToRouteMeta(absolutePath, docsDir, RouteService.getInstance());
10
14
  return new RoutePage(routeMeta, docsDir);
@@ -1,6 +1,6 @@
1
1
  import { node_path, promises } from "../../6289.29817fb4.js";
2
- import { RSPRESS_TEMP_DIR, removeTrailingSlash, addTrailingSlash } from "../../4669.69cb6b18.js";
3
- import { DEFAULT_PAGE_EXTENSIONS, glob } from "../../3521.9eb6b114.js";
2
+ import { RSPRESS_TEMP_DIR, removeTrailingSlash, addTrailingSlash } from "../../9348.1beb3e25.js";
3
+ import { DEFAULT_PAGE_EXTENSIONS, glob } from "../../7786.421b464f.js";
4
4
  import { PUBLIC_DIR } from "../constants.js";
5
5
  import { RoutePage, absolutePathToRoutePath, absolutePathToRelativePath } from "./RoutePage.js";
6
6
  import { createError } from "../utils/error.js";
@@ -5,6 +5,11 @@ interface ExtractPageDataOptions {
5
5
  searchCodeBlocks: boolean;
6
6
  replaceRules: ReplaceRule[];
7
7
  alias: Record<string, string | string[]>;
8
+ extractDescription?: boolean;
9
+ /**
10
+ * Whether search is enabled. When false, skip search index content generation.
11
+ */
12
+ searchEnabled?: boolean;
8
13
  }
9
14
  declare function getPageIndexInfoByRoute(route: RouteMeta, options: ExtractPageDataOptions): Promise<PageIndexInfo>;
10
15
  declare function extractPageData(routeService: RouteService, options: ExtractPageDataOptions): Promise<PageIndexInfo[]>;
@@ -1,21 +1,71 @@
1
1
  import { node_path, promises } from "../../6289.29817fb4.js";
2
- import { htmlToText, compile } from "../../3521.9eb6b114.js";
3
- import { MDX_OR_MD_REGEXP } from "../../4669.69cb6b18.js";
4
- import { loadFrontMatter } from "../../9643.2dff683e.js";
2
+ import { unified, visit, remark_gfm, loadFrontMatter, remark_stringify, MDX_OR_MD_REGEXP } from "../../9348.1beb3e25.js";
3
+ import { remove, remark_parse } from "../../7786.421b464f.js";
5
4
  import { applyReplaceRules } from "../utils/applyReplaceRules.js";
6
5
  import { flattenMdxContent } from "../utils/flattenMdxContent.js";
7
6
  import { importStatementRegex } from "../constants.js";
7
+ import { parseToc } from "../mdx/remarkPlugins/toc.js";
8
8
  function applyReplaceRulesToNestedObject(obj, replaceRules) {
9
9
  for(const key in obj)if ('string' == typeof obj[key]) obj[key] = applyReplaceRules(obj[key], replaceRules);
10
10
  else if ('object' == typeof obj[key] && null !== obj[key]) obj[key] = applyReplaceRulesToNestedObject(obj[key], replaceRules);
11
11
  return obj;
12
12
  }
13
+ const remarkRemoveCodeBlocks = ()=>(tree)=>{
14
+ remove(tree, 'code');
15
+ };
16
+ const remarkRemoveImages = ()=>(tree)=>{
17
+ remove(tree, 'image');
18
+ };
19
+ const remarkStripLinkUrls = ()=>(tree)=>{
20
+ visit(tree, 'link', (node)=>{
21
+ node.url = '';
22
+ });
23
+ };
24
+ const createProcessor = (searchCodeBlocks)=>unified().use(remark_parse).use(remark_gfm).use(remarkRemoveImages).use(remarkStripLinkUrls).use(searchCodeBlocks ? [] : [
25
+ remarkRemoveCodeBlocks
26
+ ]).use(remark_stringify, {
27
+ bullet: '-',
28
+ listItemIndent: 'one'
29
+ });
30
+ const processorWithCode = createProcessor(true);
31
+ const processorWithoutCode = createProcessor(false);
32
+ function extractTextFromNode(node) {
33
+ if ('value' in node && 'string' == typeof node.value) return node.value;
34
+ if ('children' in node && Array.isArray(node.children)) return node.children.map(extractTextFromNode).join('');
35
+ return '';
36
+ }
37
+ const SKIP_NODE_TYPES = new Set([
38
+ 'code',
39
+ 'html',
40
+ 'mdxjsEsm',
41
+ 'mdxFlowExpression',
42
+ 'thematicBreak',
43
+ 'image',
44
+ 'table'
45
+ ]);
46
+ function extractDescription(tree) {
47
+ const textParts = [];
48
+ let foundH1 = false;
49
+ for (const node of tree.children){
50
+ if ('heading' === node.type && 1 === node.depth) {
51
+ foundH1 = true;
52
+ continue;
53
+ }
54
+ if ('heading' === node.type && 2 === node.depth) break;
55
+ if (!SKIP_NODE_TYPES.has(node.type)) {
56
+ if (foundH1) {
57
+ const text = extractTextFromNode(node).trim();
58
+ if (text) textParts.push(text);
59
+ }
60
+ }
61
+ }
62
+ return textParts.join(' ');
63
+ }
13
64
  async function getPageIndexInfoByRoute(route, options) {
14
- const { alias, replaceRules, root, searchCodeBlocks } = options;
65
+ const { alias, replaceRules, root, searchCodeBlocks, extractDescription: extractDescriptionConfig = true, searchEnabled = true } = options;
15
66
  const defaultIndexInfo = {
16
67
  title: '',
17
68
  content: '',
18
- _html: '',
19
69
  _flattenContent: '',
20
70
  routePath: route.routePath,
21
71
  lang: route.lang,
@@ -31,73 +81,48 @@ async function getPageIndexInfoByRoute(route, options) {
31
81
  applyReplaceRulesToNestedObject(frontmatter, replaceRules);
32
82
  const { flattenContent } = await flattenMdxContent(applyReplaceRules(contentWithoutFrontMatter, replaceRules), route.absolutePath, alias);
33
83
  content = flattenContent.replace(importStatementRegex, '');
34
- const { html: rawHtml, title, toc: rawToc } = await compile({
35
- value: content,
36
- filepath: route.absolutePath,
37
- development: 'production' !== process.env.NODE_ENV,
38
- root
39
- });
40
- function encodeHtml(html) {
41
- return html.replace(/<code>([\s\S]*?)<\/\s?code>/gm, function(_match, innerContent) {
42
- return `<code>${innerContent.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;')}</code>`;
43
- });
44
- }
45
- const html = encodeHtml(String(rawHtml));
46
- content = htmlToText(html, {
47
- wordwrap: 80,
48
- selectors: [
49
- {
50
- selector: 'a',
51
- options: {
52
- ignoreHref: true
53
- }
54
- },
55
- {
56
- selector: 'img',
57
- format: 'skip'
58
- },
59
- {
60
- selector: 'pre > code',
61
- format: searchCodeBlocks ? 'block' : 'skip'
62
- },
63
- ...[
64
- 'h1',
65
- 'h2',
66
- 'h3',
67
- 'h4',
68
- 'h5',
69
- 'h6'
70
- ].map((tag)=>({
71
- selector: tag,
72
- options: {
73
- uppercase: false
74
- }
75
- }))
76
- ],
77
- tables: true,
78
- longWordSplit: {
79
- forceWrapOnLimit: true
84
+ content = content.replace(/\r\n/g, '\n');
85
+ const processor = searchCodeBlocks ? processorWithCode : processorWithoutCode;
86
+ const tree = processor.parse(content);
87
+ const { title, toc: rawToc } = parseToc(tree);
88
+ const extractedDescription = frontmatter.description || !extractDescriptionConfig ? '' : extractDescription(tree);
89
+ if (!searchEnabled) return {
90
+ ...defaultIndexInfo,
91
+ title: frontmatter.title || title,
92
+ toc: rawToc.map((item)=>({
93
+ ...item,
94
+ charIndex: -1
95
+ })),
96
+ content: '',
97
+ description: frontmatter.description || extractedDescription || void 0,
98
+ _flattenContent: flattenContent,
99
+ frontmatter: {
100
+ ...frontmatter,
101
+ __content: void 0
80
102
  }
81
- });
82
- if (content.startsWith(title)) content = content.slice(title.length);
103
+ };
104
+ const processedTree = await processor.run(tree);
105
+ let processedContent = String(processor.stringify(processedTree));
106
+ if (processedContent.startsWith(`# ${title}`)) processedContent = processedContent.slice(`# ${title}`.length).trimStart();
83
107
  const toc = rawToc.map((item)=>{
84
108
  const match = item.id.match(/-(\d+)$/);
109
+ const headingPrefix = '#'.repeat(item.depth);
85
110
  let position = -1;
86
111
  if (match) for(let i = 0; i < Number(match[1]); i++){
87
- position = content.indexOf(`\n${item.text}#\n\n`, position + 1);
112
+ position = processedContent.indexOf(`${headingPrefix} ${item.text}`, position + 1);
88
113
  if (-1 === position) break;
89
114
  }
90
115
  return {
91
116
  ...item,
92
- charIndex: content.indexOf(`\n${item.text}#\n\n`, position + 1)
117
+ charIndex: processedContent.indexOf(`${headingPrefix} ${item.text}`, position + 1)
93
118
  };
94
119
  });
95
120
  return {
96
121
  ...defaultIndexInfo,
97
122
  title: frontmatter.title || title,
98
123
  toc,
99
- content,
100
- _html: html,
124
+ content: processedContent,
125
+ description: frontmatter.description || extractedDescription || void 0,
101
126
  _flattenContent: flattenContent,
102
127
  frontmatter: {
103
128
  ...frontmatter,
@@ -106,7 +131,12 @@ async function getPageIndexInfoByRoute(route, options) {
106
131
  };
107
132
  }
108
133
  async function extractPageData(routeService, options) {
109
- const pageData = await Promise.all(routeService.getRoutes().map((routeMeta)=>getPageIndexInfoByRoute(routeMeta, options)));
134
+ const pageData = await Promise.all(routeService.getRoutes().map(async (routeMeta)=>{
135
+ const pageIndexInfo = await getPageIndexInfoByRoute(routeMeta, options);
136
+ const routePage = routeService.getRoutePageByRoutePath(routeMeta.routePath);
137
+ if (routePage) routePage.setPageIndexInfo(pageIndexInfo);
138
+ return pageIndexInfo;
139
+ }));
110
140
  return pageData;
111
141
  }
112
142
  export { extractPageData };
@@ -1,5 +1,5 @@
1
- import { addTrailingSlash, addLeadingSlash } from "../../4669.69cb6b18.js";
2
- import { DEFAULT_PAGE_EXTENSIONS } from "../../3521.9eb6b114.js";
1
+ import { addTrailingSlash, addLeadingSlash } from "../../9348.1beb3e25.js";
2
+ import { DEFAULT_PAGE_EXTENSIONS } from "../../7786.421b464f.js";
3
3
  const getRoutePathParts = (relativePath, lang, version, langs, versions)=>{
4
4
  const [versionPart, langPart, purePath] = splitRoutePathParts(relativePath, lang, version, langs, versions);
5
5
  return [
@@ -118,6 +118,27 @@ export declare const DEFAULT_I18N_TEXT: {
118
118
  readonly ko: "일치하는 API가 없습니다";
119
119
  readonly ru: "Не найден подходящий API";
120
120
  };
121
+ readonly openInText: {
122
+ readonly en: "Open in {{name}}";
123
+ readonly zh: "在 {{name}} 中打开";
124
+ readonly ja: "{{name}} で開く";
125
+ readonly ko: "{{name}}에서 열기";
126
+ readonly ru: "Открыть в {{name}}";
127
+ };
128
+ readonly copyMarkdownText: {
129
+ readonly en: "Copy Markdown";
130
+ readonly zh: "复制 Markdown";
131
+ readonly ja: "Markdown をコピー";
132
+ readonly ko: "마크다운 복사";
133
+ readonly ru: "Скопировать Markdown";
134
+ };
135
+ readonly copyMarkdownLinkText: {
136
+ readonly en: "Copy Markdown link";
137
+ readonly zh: "复制 Markdown 链接";
138
+ readonly ja: "Markdown リンクをコピー";
139
+ readonly ko: "마크다운 링크 복사";
140
+ readonly ru: "Скопировать ссылку в формате Markdown";
141
+ };
121
142
  readonly editLinkText: {
122
143
  readonly en: "📝 Edit this page";
123
144
  readonly zh: "📝 编辑此页面";
@@ -118,6 +118,27 @@ const DEFAULT_I18N_TEXT = {
118
118
  ko: '일치하는 API가 없습니다',
119
119
  ru: 'Не найден подходящий API'
120
120
  },
121
+ openInText: {
122
+ en: 'Open in {{name}}',
123
+ zh: '在 {{name}} 中打开',
124
+ ja: '{{name}} で開く',
125
+ ko: '{{name}}에서 열기',
126
+ ru: 'Открыть в {{name}}'
127
+ },
128
+ copyMarkdownText: {
129
+ en: 'Copy Markdown',
130
+ zh: '复制 Markdown',
131
+ ja: 'Markdown をコピー',
132
+ ko: '마크다운 복사',
133
+ ru: 'Скопировать Markdown'
134
+ },
135
+ copyMarkdownLinkText: {
136
+ en: 'Copy Markdown link',
137
+ zh: '复制 Markdown 链接',
138
+ ja: 'Markdown リンクをコピー',
139
+ ko: '마크다운 링크 복사',
140
+ ru: 'Скопировать ссылку в формате Markdown'
141
+ },
121
142
  editLinkText: {
122
143
  en: '📝 Edit this page',
123
144
  zh: '📝 编辑此页面',
@@ -1,4 +1,4 @@
1
- import { createRequire } from "../../5485.9fc7f63d.js";
1
+ import { createRequire } from "../../5485.7586c86a.js";
2
2
  import { picocolors, join, logger } from "../../6289.29817fb4.js";
3
3
  import { DEFAULT_I18N_TEXT } from "./DEFAULT_I18N_TEXT.js";
4
4
  import { createError } from "../utils/error.js";
@@ -56,13 +56,14 @@ async function getI18nData(docConfig, pluginDriver) {
56
56
  }
57
57
  }
58
58
  if (logKeys.size > 0 && !logged) {
59
- logger.warn(`${logPrefix} The following i18n keys are missing for some languages and have fallen back to 'en':
59
+ logger.warn(`${logPrefix} The following i18n keys are missing for some languages and have fallen back to 'en':
60
60
  ${picocolors.gray(JSON.stringify(Object.fromEntries([
61
61
  ...logKeys.keys()
62
62
  ].map((i)=>[
63
63
  i,
64
64
  '...'
65
- ])), null, 2))}`);
65
+ ])), null, 2))}
66
+ You can provide translations via ${picocolors.cyan('i18n.json')} file or ${picocolors.cyan('i18nSource')} config in rspress.config.ts`);
66
67
  logged = true;
67
68
  }
68
69
  return filteredI18nSource;
@@ -1,5 +1,5 @@
1
- import { SEARCH_INDEX_NAME } from "../../../4669.69cb6b18.js";
2
- import { groupBy } from "../../../3521.9eb6b114.js";
1
+ import { SEARCH_INDEX_NAME } from "../../../9348.1beb3e25.js";
2
+ import { groupBy } from "../../../7786.421b464f.js";
3
3
  import { extractPageData } from "../../route/extractPageData.js";
4
4
  import { createHash } from "../../utils/createHash.js";
5
5
  function deletePrivateField(obj) {
@@ -16,13 +16,16 @@ async function createPageData(context) {
16
16
  const tempSearchObj = Object.assign({}, userConfig.search);
17
17
  if (tempSearchObj) tempSearchObj.searchHooks = void 0;
18
18
  const replaceRules = userConfig?.replaceRules || [];
19
- const searchConfig = userConfig?.search || {};
20
- const searchCodeBlocks = 'codeBlocks' in searchConfig ? Boolean(searchConfig.codeBlocks) : true;
19
+ const searchConfig = userConfig?.search;
20
+ const searchEnabled = false !== searchConfig;
21
+ const searchCodeBlocks = searchConfig && 'object' == typeof searchConfig && 'codeBlocks' in searchConfig ? Boolean(searchConfig.codeBlocks) : true;
21
22
  const pages = await extractPageData(routeService, {
22
23
  replaceRules,
23
24
  alias,
24
25
  root: userDocRoot,
25
- searchCodeBlocks
26
+ searchCodeBlocks,
27
+ extractDescription: userConfig.markdown?.extractDescription,
28
+ searchEnabled
26
29
  });
27
30
  await pluginDriver.modifySearchIndexData(pages);
28
31
  const versioned = 'boolean' != typeof userConfig.search && userConfig.search?.versioned;
@@ -49,7 +52,7 @@ async function createPageData(context) {
49
52
  const filepaths = [];
50
53
  const pageData = {
51
54
  pages: pages.map((page)=>{
52
- const { content: _content, _filepath, _html, _flattenContent, ...rest } = page;
55
+ const { content: _content, _filepath, _flattenContent, ...rest } = page;
53
56
  filepaths.push(_filepath);
54
57
  return rest;
55
58
  })
@@ -1,4 +1,5 @@
1
- import { pluginVirtualModule } from "../../../3521.9eb6b114.js";
1
+ import { logger } from "../../../6289.29817fb4.js";
2
+ import { pluginVirtualModule } from "../../../7786.421b464f.js";
2
3
  import { createPageData } from "./createPageData.js";
3
4
  const rsbuildPluginDocVM = async ({ config, userDocRoot, routeService, pluginDriver })=>{
4
5
  const ref = {
@@ -10,26 +11,31 @@ const rsbuildPluginDocVM = async ({ config, userDocRoot, routeService, pluginDri
10
11
  const searchIndexRsbuildPlugin = {
11
12
  name: 'rsbuild-plugin-searchIndex',
12
13
  async setup (api) {
13
- api.modifyBundlerChain(async (bundlerChain)=>{
14
+ api.modifyBundlerChain(async (bundlerChain, { environment })=>{
14
15
  const alias = bundlerChain.resolve.alias.entries();
15
- const { pageData, indexHashByGroup, searchIndex, filepaths } = await createPageData({
16
- config,
17
- alias: alias,
18
- userDocRoot,
19
- routeService,
20
- pluginDriver
21
- });
22
- ref.pageData = pageData;
23
- ref.searchIndex = searchIndex;
24
- ref.indexHashByGroup = indexHashByGroup;
25
- ref.filepaths = filepaths;
16
+ if ('web' === environment.name) {
17
+ const now = performance.now();
18
+ const { pageData, indexHashByGroup, searchIndex, filepaths } = await createPageData({
19
+ config,
20
+ alias: alias,
21
+ userDocRoot,
22
+ routeService,
23
+ pluginDriver
24
+ });
25
+ logger.debug(`createPageData cost: ${performance.now() - now}ms`);
26
+ ref.pageData = pageData;
27
+ ref.searchIndex = searchIndex;
28
+ ref.indexHashByGroup = indexHashByGroup;
29
+ ref.filepaths = filepaths;
30
+ }
26
31
  api.processAssets({
27
32
  stage: 'report',
28
33
  environments: [
29
34
  'web'
30
35
  ]
31
36
  }, ({ compilation, compiler })=>{
32
- for (const [filename, stringifiedIndex] of Object.entries(searchIndex))compilation.emitAsset(`static/${filename}`, new compiler.webpack.sources.RawSource(stringifiedIndex));
37
+ if (!ref.searchIndex) return;
38
+ for (const [filename, stringifiedIndex] of Object.entries(ref.searchIndex))compilation.emitAsset(`static/${filename}`, new compiler.webpack.sources.RawSource(stringifiedIndex));
33
39
  });
34
40
  });
35
41
  }
@@ -1,4 +1,4 @@
1
- import { getIconUrlPath } from "../../../9643.2dff683e.js";
1
+ import { getIconUrlPath } from "../../../9348.1beb3e25.js";
2
2
  import { normalizeThemeConfig } from "./normalizeThemeConfig.js";
3
3
  async function createSiteData(userConfig) {
4
4
  const tempSearchObj = Object.assign({}, userConfig.search);
@@ -14,6 +14,7 @@ async function createSiteData(userConfig) {
14
14
  locales: userConfig?.locales || userConfig.themeConfig?.locales || [],
15
15
  logo: userConfig?.logo || '',
16
16
  logoText: userConfig?.logoText || '',
17
+ logoHref: userConfig?.logoHref || '',
17
18
  multiVersion: {
18
19
  default: userConfig?.multiVersion?.default || '',
19
20
  versions: userConfig?.multiVersion?.versions || []
@@ -1,4 +1,4 @@
1
- import { isExternalUrl, slash, addLeadingSlash, normalizeHref } from "../../../4669.69cb6b18.js";
1
+ import { isExternalUrl, slash, addLeadingSlash, normalizeHref } from "../../../9348.1beb3e25.js";
2
2
  import { getI18nData } from "../i18n.js";
3
3
  import { applyReplaceRules } from "../../utils/applyReplaceRules.js";
4
4
  async function normalizeThemeConfig(docConfig) {