@rspress/core 2.0.18 → 2.0.20

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 (157) hide show
  1. package/dist/2711~0.js +3007 -0
  2. package/dist/{4538.js → 4538~0.js} +1 -1
  3. package/dist/{5357.js → 5357~0.js} +1 -1
  4. package/dist/{3553.js → 8472~0.js} +3 -3
  5. package/dist/{0~execa.js → 864~0.js} +11 -11
  6. package/dist/cli/index.js +13 -40
  7. package/dist/config/defineConfig.d.ts +15 -15
  8. package/dist/config/loadConfigFile.js +2 -3
  9. package/dist/eject-theme/components/HoverGroup/index.scss +16 -0
  10. package/dist/eject-theme/components/HoverGroup/index.tsx +22 -1
  11. package/dist/eject-theme/components/Llms/LlmsCopyButton.tsx +2 -6
  12. package/dist/eject-theme/components/Llms/LlmsCopyRow.tsx +2 -5
  13. package/dist/eject-theme/components/Llms/LlmsHint.test.tsx +104 -0
  14. package/dist/eject-theme/components/Llms/LlmsHint.tsx +74 -0
  15. package/dist/eject-theme/components/Llms/getLlmsCopyContent.test.ts +21 -0
  16. package/dist/eject-theme/components/Llms/getLlmsCopyContent.ts +20 -0
  17. package/dist/eject-theme/components/Llms/index.tsx +1 -1
  18. package/dist/eject-theme/components/Nav/NavMenu.scss +16 -0
  19. package/dist/eject-theme/components/Nav/NavMenu.tsx +12 -0
  20. package/dist/eject-theme/components/Nav/hooks.tsx +1 -2
  21. package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.scss +18 -2
  22. package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.tsx +27 -19
  23. package/dist/eject-theme/components/NavScreen/index.scss +4 -0
  24. package/dist/eject-theme/components/Outline/index.scss +4 -0
  25. package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +1 -1
  26. package/dist/eject-theme/components/Sidebar/SidebarGroup.tsx +3 -0
  27. package/dist/eject-theme/components/Sidebar/SidebarItem.scss +16 -0
  28. package/dist/eject-theme/components/Sidebar/SidebarItem.test.tsx +51 -0
  29. package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +10 -1
  30. package/dist/eject-theme/components/Sidebar/SidebarSectionHeader.scss +15 -0
  31. package/dist/eject-theme/components/Sidebar/SidebarSectionHeader.tsx +6 -1
  32. package/dist/eject-theme/components/Sidebar/index.tsx +1 -0
  33. package/dist/index.js +1 -1
  34. package/dist/node/PluginDriver.js +1 -1
  35. package/dist/node/auto-nav-sidebar/index.js +1 -1
  36. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  37. package/dist/node/auto-nav-sidebar/normalize.js +40 -12
  38. package/dist/node/auto-nav-sidebar/type.d.ts +7 -0
  39. package/dist/node/auto-nav-sidebar/utils.d.ts +1 -0
  40. package/dist/node/auto-nav-sidebar/utils.js +2 -1
  41. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  42. package/dist/node/constants.d.ts +2 -1
  43. package/dist/node/constants.js +50 -2
  44. package/dist/node/dev.d.ts +2 -1
  45. package/dist/node/dev.js +7 -2
  46. package/dist/node/eject.js +3 -3
  47. package/dist/node/initRsbuild.d.ts +6 -2
  48. package/dist/node/initRsbuild.js +37 -13
  49. package/dist/node/last-updated/index.js +113 -16
  50. package/dist/node/logger/hint.js +2 -2
  51. package/dist/node/mdx/options.js +3 -2
  52. package/dist/node/mdx/processor.js +1 -1
  53. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  54. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  55. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  56. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  57. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +3 -3
  58. package/dist/node/mdx/remarkPlugins/image.js +3 -3
  59. package/dist/node/mdx/remarkPlugins/link.d.ts +2 -1
  60. package/dist/node/mdx/remarkPlugins/link.js +8 -7
  61. package/dist/node/mdx/remarkPlugins/toc.js +1 -1
  62. package/dist/node/medium-zoom/index.js +1 -1
  63. package/dist/node/route/RoutePage.d.ts +0 -1
  64. package/dist/node/route/RoutePage.js +4 -6
  65. package/dist/node/route/RouteService.js +1 -1
  66. package/dist/node/route/extractPageData.js +3 -15
  67. package/dist/node/route/normalizeRoutePath.js +2 -3
  68. package/dist/node/runtimeModule/i18n.js +3 -3
  69. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  70. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  71. package/dist/node/runtimeModule/searchHooks.js +1 -1
  72. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  73. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  74. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  75. package/dist/node/serve.js +1 -1
  76. package/dist/node/ssg/alternateLinks.js +1 -1
  77. package/dist/node/ssg/htmlFile.js +1 -1
  78. package/dist/node/ssg/renderHtmlTemplate.js +1 -1
  79. package/dist/node/ssg/renderPage.js +3 -3
  80. package/dist/node/ssg/renderPageWorker.js +2 -2
  81. package/dist/node/ssg/renderPages.js +6 -6
  82. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  83. package/dist/node/ssg/ssgEnv.js +1 -1
  84. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  85. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  86. package/dist/node/ssg-md/remarkSplitMdx.js +8 -10
  87. package/dist/node/ssg-md/renderPage.js +3 -3
  88. package/dist/node/ssg-md/renderPages.js +4 -4
  89. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  90. package/dist/node/utils/checkLanguageParity.js +1 -1
  91. package/dist/node/utils/createHash.js +1 -1
  92. package/dist/node/utils/error.js +2 -2
  93. package/dist/node/utils/flattenMdxContent.js +2 -2
  94. package/dist/node/utils/fs.js +1 -1
  95. package/dist/node/utils/getPageKey.js +1 -1
  96. package/dist/node/utils/normalizePath.js +1 -1
  97. package/dist/node/utils/reactAlias.js +3 -3
  98. package/dist/runtime/App.js +7 -4
  99. package/dist/runtime/csrClientEntry.js +7 -2
  100. package/dist/runtime/index.d.ts +1 -0
  101. package/dist/runtime/index.js +1 -0
  102. package/dist/runtime/reactDom.d.ts +19 -0
  103. package/dist/runtime/reactDom.js +5 -0
  104. package/dist/runtime/route.d.ts +10 -0
  105. package/dist/runtime/route.js +13 -2
  106. package/dist/runtime/ssrClientEntry.js +2 -0
  107. package/dist/theme/components/HoverGroup/index.css +15 -0
  108. package/dist/theme/components/HoverGroup/index.js +17 -1
  109. package/dist/theme/components/Llms/LlmsCopyButton.js +3 -4
  110. package/dist/theme/components/Llms/LlmsCopyRow.js +2 -3
  111. package/dist/theme/components/Llms/LlmsHint.d.ts +2 -0
  112. package/dist/theme/components/Llms/LlmsHint.js +44 -0
  113. package/dist/theme/components/Llms/getLlmsCopyContent.d.ts +1 -0
  114. package/dist/theme/components/Llms/getLlmsCopyContent.js +14 -0
  115. package/dist/theme/components/Llms/index.d.ts +1 -1
  116. package/dist/theme/components/Llms/index.js +1 -1
  117. package/dist/theme/components/Nav/NavMenu.css +15 -0
  118. package/dist/theme/components/Nav/NavMenu.js +8 -0
  119. package/dist/theme/components/Nav/hooks.js +1 -2
  120. package/dist/theme/components/NavScreen/NavScreenMenuItem.css +17 -2
  121. package/dist/theme/components/NavScreen/NavScreenMenuItem.js +21 -22
  122. package/dist/theme/components/NavScreen/index.css +4 -0
  123. package/dist/theme/components/Outline/index.css +4 -0
  124. package/dist/theme/components/Search/logic/providers/LocalProvider.js +1 -1
  125. package/dist/theme/components/Sidebar/SidebarGroup.js +4 -1
  126. package/dist/theme/components/Sidebar/SidebarItem.css +15 -0
  127. package/dist/theme/components/Sidebar/SidebarItem.d.ts +2 -1
  128. package/dist/theme/components/Sidebar/SidebarItem.js +7 -2
  129. package/dist/theme/components/Sidebar/SidebarSectionHeader.css +14 -0
  130. package/dist/theme/components/Sidebar/SidebarSectionHeader.d.ts +2 -1
  131. package/dist/theme/components/Sidebar/SidebarSectionHeader.js +12 -6
  132. package/dist/theme/components/Sidebar/index.js +1 -0
  133. package/dist/theme/components/SwitchAppearance/global.css +3 -16
  134. package/dist/theme/index.d.ts +1 -2
  135. package/dist/theme/index.js +1 -2
  136. package/dist/theme/layout/Layout/index.js +1 -2
  137. package/dist/theme/logic/utils.d.ts +4 -0
  138. package/dist/theme/logic/utils.js +23 -2
  139. package/dist/theme/styles/preflight.css +0 -2
  140. package/meta-json-schema.json +33 -3
  141. package/nav-json-schema.json +9 -0
  142. package/package.json +18 -23
  143. package/dist/5871.js +0 -7275
  144. package/dist/5871.js.LICENSE.txt +0 -41
  145. package/dist/eject-theme/components/Llms/LlmsHiddenHint.test.tsx +0 -23
  146. package/dist/eject-theme/components/Llms/LlmsHiddenHint.tsx +0 -15
  147. package/dist/theme/components/Llms/LlmsHiddenHint.d.ts +0 -1
  148. package/dist/theme/components/Llms/LlmsHiddenHint.js +0 -18
  149. package/dist/theme/logic/useRedirect4FirstVisit.d.ts +0 -5
  150. package/dist/theme/logic/useRedirect4FirstVisit.js +0 -31
  151. /package/dist/{102.js → 102~0.js} +0 -0
  152. /package/dist/{7748.js → 7748~0.js} +0 -0
  153. /package/dist/{0~8016.js → 8016~0.js} +0 -0
  154. /package/dist/{9857.js → 9857~0.js} +0 -0
  155. /package/dist/{9940.js → 9940~0.js} +0 -0
  156. /package/dist/{0~rslib-runtime.js → rslib-runtime~0.js} +0 -0
  157. /package/dist/{0~tinypool.js → tinypool~0.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { __webpack_require__ } from "./0~rslib-runtime.js";
1
+ import { __webpack_require__ } from "./rslib-runtime~0.js";
2
2
  __webpack_require__.add({
3
3
  "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js" (module) {
4
4
  let p = process || {}, argv = p.argv || [], env = p.env || {};
@@ -4,5 +4,5 @@ export { cwd } from "node:process";
4
4
  export { logger } from "@rspress/shared/logger";
5
5
  export { visit } from "unist-util-visit";
6
6
  export { existsSync } from "node:fs";
7
- export { MDX_OR_MD_REGEXP, addLeadingSlash, isDataUrl, isExternalUrl, isProduction, normalizeHref, parseUrl, withBase } from "@rspress/shared";
7
+ export { MDX_OR_MD_REGEXP, addLeadingSlash, isDataUrl, isExternalUrl, isProduction, normalizeHref, parseUrl, withBase, withSiteOrigin } from "@rspress/shared";
8
8
  export { getNodeAttribute } from "@rspress/shared/node-utils";
@@ -1,11 +1,11 @@
1
1
  var package_namespaceObject = {
2
- rE: "2.0.18"
2
+ rE: "2.0.20"
3
3
  };
4
4
  async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true, signal } = {}) {
5
5
  return new Promise((resolve_, reject_)=>{
6
6
  if (void 0 === iterable[Symbol.iterator] && void 0 === iterable[Symbol.asyncIterator]) throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
7
7
  if ('function' != typeof mapper) throw new TypeError('Mapper function is required');
8
- if (!(Number.isSafeInteger(concurrency) && concurrency >= 1 || concurrency === 1 / 0)) throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
8
+ if (!(Number.isSafeInteger(concurrency) && concurrency >= 1 || 1 / 0 === concurrency)) throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
9
9
  const result = [];
10
10
  const errors = [];
11
11
  const skippedIndexesMap = new Map();
@@ -32,7 +32,7 @@ async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true,
32
32
  cleanup();
33
33
  };
34
34
  if (signal) {
35
- if (signal.aborted) reject(signal.reason);
35
+ if (signal.aborted) return void reject(signal.reason);
36
36
  signal.addEventListener('abort', signalListener, {
37
37
  once: true
38
38
  });
@@ -1,5 +1,5 @@
1
- import { Buffer } from "node:buffer";
2
1
  import node_path from "node:path";
2
+ import { Buffer } from "node:buffer";
3
3
  import node_child_process, { ChildProcess } from "node:child_process";
4
4
  import node_process from "node:process";
5
5
  import { fileURLToPath } from "node:url";
@@ -7,8 +7,8 @@ import node_os, { constants } from "node:os";
7
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
- import { __webpack_require__ } from "./0~rslib-runtime.js";
11
- import "./5871.js";
10
+ import { __webpack_require__ } from "./rslib-runtime~0.js";
11
+ import "./2711~0.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");
@@ -70,7 +70,7 @@ __webpack_require__.add({
70
70
  };
71
71
  },
72
72
  "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js" (module, __unused_rspack_exports, __webpack_require__) {
73
- const path = __webpack_require__("path?aeb1");
73
+ const path = __webpack_require__("path?37f5");
74
74
  const resolveCommand = __webpack_require__("../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js");
75
75
  const escape = __webpack_require__("../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js");
76
76
  const readShebang = __webpack_require__("../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js");
@@ -150,7 +150,7 @@ __webpack_require__.add({
150
150
  module.exports.argument = escapeArgument;
151
151
  },
152
152
  "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js" (module, __unused_rspack_exports, __webpack_require__) {
153
- const fs = __webpack_require__("fs?8b28");
153
+ const fs = __webpack_require__("fs?cdbd");
154
154
  const shebangCommand = __webpack_require__("../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js");
155
155
  function readShebang(command) {
156
156
  const size = 150;
@@ -166,7 +166,7 @@ __webpack_require__.add({
166
166
  module.exports = readShebang;
167
167
  },
168
168
  "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js" (module, __unused_rspack_exports, __webpack_require__) {
169
- const path = __webpack_require__("path?aeb1");
169
+ const path = __webpack_require__("path?37f5");
170
170
  const which = __webpack_require__("../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js");
171
171
  const getPathKey = __webpack_require__("../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js");
172
172
  function resolveCommandAttempt(parsed, withoutPathExt) {
@@ -197,7 +197,7 @@ __webpack_require__.add({
197
197
  module.exports = resolveCommand;
198
198
  },
199
199
  "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js" (module, __unused_rspack_exports, __webpack_require__) {
200
- __webpack_require__("fs?8b28");
200
+ __webpack_require__("fs?cdbd");
201
201
  var core;
202
202
  core = 'win32' === process.platform || global.TESTING_WINDOWS ? __webpack_require__("../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js") : __webpack_require__("../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js");
203
203
  module.exports = isexe;
@@ -238,7 +238,7 @@ __webpack_require__.add({
238
238
  "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js" (module, __unused_rspack_exports, __webpack_require__) {
239
239
  module.exports = isexe;
240
240
  isexe.sync = sync;
241
- var fs = __webpack_require__("fs?8b28");
241
+ var fs = __webpack_require__("fs?cdbd");
242
242
  function isexe(path, options, cb) {
243
243
  fs.stat(path, function(er, stat) {
244
244
  cb(er, er ? false : checkStat(stat, options));
@@ -267,7 +267,7 @@ __webpack_require__.add({
267
267
  "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js" (module, __unused_rspack_exports, __webpack_require__) {
268
268
  module.exports = isexe;
269
269
  isexe.sync = sync;
270
- var fs = __webpack_require__("fs?8b28");
270
+ var fs = __webpack_require__("fs?cdbd");
271
271
  function checkPathExt(path, options) {
272
272
  var pathext = void 0 !== options.pathExt ? options.pathExt : process.env.PATHEXT;
273
273
  if (!pathext) return true;
@@ -355,7 +355,7 @@ __webpack_require__.add({
355
355
  },
356
356
  "../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js" (module, __unused_rspack_exports, __webpack_require__) {
357
357
  const isWindows = 'win32' === process.platform || 'cygwin' === process.env.OSTYPE || 'msys' === process.env.OSTYPE;
358
- const path = __webpack_require__("path?aeb1");
358
+ const path = __webpack_require__("path?37f5");
359
359
  const COLON = isWindows ? ';' : ':';
360
360
  const isexe = __webpack_require__("../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js");
361
361
  const getNotFoundError = (cmd)=>Object.assign(new Error(`not found: ${cmd}`), {
@@ -1783,4 +1783,4 @@ function create$(options) {
1783
1783
  return $;
1784
1784
  }
1785
1785
  create$();
1786
- export { execa };
1786
+ export { execa, node_path };
package/dist/cli/index.js CHANGED
@@ -1,19 +1,10 @@
1
- import { __webpack_require__ } from "../0~rslib-runtime.js";
2
- import { node_path, logger, join, cac } from "../5871.js";
3
- import "../4538.js";
4
- import { package_namespaceObject } from "../3553.js";
1
+ import { logger, cac } from "../2711~0.js";
2
+ import { package_namespaceObject } from "../8472~0.js";
5
3
  import { loadConfigFile, resolveDocRoot } from "../config/loadConfigFile.js";
6
4
  import { dev } from "../node/dev.js";
7
5
  import { build } from "../node/build.js";
8
6
  import { serve } from "../node/serve.js";
9
7
  import { listComponents, ejectComponent } from "../node/eject.js";
10
- const chokidar = __webpack_require__("../../node_modules/.pnpm/chokidar@3.6.0/node_modules/chokidar/index.js");
11
- const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
12
- var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
13
- const META_FILES = [
14
- '_meta.json',
15
- '_nav.json'
16
- ];
17
8
  const setNodeEnv = (env)=>{
18
9
  process.env.NODE_ENV = env;
19
10
  };
@@ -24,9 +15,7 @@ function runCLI({ argv = process.argv } = {}) {
24
15
  cli.option('-c, --config <config>', 'Set the configuration file (relative or absolute path)');
25
16
  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
17
  setNodeEnv('development');
27
- let isRestarting = false;
28
18
  const cwd = process.cwd();
29
- let cliWatcher;
30
19
  let devServer;
31
20
  const startDevServer = async ()=>{
32
21
  const { port, host } = options || {};
@@ -44,39 +33,23 @@ function runCLI({ argv = process.argv } = {}) {
44
33
  port,
45
34
  host
46
35
  }
47
- }
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
- }
36
+ },
37
+ restart
73
38
  });
74
39
  };
40
+ const restart = async ()=>{
41
+ try {
42
+ await startDevServer();
43
+ return true;
44
+ } catch (error) {
45
+ logger.error(error);
46
+ return false;
47
+ }
48
+ };
75
49
  await startDevServer();
76
50
  const exitProcess = async ()=>{
77
51
  try {
78
52
  await devServer.close();
79
- await cliWatcher.close();
80
53
  } finally{
81
54
  process.exit(0);
82
55
  }
@@ -5,20 +5,6 @@ import type { UserConfig } from '@rspress/shared';
5
5
  * such as fetching data or reading files.
6
6
  */
7
7
  export type UserConfigAsyncFn = () => Promise<UserConfig>;
8
- /**
9
- * Define a static Rspress configuration object.
10
- * @param config - The Rspress configuration object.
11
- * @returns The same configuration object (enables type checking and IDE autocompletion).
12
- * @example
13
- * ```ts
14
- * import { defineConfig } from '@rspress/core';
15
- *
16
- * export default defineConfig({
17
- * title: 'My Site',
18
- * });
19
- * ```
20
- */
21
- export declare function defineConfig(config: UserConfig): UserConfig;
22
8
  /**
23
9
  * Define an async Rspress configuration function.
24
10
  * Use this overload when you need to perform async operations during configuration,
@@ -37,4 +23,18 @@ export declare function defineConfig(config: UserConfig): UserConfig;
37
23
  * });
38
24
  * ```
39
25
  */
40
- export declare function defineConfig(config: UserConfigAsyncFn): UserConfigAsyncFn;
26
+ export declare function defineConfig<const Config extends UserConfig>(config: () => Promise<Config>): UserConfigAsyncFn;
27
+ /**
28
+ * Define a static Rspress configuration object.
29
+ * @param config - The Rspress configuration object.
30
+ * @returns The same configuration object (enables type checking and IDE autocompletion).
31
+ * @example
32
+ * ```ts
33
+ * import { defineConfig } from '@rspress/core';
34
+ *
35
+ * export default defineConfig({
36
+ * title: 'My Site',
37
+ * });
38
+ * ```
39
+ */
40
+ export declare function defineConfig(config: UserConfig): UserConfig;
@@ -1,9 +1,8 @@
1
- import { node_fs, node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../5871.js";
1
+ import { node_fs, node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../2711~0.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();
5
- let configFilePath = '';
6
- configFilePath = customConfigFile ? node_path.isAbsolute(customConfigFile) ? customConfigFile : node_path.join(baseDir, customConfigFile) : findConfig(node_path.join(baseDir, DEFAULT_CONFIG_NAME));
5
+ const configFilePath = customConfigFile ? node_path.isAbsolute(customConfigFile) ? customConfigFile : node_path.join(baseDir, customConfigFile) : findConfig(node_path.join(baseDir, DEFAULT_CONFIG_NAME));
7
6
  if (!configFilePath) {
8
7
  logger.info(`No config file found in ${baseDir}`);
9
8
  return {
@@ -83,6 +83,22 @@
83
83
  height: 100%;
84
84
  }
85
85
 
86
+ &__icon {
87
+ width: 16px;
88
+ height: 16px;
89
+ flex: 0 0 16px;
90
+ font-size: 16px;
91
+ line-height: 16px;
92
+ object-fit: contain;
93
+
94
+ > svg,
95
+ > img {
96
+ width: 100%;
97
+ height: 100%;
98
+ object-fit: contain;
99
+ }
100
+ }
101
+
86
102
  &--active {
87
103
  font-weight: 600;
88
104
  color: var(--rp-c-brand);
@@ -1,6 +1,6 @@
1
1
  import type { NavItemWithChildren } from '@rspress/core';
2
2
  import { matchNavbar, useLocation } from '@rspress/core/runtime';
3
- import { Link, Tag } from '@rspress/core/theme';
3
+ import { Link, SvgWrapper, Tag } from '@rspress/core/theme';
4
4
  import cls from 'clsx';
5
5
 
6
6
  import './index.scss';
@@ -51,6 +51,12 @@ function HoverGroupItem({
51
51
  hrefLang={item.lang}
52
52
  rel={item.rel}
53
53
  >
54
+ {item.icon && (
55
+ <SvgWrapper
56
+ icon={item.icon}
57
+ className="rp-hover-group__item__icon"
58
+ />
59
+ )}
54
60
  {item.text}
55
61
  {'tag' in item && item.tag && <Tag tag={item.tag} />}
56
62
  </Link>
@@ -94,11 +100,23 @@ function HoverGroupItem({
94
100
  hrefLang={lang}
95
101
  rel={rel}
96
102
  >
103
+ {item.icon && (
104
+ <SvgWrapper
105
+ icon={item.icon}
106
+ className="rp-hover-group__item__icon"
107
+ />
108
+ )}
97
109
  {text}
98
110
  {'tag' in item && item.tag && <Tag tag={item.tag} />}
99
111
  </Link>
100
112
  ) : (
101
113
  <div className="rp-hover-group__item__link" lang={lang}>
114
+ {item.icon && (
115
+ <SvgWrapper
116
+ icon={item.icon}
117
+ className="rp-hover-group__item__icon"
118
+ />
119
+ )}
102
120
  {text}
103
121
  {'tag' in item && item.tag && <Tag tag={item.tag} />}
104
122
  </div>
@@ -115,6 +133,9 @@ function HoverGroupItem({
115
133
  data-depth={depth}
116
134
  >
117
135
  <div className="rp-hover-group__item__link">
136
+ {item.icon && (
137
+ <SvgWrapper icon={item.icon} className="rp-hover-group__item__icon" />
138
+ )}
118
139
  {item.text}
119
140
  {'tag' in item && item.tag && <Tag tag={item.tag} />}
120
141
  </div>
@@ -13,6 +13,7 @@ import {
13
13
  import { useCallback, useRef, useState } from 'react';
14
14
  import './index.scss';
15
15
  import './LlmsCopyButton.scss';
16
+ import { getLlmsCopyContent } from './getLlmsCopyContent';
16
17
  import { useMdUrl } from './useMdUrl';
17
18
 
18
19
  export interface LlmsCopyButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
@@ -33,8 +34,6 @@ export interface LlmsCopyButtonProps extends React.ButtonHTMLAttributes<HTMLButt
33
34
  onClick?: React.MouseEventHandler<HTMLButtonElement>;
34
35
  }
35
36
 
36
- const cache = new Map<string, string>();
37
-
38
37
  export function LlmsCopyButton(props: LlmsCopyButtonProps) {
39
38
  const { onClick, ...otherProps } = props;
40
39
  const t = useI18n();
@@ -50,10 +49,7 @@ export function LlmsCopyButton(props: LlmsCopyButtonProps) {
50
49
 
51
50
  const url = pathname;
52
51
  try {
53
- const content: string =
54
- cache.get(url) ?? (await fetch(url).then(res => res.text()));
55
-
56
- cache.set(url, content);
52
+ const content = await getLlmsCopyContent(url);
57
53
  const isCopied = await copyToClipboard(content);
58
54
  if (!isCopied) {
59
55
  return;
@@ -6,10 +6,9 @@ import {
6
6
  SvgWrapper,
7
7
  } from '@rspress/core/theme';
8
8
  import { useCallback, useRef, useState } from 'react';
9
+ import { getLlmsCopyContent } from './getLlmsCopyContent';
9
10
  import { useMdUrl } from './useMdUrl';
10
11
 
11
- const cache = new Map<string, string>();
12
-
13
12
  export function LlmsCopyRow() {
14
13
  const t = useI18n();
15
14
  const { pathname } = useMdUrl();
@@ -21,9 +20,7 @@ export function LlmsCopyRow() {
21
20
  if (!pathname) return;
22
21
  setLoading(true);
23
22
  try {
24
- const content: string =
25
- cache.get(pathname) ?? (await fetch(pathname).then(res => res.text()));
26
- cache.set(pathname, content);
23
+ const content = await getLlmsCopyContent(pathname);
27
24
  const isCopied = await copyToClipboard(content);
28
25
  if (!isCopied) {
29
26
  return;
@@ -0,0 +1,104 @@
1
+ import { afterEach, describe, expect, it, rs } from '@rstest/core';
2
+ import { renderToStaticMarkup } from 'react-dom/server';
3
+ import { renderToMarkdownString } from 'react-render-to-markdown';
4
+ import { LlmsHint } from './LlmsHint';
5
+
6
+ const defaultPage = {
7
+ lang: 'en',
8
+ routePath: '/guide/',
9
+ version: '',
10
+ };
11
+
12
+ const defaultSite = {
13
+ lang: 'en',
14
+ multiVersion: {
15
+ default: '',
16
+ versions: [] as string[],
17
+ },
18
+ };
19
+
20
+ let page = defaultPage;
21
+ let site = defaultSite;
22
+
23
+ rs.mock('@rspress/core/runtime', () => ({
24
+ routePathToMdPath: (path: string) => `/docs${path}index.md`,
25
+ usePage: () => ({ page }),
26
+ useSite: () => ({ site }),
27
+ withBase: (path: string) => `/docs${path}`,
28
+ withSiteOrigin: (path: string) => `https://example.com${path}`,
29
+ }));
30
+
31
+ const originalSsgMd = import.meta.env.SSG_MD;
32
+
33
+ const setSsgMd = (value: boolean | undefined) => {
34
+ if (value === undefined) {
35
+ delete (import.meta.env as unknown as Record<string, unknown>).SSG_MD;
36
+ return;
37
+ }
38
+
39
+ (import.meta.env as unknown as Record<string, unknown>).SSG_MD = value;
40
+ };
41
+
42
+ afterEach(() => {
43
+ setSsgMd(originalSsgMd);
44
+ page = defaultPage;
45
+ site = defaultSite;
46
+ });
47
+
48
+ describe('LlmsHint', () => {
49
+ it('renders a visually hidden plain-text directive in HTML', () => {
50
+ const html = renderToStaticMarkup(<LlmsHint />);
51
+
52
+ expect(html).toContain('class="rp-llms-hint"');
53
+ expect(html).toMatch(/clip:rect\(0, ?0, ?0, ?0\)/);
54
+ expect(html).not.toContain('display:none');
55
+ expect(html).not.toContain('hidden=""');
56
+ expect(html).not.toContain('aria-hidden="true"');
57
+ expect(html).not.toContain('<a ');
58
+ expect(html).toContain(
59
+ 'For AI agents: the complete documentation index is available at https://example.com/docs/llms.txt, the full documentation bundle is available at https://example.com/docs/llms-full.txt, and this page is available as Markdown at https://example.com/docs/guide/index.md.',
60
+ );
61
+ });
62
+
63
+ it('renders a blockquote string when SSG_MD is enabled', async () => {
64
+ setSsgMd(true);
65
+
66
+ expect(await renderToMarkdownString(<LlmsHint />)).toBe(
67
+ '> For AI agents: the complete documentation index is available at https://example.com/docs/llms.txt, the full documentation bundle is available at https://example.com/docs/llms-full.txt.\n\n',
68
+ );
69
+ });
70
+
71
+ it('prefixes llms file URLs with locale and version when needed', () => {
72
+ page = {
73
+ ...defaultPage,
74
+ lang: 'zh',
75
+ };
76
+ expect(renderToStaticMarkup(<LlmsHint />)).toContain(
77
+ 'https://example.com/docs/zh/llms.txt',
78
+ );
79
+
80
+ site = {
81
+ ...defaultSite,
82
+ multiVersion: {
83
+ default: 'v2',
84
+ versions: ['v1', 'v2'],
85
+ },
86
+ };
87
+ page = {
88
+ ...defaultPage,
89
+ version: 'v1',
90
+ };
91
+ expect(renderToStaticMarkup(<LlmsHint />)).toContain(
92
+ 'https://example.com/docs/v1/llms.txt',
93
+ );
94
+
95
+ page = {
96
+ ...defaultPage,
97
+ lang: 'zh',
98
+ version: 'v1',
99
+ };
100
+ const html = renderToStaticMarkup(<LlmsHint />);
101
+ expect(html).toContain('https://example.com/docs/v1/zh/llms.txt');
102
+ expect(html).toContain('https://example.com/docs/v1/zh/llms-full.txt');
103
+ });
104
+ });
@@ -0,0 +1,74 @@
1
+ import {
2
+ routePathToMdPath,
3
+ usePage,
4
+ useSite,
5
+ withBase,
6
+ withSiteOrigin,
7
+ } from '@rspress/core/runtime';
8
+ import type React from 'react';
9
+
10
+ const visuallyHiddenStyle: React.CSSProperties = {
11
+ position: 'absolute',
12
+ width: 1,
13
+ height: 1,
14
+ padding: 0,
15
+ margin: -1,
16
+ overflow: 'hidden',
17
+ clip: 'rect(0, 0, 0, 0)',
18
+ clipPath: 'inset(50%)',
19
+ whiteSpace: 'nowrap',
20
+ border: 0,
21
+ };
22
+
23
+ function createLlmsHintText({
24
+ llmsTxtUrl,
25
+ llmsFullTxtUrl,
26
+ pageMdUrl,
27
+ }: {
28
+ llmsTxtUrl: string;
29
+ llmsFullTxtUrl: string;
30
+ pageMdUrl?: string;
31
+ }) {
32
+ const text = `For AI agents: the complete documentation index is available at ${llmsTxtUrl}, the full documentation bundle is available at ${llmsFullTxtUrl}`;
33
+ return pageMdUrl
34
+ ? `${text}, and this page is available as Markdown at ${pageMdUrl}.`
35
+ : `${text}.`;
36
+ }
37
+
38
+ export function LlmsHint() {
39
+ const { page } = usePage();
40
+ const { site } = useSite();
41
+ if (!page?.routePath) {
42
+ return null;
43
+ }
44
+
45
+ const isMultiVersion = site.multiVersion.versions.length > 0;
46
+ const versionPrefix =
47
+ isMultiVersion && page.version !== site.multiVersion.default
48
+ ? `${page.version}/`
49
+ : '';
50
+ const langPrefix = page.lang === site.lang ? '' : `${page.lang}/`;
51
+ const llmsTxtUrl = withSiteOrigin(
52
+ withBase(`/${versionPrefix}${langPrefix}llms.txt`),
53
+ );
54
+ const llmsFullTxtUrl = withSiteOrigin(
55
+ withBase(`/${versionPrefix}${langPrefix}llms-full.txt`),
56
+ );
57
+
58
+ if (import.meta.env.SSG_MD) {
59
+ return `> ${createLlmsHintText({ llmsTxtUrl, llmsFullTxtUrl })}\n\n`;
60
+ }
61
+
62
+ const pageMdUrl = withSiteOrigin(routePathToMdPath(page.routePath));
63
+ const hintText = createLlmsHintText({
64
+ llmsTxtUrl,
65
+ llmsFullTxtUrl,
66
+ pageMdUrl,
67
+ });
68
+
69
+ return (
70
+ <div className="rp-llms-hint" style={visuallyHiddenStyle}>
71
+ {hintText}
72
+ </div>
73
+ );
74
+ }
@@ -0,0 +1,21 @@
1
+ import { afterEach, describe, expect, it, rs } from '@rstest/core';
2
+ import { getLlmsCopyContent } from './getLlmsCopyContent';
3
+
4
+ afterEach(() => {
5
+ rs.restoreAllMocks();
6
+ });
7
+
8
+ describe('getLlmsCopyContent', () => {
9
+ it('fetches Markdown content in production mode', async () => {
10
+ const warnSpy = rs.spyOn(console, 'warn').mockImplementation(() => {});
11
+ const fetchSpy = rs
12
+ .spyOn(globalThis, 'fetch')
13
+ .mockResolvedValue(new Response('# Hello'));
14
+
15
+ await expect(getLlmsCopyContent('/guide/production.md')).resolves.toBe(
16
+ '# Hello',
17
+ );
18
+ expect(fetchSpy).toHaveBeenCalledWith('/guide/production.md');
19
+ expect(warnSpy).not.toHaveBeenCalled();
20
+ });
21
+ });
@@ -0,0 +1,20 @@
1
+ const cache = new Map<string, string>();
2
+
3
+ const DEV_COPY_WARNING =
4
+ 'Warning: Markdown content is unavailable in development mode; run `rspress build` to use this feature.';
5
+
6
+ export async function getLlmsCopyContent(url: string): Promise<string> {
7
+ if (import.meta.env.DEV) {
8
+ console.warn(DEV_COPY_WARNING);
9
+ return DEV_COPY_WARNING;
10
+ }
11
+
12
+ const cachedContent = cache.get(url);
13
+ if (cachedContent !== undefined) {
14
+ return cachedContent;
15
+ }
16
+
17
+ const content = await fetch(url).then(response => response.text());
18
+ cache.set(url, content);
19
+ return content;
20
+ }
@@ -1,6 +1,6 @@
1
1
  export { LlmsContainer, type LlmsContainerProps } from './LlmsContainer';
2
2
  export { LlmsCopyButton, type LlmsCopyButtonProps } from './LlmsCopyButton';
3
- export { LlmsHiddenHint } from './LlmsHiddenHint';
3
+ export { LlmsHint } from './LlmsHint';
4
4
  export {
5
5
  LlmsViewOptions,
6
6
  type LlmsViewOptionsItem,
@@ -44,6 +44,22 @@
44
44
  transition: transform 0.3s ease-in-out;
45
45
  }
46
46
 
47
+ &__leading-icon {
48
+ width: 16px;
49
+ height: 16px;
50
+ flex: 0 0 16px;
51
+ font-size: 16px;
52
+ line-height: 16px;
53
+ object-fit: contain;
54
+
55
+ > svg,
56
+ > img {
57
+ width: 100%;
58
+ height: 100%;
59
+ object-fit: contain;
60
+ }
61
+ }
62
+
47
63
  &:hover {
48
64
  .rp-nav-menu__item__container {
49
65
  color: var(--rp-c-brand);