@rspress/core 2.0.13 → 2.0.14

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 (77) hide show
  1. package/dist/0~execa.js +1 -1
  2. package/dist/0~rslib-runtime.js +9 -5
  3. package/dist/{2633.js → 4942.js} +12 -9
  4. package/dist/5580.js +2 -2
  5. package/dist/6646.js +3 -0
  6. package/dist/{7275.js → 7261.js} +2 -2
  7. package/dist/cli/index.js +1 -1
  8. package/dist/eject-theme/components/Banner/index.scss +11 -0
  9. package/dist/eject-theme/components/Banner/index.tsx +5 -1
  10. package/dist/eject-theme/components/Link/index.tsx +6 -0
  11. package/dist/eject-theme/components/Outline/index.tsx +0 -6
  12. package/dist/eject-theme/components/Search/SearchPanel.tsx +1 -0
  13. package/dist/eject-theme/components/Search/logic/search.ts +15 -16
  14. package/dist/eject-theme/components/SidebarMenu/index.tsx +10 -3
  15. package/dist/eject-theme/components/SidebarMenu/useSidebarMenu.tsx +12 -3
  16. package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +120 -0
  17. package/dist/eject-theme/components/SocialLinks/SocialLink.tsx +5 -0
  18. package/dist/eject-theme/components/SocialLinks/index.scss +17 -0
  19. package/dist/eject-theme/components/Tag/index.test.tsx +55 -0
  20. package/dist/eject-theme/components/Tag/index.tsx +19 -5
  21. package/dist/node/PluginDriver.js +1 -1
  22. package/dist/node/auto-nav-sidebar/index.js +1 -1
  23. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  24. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  25. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  26. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  27. package/dist/node/constants.js +1 -1
  28. package/dist/node/initRsbuild.js +17 -8
  29. package/dist/node/route/RoutePage.js +1 -1
  30. package/dist/node/route/RouteService.js +1 -1
  31. package/dist/node/route/extractPageData.js +1 -1
  32. package/dist/node/route/normalizeRoutePath.js +1 -1
  33. package/dist/node/runtimeModule/i18n.js +1 -1
  34. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  35. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  36. package/dist/node/runtimeModule/searchHooks.js +1 -1
  37. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  38. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  39. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +33 -9
  40. package/dist/node/serve.js +1 -1
  41. package/dist/node/ssg/htmlFile.d.ts +2 -0
  42. package/dist/node/ssg/htmlFile.js +14 -0
  43. package/dist/node/ssg/renderPage.js +1 -1
  44. package/dist/node/ssg/renderPageWorker.d.ts +3 -6
  45. package/dist/node/ssg/renderPageWorker.js +24 -4
  46. package/dist/node/ssg/renderPages.d.ts +1 -1
  47. package/dist/node/ssg/renderPages.js +18 -17
  48. package/dist/node/ssg/rsbuildPluginSSG.js +2 -2
  49. package/dist/node/ssg/ssgEnv.js +1 -1
  50. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  51. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  52. package/dist/node/ssg-md/renderPage.js +1 -1
  53. package/dist/node/ssg-md/renderPages.js +2 -2
  54. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  55. package/dist/node/utils/checkLanguageParity.js +1 -1
  56. package/dist/node/utils/createHash.js +1 -1
  57. package/dist/node/utils/flattenMdxContent.js +1 -1
  58. package/dist/node/utils/getPageKey.js +1 -1
  59. package/dist/node/utils/reactAlias.js +1 -1
  60. package/dist/theme/components/Banner/index.css +11 -0
  61. package/dist/theme/components/Banner/index.js +1 -0
  62. package/dist/theme/components/Link/index.js +6 -0
  63. package/dist/theme/components/Outline/index.js +1 -3
  64. package/dist/theme/components/Search/SearchPanel.js +1 -0
  65. package/dist/theme/components/Search/logic/search.js +12 -7
  66. package/dist/theme/components/SidebarMenu/index.d.ts +3 -0
  67. package/dist/theme/components/SidebarMenu/index.js +4 -3
  68. package/dist/theme/components/SidebarMenu/useSidebarMenu.d.ts +2 -1
  69. package/dist/theme/components/SidebarMenu/useSidebarMenu.js +7 -3
  70. package/dist/theme/components/SocialLinks/GithubStars.d.ts +7 -0
  71. package/dist/theme/components/SocialLinks/GithubStars.js +85 -0
  72. package/dist/theme/components/SocialLinks/SocialLink.js +5 -0
  73. package/dist/theme/components/SocialLinks/index.css +19 -0
  74. package/dist/theme/components/Tag/index.js +9 -5
  75. package/dist/theme/layout/DocLayout/index.js +1 -1
  76. package/package.json +10 -11
  77. package/dist/559.js +0 -1
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 "./2633.js";
11
+ import "./4942.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");
@@ -20,11 +20,15 @@ __webpack_require__.m = __webpack_modules__;
20
20
  };
21
21
  })();
22
22
  (()=>{
23
- __webpack_require__.d = (exports, definition)=>{
24
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
25
- enumerable: true,
26
- get: definition[key]
27
- });
23
+ __webpack_require__.d = (exports, getters, values)=>{
24
+ var define = (defs, kind)=>{
25
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ [kind]: defs[key]
28
+ });
29
+ };
30
+ define(getters, "get");
31
+ define(values, "value");
28
32
  };
29
33
  })();
30
34
  (()=>{
@@ -2128,6 +2128,7 @@ var Builder = class {
2128
2128
  const picomatch = __webpack_require__("../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/index.js");
2129
2129
  const isReadonlyArray = Array.isArray;
2130
2130
  const BACKSLASHES = /\\/g;
2131
+ const DRIVE_RELATIVE_PATH = /^[A-Za-z]:$/;
2131
2132
  const isWin = "win32" === process.platform;
2132
2133
  const ONLY_PARENT_DIRECTORIES = /^(\/?\.\.)+$/;
2133
2134
  function getPartialMatcher(patterns, options = {}) {
@@ -2193,6 +2194,9 @@ function buildRelative(cwd, root) {
2193
2194
  return "/" === p[p.length - 1] && "" !== result ? `${result}/` : result || ".";
2194
2195
  };
2195
2196
  }
2197
+ function ensureNonDriveRelativePath(path) {
2198
+ return path.replace(DRIVE_RELATIVE_PATH, (match)=>`${match}/`);
2199
+ }
2196
2200
  const splitPatternOptions = {
2197
2201
  parts: true
2198
2202
  };
@@ -2243,7 +2247,7 @@ function normalizePattern(pattern, opts, props, isIgnore) {
2243
2247
  }
2244
2248
  const potentialRoot = posix.join(cwd, parentDir.slice(3 * i));
2245
2249
  if ("." !== potentialRoot[0] && props.root.length > potentialRoot.length) {
2246
- props.root = potentialRoot;
2250
+ props.root = ensureNonDriveRelativePath(potentialRoot);
2247
2251
  props.depthOffset = -n + i;
2248
2252
  }
2249
2253
  }
@@ -2262,7 +2266,7 @@ function normalizePattern(pattern, opts, props, isIgnore) {
2262
2266
  }
2263
2267
  props.depthOffset = newCommonPath.length;
2264
2268
  props.commonPath = newCommonPath;
2265
- props.root = newCommonPath.length > 0 ? posix.join(cwd, ...newCommonPath) : cwd;
2269
+ props.root = ensureNonDriveRelativePath(newCommonPath.length > 0 ? posix.join(cwd, ...newCommonPath) : cwd);
2266
2270
  }
2267
2271
  return result;
2268
2272
  }
@@ -2354,18 +2358,17 @@ function formatPaths(paths, mapper) {
2354
2358
  }
2355
2359
  const defaultOptions = {
2356
2360
  caseSensitiveMatch: true,
2357
- cwd: process.cwd(),
2358
2361
  debug: !!process.env.TINYGLOBBY_DEBUG,
2359
2362
  expandDirectories: true,
2360
2363
  followSymbolicLinks: true,
2361
2364
  onlyFiles: true
2362
2365
  };
2363
2366
  function getOptions(options) {
2364
- const opts = {
2365
- ...defaultOptions,
2366
- ...options
2367
- };
2368
- opts.cwd = (opts.cwd instanceof URL ? fileURLToPath(opts.cwd) : resolve(opts.cwd)).replace(BACKSLASHES, "/");
2367
+ const opts = Object.assign({}, options);
2368
+ for(const key in defaultOptions)if (void 0 === opts[key]) Object.assign(opts, {
2369
+ [key]: defaultOptions[key]
2370
+ });
2371
+ opts.cwd = (opts.cwd instanceof URL ? fileURLToPath(opts.cwd) : resolve(opts.cwd || process.cwd())).replace(BACKSLASHES, "/");
2369
2372
  opts.ignore = ensureStringArray(opts.ignore);
2370
2373
  opts.fs && (opts.fs = {
2371
2374
  readdir: opts.fs.readdir || readdir,
@@ -2436,7 +2439,7 @@ const pluginVirtualModule = (pluginOptions = {})=>({
2436
2439
  });
2437
2440
  export { DEFAULT_PAGE_EXTENSIONS } from "@rspress/shared/constants";
2438
2441
  export { default as promises, mkdir, readdir as promises_readdir, rm, stat as promises_stat, writeFile } from "node:fs/promises";
2439
- export { MDX_OR_MD_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, getSidebarDataGroup, isDebugMode, isExternalUrl, normalizeHref, removeLeadingSlash, removeTrailingSlash, slash, withBase } from "@rspress/shared";
2442
+ export { MDX_OR_MD_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, getSidebarDataGroup, isDebugMode, isExternalUrl, isProduction, normalizeHref, removeLeadingSlash, removeTrailingSlash, slash, withBase } from "@rspress/shared";
2440
2443
  export { logger } from "@rspress/shared/logger";
2441
2444
  export { extractTextAndId, getIconUrlPath, loadFrontMatter } from "@rspress/shared/node-utils";
2442
2445
  export { createRequire as external_node_module_createRequire } from "node:module";
package/dist/5580.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*! LICENSE: 5580.js.LICENSE.txt */
2
2
  import { __webpack_require__ } from "./0~rslib-runtime.js";
3
- import "./2633.js";
3
+ import "./4942.js";
4
4
  import { createRequire as __rspack_createRequire } from "node:module";
5
5
  const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
6
6
  __webpack_require__.add({
@@ -4268,7 +4268,7 @@ __webpack_require__.add({
4268
4268
  module.exports = __rspack_createRequire_require("util");
4269
4269
  },
4270
4270
  "../../node_modules/.pnpm/binary-extensions@2.3.0/node_modules/binary-extensions/binary-extensions.json" (module) {
4271
- module.exports = JSON.parse('["3dm","3ds","3g2","3gp","7z","a","aac","adp","afdesign","afphoto","afpub","ai","aif","aiff","alz","ape","apk","appimage","ar","arj","asf","au","avi","bak","baml","bh","bin","bk","bmp","btif","bz2","bzip2","cab","caf","cgm","class","cmx","cpio","cr2","cur","dat","dcm","deb","dex","djvu","dll","dmg","dng","doc","docm","docx","dot","dotm","dra","DS_Store","dsk","dts","dtshd","dvb","dwg","dxf","ecelp4800","ecelp7470","ecelp9600","egg","eol","eot","epub","exe","f4v","fbs","fh","fla","flac","flatpak","fli","flv","fpx","fst","fvt","g3","gh","gif","graffle","gz","gzip","h261","h263","h264","icns","ico","ief","img","ipa","iso","jar","jpeg","jpg","jpgv","jpm","jxr","key","ktx","lha","lib","lvp","lz","lzh","lzma","lzo","m3u","m4a","m4v","mar","mdi","mht","mid","midi","mj2","mka","mkv","mmr","mng","mobi","mov","movie","mp3","mp4","mp4a","mpeg","mpg","mpga","mxu","nef","npx","numbers","nupkg","o","odp","ods","odt","oga","ogg","ogv","otf","ott","pages","pbm","pcx","pdb","pdf","pea","pgm","pic","png","pnm","pot","potm","potx","ppa","ppam","ppm","pps","ppsm","ppsx","ppt","pptm","pptx","psd","pya","pyc","pyo","pyv","qt","rar","ras","raw","resources","rgb","rip","rlc","rmf","rmvb","rpm","rtf","rz","s3m","s7z","scpt","sgi","shar","snap","sil","sketch","slk","smv","snk","so","stl","suo","sub","swf","tar","tbz","tbz2","tga","tgz","thmx","tif","tiff","tlz","ttc","ttf","txz","udf","uvh","uvi","uvm","uvp","uvs","uvu","viv","vob","war","wav","wax","wbmp","wdp","weba","webm","webp","whl","wim","wm","wma","wmv","wmx","woff","woff2","wrm","wvx","xbm","xif","xla","xlam","xls","xlsb","xlsm","xlsx","xlt","xltm","xltx","xm","xmind","xpi","xpm","xwd","xz","z","zip","zipx"]');
4271
+ module.exports = /*#__PURE__*/ JSON.parse('["3dm","3ds","3g2","3gp","7z","a","aac","adp","afdesign","afphoto","afpub","ai","aif","aiff","alz","ape","apk","appimage","ar","arj","asf","au","avi","bak","baml","bh","bin","bk","bmp","btif","bz2","bzip2","cab","caf","cgm","class","cmx","cpio","cr2","cur","dat","dcm","deb","dex","djvu","dll","dmg","dng","doc","docm","docx","dot","dotm","dra","DS_Store","dsk","dts","dtshd","dvb","dwg","dxf","ecelp4800","ecelp7470","ecelp9600","egg","eol","eot","epub","exe","f4v","fbs","fh","fla","flac","flatpak","fli","flv","fpx","fst","fvt","g3","gh","gif","graffle","gz","gzip","h261","h263","h264","icns","ico","ief","img","ipa","iso","jar","jpeg","jpg","jpgv","jpm","jxr","key","ktx","lha","lib","lvp","lz","lzh","lzma","lzo","m3u","m4a","m4v","mar","mdi","mht","mid","midi","mj2","mka","mkv","mmr","mng","mobi","mov","movie","mp3","mp4","mp4a","mpeg","mpg","mpga","mxu","nef","npx","numbers","nupkg","o","odp","ods","odt","oga","ogg","ogv","otf","ott","pages","pbm","pcx","pdb","pdf","pea","pgm","pic","png","pnm","pot","potm","potx","ppa","ppam","ppm","pps","ppsm","ppsx","ppt","pptm","pptx","psd","pya","pyc","pyo","pyv","qt","rar","ras","raw","resources","rgb","rip","rlc","rmf","rmvb","rpm","rtf","rz","s3m","s7z","scpt","sgi","shar","snap","sil","sketch","slk","smv","snk","so","stl","suo","sub","swf","tar","tbz","tbz2","tga","tgz","thmx","tif","tiff","tlz","ttc","ttf","txz","udf","uvh","uvi","uvm","uvp","uvs","uvu","viv","vob","war","wav","wax","wbmp","wdp","weba","webm","webp","whl","wim","wm","wma","wmv","wmx","woff","woff2","wrm","wvx","xbm","xif","xla","xlam","xls","xlsb","xlsm","xlsx","xlt","xltm","xltx","xm","xmind","xpi","xpm","xwd","xz","z","zip","zipx"]');
4272
4272
  }
4273
4273
  });
4274
4274
  function toArr(any) {
package/dist/6646.js ADDED
@@ -0,0 +1,3 @@
1
+ export { mkdir, writeFile } from "node:fs/promises";
2
+ export { dirname } from "node:path";
3
+ export { workerData } from "node:worker_threads";
@@ -1,5 +1,5 @@
1
1
  var package_namespaceObject = {
2
- rE: "2.0.13"
2
+ rE: "2.0.14"
3
3
  };
4
4
  async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true, signal } = {}) {
5
5
  return new Promise((resolve_, reject_)=>{
@@ -93,7 +93,7 @@ async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true,
93
93
  }
94
94
  const pMapSkip = Symbol('skip');
95
95
  export { createRequire } from "node:module";
96
- export { default as node_path } from "node:path";
96
+ export { default as node_path, isAbsolute, relative, resolve as external_node_path_resolve } from "node:path";
97
97
  export { pathToFileURL } from "node:url";
98
98
  export { logger } from "@rspress/shared/logger";
99
99
  export { createHead, transformHtmlTemplate } 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
2
  import { node_path, logger, join, cac } from "../5580.js";
3
3
  import "../7986.js";
4
- import { package_namespaceObject } from "../7275.js";
4
+ import { package_namespaceObject } from "../7261.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";
@@ -17,11 +17,22 @@
17
17
  z-index: 999;
18
18
  background: var(--rp-banner-background);
19
19
  height: 36px;
20
+ box-sizing: border-box;
21
+ padding: 0 3.5rem;
20
22
 
21
23
  &__link {
24
+ display: block;
25
+ flex: 1 1 auto;
26
+ min-width: 0;
27
+ max-width: 100%;
28
+ overflow: hidden;
22
29
  color: #fff;
23
30
  font-weight: 700;
31
+ line-height: 36px;
32
+ text-align: center;
24
33
  text-decoration: none;
34
+ text-overflow: ellipsis;
35
+ white-space: nowrap;
25
36
 
26
37
  &:hover {
27
38
  text-decoration: underline;
@@ -97,7 +97,11 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
97
97
  <div className={clsx('rp-banner', className)} ref={ref}>
98
98
  {customChildren ?? (
99
99
  <>
100
- <Link href={href} className="rp-banner__link">
100
+ <Link
101
+ href={href}
102
+ className="rp-banner__link"
103
+ title={typeof message === 'string' ? message : undefined}
104
+ >
101
105
  {message}
102
106
  </Link>
103
107
  <SvgWrapper
@@ -100,6 +100,9 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
100
100
  onMouseEnter?.(event);
101
101
  preloadLink(removeBaseHref);
102
102
  }}
103
+ onTouchStart={() => {
104
+ preloadLink(removeBaseHref);
105
+ }}
103
106
  onClick={e => {
104
107
  onClick?.(e);
105
108
  if (
@@ -134,6 +137,9 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
134
137
  onMouseEnter?.(event);
135
138
  preloadLink(removeBaseHref);
136
139
  }}
140
+ onTouchStart={() => {
141
+ preloadLink(removeBaseHref);
142
+ }}
137
143
  onClick={e => {
138
144
  onClick?.(e);
139
145
  if (
@@ -5,7 +5,6 @@ import {
5
5
  LlmsOpenRow,
6
6
  ReadPercent,
7
7
  Toc,
8
- useDynamicToc,
9
8
  } from '@rspress/core/theme';
10
9
  import './index.scss';
11
10
  import { ScrollToTop } from './ScrollToTop';
@@ -13,17 +12,12 @@ import { ScrollToTop } from './ScrollToTop';
13
12
  export function Outline() {
14
13
  const t = useI18n();
15
14
 
16
- const headers = useDynamicToc();
17
15
  const {
18
16
  site: {
19
17
  themeConfig: { enableScrollToTop = true, llmsUI },
20
18
  },
21
19
  } = useSite();
22
20
 
23
- if (headers.length === 0) {
24
- return <></>;
25
- }
26
-
27
21
  const placement =
28
22
  typeof llmsUI === 'object' ? (llmsUI?.placement ?? 'title') : 'title';
29
23
 
@@ -511,6 +511,7 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
511
511
  aria-label="SearchPanelInput"
512
512
  autoComplete="off"
513
513
  autoFocus
514
+ inputMode="search"
514
515
  onChange={e => handleQueryChange(e.target.value)}
515
516
  />
516
517
  <label>
@@ -213,24 +213,23 @@ export class PageSearcher {
213
213
  highlightStartIndex + THRESHOLD_CONTENT_LENGTH,
214
214
  );
215
215
  const statement = content.slice(statementStartIndex, statementEndIndex);
216
- const highlightInfoList = (
217
- item as RemotePageInfo
218
- )._matchesPosition.content
219
- .filter(
220
- match =>
221
- match.start >= highlightStartIndex &&
222
- match.start + match.length <=
223
- highlightStartIndex + THRESHOLD_CONTENT_LENGTH,
224
- )
225
- .map(match => {
216
+
217
+ const highlightInfoList: Array<{ start: number; length: number }> = [];
218
+ const limitIndex = highlightStartIndex + THRESHOLD_CONTENT_LENGTH;
219
+ for (const match of (item as RemotePageInfo)._matchesPosition?.content ||
220
+ []) {
221
+ const { start, length } = match;
222
+
223
+ if (start >= highlightStartIndex && start + length <= limitIndex) {
226
224
  const startCharIndex =
227
- byteToCharIndex(content, match.start) - statementStartIndex + 3;
228
- return {
229
- // prefix `...` length is 3
225
+ byteToCharIndex(content, start) - statementStartIndex + 3; // prefix `...` length is 3
226
+
227
+ highlightInfoList.push({
230
228
  start: startCharIndex,
231
- length: match.length,
232
- };
233
- });
229
+ length,
230
+ });
231
+ }
232
+ }
234
233
 
235
234
  matchedResult.push({
236
235
  type: 'content',
@@ -8,7 +8,7 @@ import {
8
8
  useActiveAnchor,
9
9
  useDynamicToc,
10
10
  } from '@rspress/core/theme';
11
- import { forwardRef, useEffect, useRef } from 'react';
11
+ import { forwardRef, type ReactNode, useEffect, useRef } from 'react';
12
12
  import { createPortal } from 'react-dom';
13
13
  import './index.scss';
14
14
 
@@ -20,11 +20,15 @@ export const SidebarMenu = forwardRef(
20
20
  onIsSidebarOpenChange,
21
21
  isOutlineOpen,
22
22
  onIsOutlineOpenChange,
23
+ beforeOutline,
24
+ afterOutline,
23
25
  }: {
24
26
  isSidebarOpen: boolean;
25
27
  onIsSidebarOpenChange: (isOpen: boolean) => void;
26
28
  isOutlineOpen: boolean;
27
29
  onIsOutlineOpenChange: (isOpen: boolean) => void;
30
+ beforeOutline?: ReactNode;
31
+ afterOutline?: ReactNode;
28
32
  },
29
33
  forwardedRef,
30
34
  ) => {
@@ -36,6 +40,9 @@ export const SidebarMenu = forwardRef(
36
40
  const headers = useDynamicToc();
37
41
  const { scrolledHeader } = useActiveAnchor(headers);
38
42
 
43
+ const outlineDisabled =
44
+ !beforeOutline && !afterOutline && headers.length === 0;
45
+
39
46
  const {
40
47
  frontmatter: {
41
48
  sidebar: sidebarConfig = true,
@@ -98,7 +105,7 @@ export const SidebarMenu = forwardRef(
98
105
  {showOutline ? (
99
106
  <button
100
107
  type="button"
101
- disabled={headers.length === 0}
108
+ disabled={outlineDisabled}
102
109
  onClick={e => {
103
110
  e.preventDefault();
104
111
  e.stopPropagation();
@@ -118,7 +125,7 @@ export const SidebarMenu = forwardRef(
118
125
  )}
119
126
  <ReadPercent size={14} strokeWidth={2} />
120
127
  {/* TODO: discussion */}
121
- {headers.length !== 0 && (
128
+ {!outlineDisabled && (
122
129
  <SvgWrapper
123
130
  icon={IconArrowRight}
124
131
  className="rp-sidebar-menu__right__icon"
@@ -1,9 +1,9 @@
1
1
  import { clearAllBodyScrollLocks, disableBodyScroll } from 'body-scroll-lock';
2
- import { useEffect, useMemo, useRef, useState } from 'react';
2
+ import { type ReactNode, useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { SidebarMenu } from '.';
4
4
  import { useClickOutside } from './useClickOutside';
5
5
 
6
- function useSidebarMenu() {
6
+ function useSidebarMenu(beforeOutline?: ReactNode, afterOutline?: ReactNode) {
7
7
  const [isSidebarOpen, setIsSidebarOpen] = useState(false);
8
8
  const [isOutlineOpen, setIsOutlineOpen] = useState(false);
9
9
 
@@ -39,9 +39,18 @@ function useSidebarMenu() {
39
39
  isOutlineOpen={isOutlineOpen}
40
40
  onIsOutlineOpenChange={setIsOutlineOpen}
41
41
  ref={sidebarMenuRef}
42
+ beforeOutline={beforeOutline}
43
+ afterOutline={afterOutline}
42
44
  />
43
45
  );
44
- }, [isOutlineOpen, isSidebarOpen, setIsOutlineOpen, setIsSidebarOpen]);
46
+ }, [
47
+ isOutlineOpen,
48
+ isSidebarOpen,
49
+ setIsOutlineOpen,
50
+ setIsSidebarOpen,
51
+ beforeOutline,
52
+ afterOutline,
53
+ ]);
45
54
 
46
55
  return {
47
56
  sidebarMenu,
@@ -0,0 +1,120 @@
1
+ import { type ReactNode, useEffect, useState } from 'react';
2
+
3
+ const TTL_MS = 60 * 60 * 1000;
4
+
5
+ type Cached = { count: number; fetchedAt: number };
6
+
7
+ function storageKey(repo: string) {
8
+ return `rp-github-stars:${repo}`;
9
+ }
10
+
11
+ function parseRepo(content: string): string | null {
12
+ try {
13
+ const url = new URL(content);
14
+ const host = url.hostname.replace(/^www\./, '');
15
+ if (host !== 'github.com') return null;
16
+ const match = url.pathname.match(/^\/([^/]+)\/([^/]+)/);
17
+ if (!match) return null;
18
+ return `${match[1]}/${match[2].replace(/\.git$/, '')}`;
19
+ } catch {
20
+ return null;
21
+ }
22
+ }
23
+
24
+ function readCache(repo: string): Cached | null {
25
+ if (typeof localStorage === 'undefined') return null;
26
+ try {
27
+ const raw = localStorage.getItem(storageKey(repo));
28
+ if (!raw) return null;
29
+ const parsed = JSON.parse(raw) as Cached;
30
+ if (
31
+ typeof parsed?.count !== 'number' ||
32
+ typeof parsed?.fetchedAt !== 'number'
33
+ ) {
34
+ return null;
35
+ }
36
+ return parsed;
37
+ } catch {
38
+ return null;
39
+ }
40
+ }
41
+
42
+ function writeCache(repo: string, count: number) {
43
+ if (typeof localStorage === 'undefined') return;
44
+ try {
45
+ localStorage.setItem(
46
+ storageKey(repo),
47
+ JSON.stringify({ count, fetchedAt: Date.now() }),
48
+ );
49
+ } catch {
50
+ // Storage may be full or disabled (private mode); ignore.
51
+ }
52
+ }
53
+
54
+ function formatCount(count: number): string {
55
+ if (count >= 1_000_000) {
56
+ return `${(count / 1_000_000).toFixed(1)}M`;
57
+ }
58
+ if (count >= 1000) {
59
+ return `${(count / 1000).toFixed(1)}K`;
60
+ }
61
+ return String(count);
62
+ }
63
+
64
+ interface GithubStarsProps {
65
+ content: string;
66
+ icon: ReactNode;
67
+ }
68
+
69
+ export const GithubStars = (props: GithubStarsProps) => {
70
+ const { content, icon } = props;
71
+ const repo = parseRepo(content);
72
+
73
+ const [count, setCount] = useState<number | null>(() =>
74
+ repo ? (readCache(repo)?.count ?? null) : null,
75
+ );
76
+
77
+ useEffect(() => {
78
+ if (!repo) return;
79
+ const cached = readCache(repo);
80
+ if (cached && Date.now() - cached.fetchedAt < TTL_MS) return;
81
+
82
+ let cancelled = false;
83
+ fetch(`https://api.github.com/repos/${repo}`)
84
+ .then(res => (res.ok ? res.json() : Promise.reject(res.status)))
85
+ .then((data: { stargazers_count: number }) => {
86
+ if (cancelled) return;
87
+ if (typeof data?.stargazers_count === 'number') {
88
+ setCount(data.stargazers_count);
89
+ writeCache(repo, data.stargazers_count);
90
+ }
91
+ })
92
+ .catch(() => {
93
+ // GitHub API failed (network, rate limit). Fall back to icon-only.
94
+ });
95
+ return () => {
96
+ cancelled = true;
97
+ };
98
+ }, [repo]);
99
+
100
+ return (
101
+ <a
102
+ href={content}
103
+ target="_blank"
104
+ rel="noopener noreferrer"
105
+ className="rp-social-links__item rp-social-links__github-stars"
106
+ aria-label={
107
+ count == null
108
+ ? 'GitHub repository'
109
+ : `GitHub repository, ${count.toLocaleString()} stars`
110
+ }
111
+ >
112
+ <div className="rp-social-links__icon">{icon}</div>
113
+ {count != null && (
114
+ <span className="rp-social-links__github-stars-count">
115
+ {formatCount(count)}
116
+ </span>
117
+ )}
118
+ </a>
119
+ );
120
+ };
@@ -1,6 +1,7 @@
1
1
  import type { SocialLink as ISocialLink } from '@rspress/core';
2
2
  import iconMap from 'virtual-social-links';
3
3
  import './index.scss';
4
+ import { GithubStars } from './GithubStars';
4
5
  import { useHoverGroup } from '../HoverGroup/useHoverGroup';
5
6
 
6
7
  interface SocialLinkProps {
@@ -55,6 +56,10 @@ export const SocialLink = (props: SocialLinkProps) => {
55
56
  );
56
57
  }
57
58
 
59
+ if (mode === 'github-stars') {
60
+ return <GithubStars content={content} icon={IconComp} />;
61
+ }
62
+
58
63
  if (mode === 'text') {
59
64
  return (
60
65
  <div
@@ -36,4 +36,21 @@
36
36
  flex-wrap: nowrap;
37
37
  gap: 1rem;
38
38
  }
39
+ &__github-stars {
40
+ flex-direction: row;
41
+ gap: 6px;
42
+ text-decoration: none;
43
+ color: var(--rp-c-text-2);
44
+ transition: color 0.2s ease;
45
+
46
+ &:hover {
47
+ color: var(--rp-c-text-1);
48
+ }
49
+ }
50
+ &__github-stars-count {
51
+ font-size: 13px;
52
+ font-weight: 500;
53
+ line-height: 1;
54
+ font-variant-numeric: tabular-nums;
55
+ }
39
56
  }
@@ -0,0 +1,55 @@
1
+ import { describe, expect, it, rs } from '@rstest/core';
2
+ import { renderToStaticMarkup } from 'react-dom/server';
3
+ import { Tag } from './index';
4
+
5
+ rs.mock('@rspress/core/runtime', () => ({
6
+ isDataUrl: (url: string) => url.startsWith('data:'),
7
+ isExternalUrl: (url: string) => /^https?:\/\//.test(url),
8
+ normalizeImagePath: (url: string) =>
9
+ url.startsWith('/') ? `/base${url}` : url,
10
+ }));
11
+
12
+ rs.mock('@rspress/core/theme', () => ({
13
+ Badge: ({
14
+ children,
15
+ text,
16
+ type,
17
+ }: {
18
+ children?: React.ReactNode;
19
+ text?: string;
20
+ type?: string;
21
+ }) => (
22
+ <span data-badge-type={type} data-text={text}>
23
+ {children}
24
+ </span>
25
+ ),
26
+ IconDeprecated: 'deprecated-icon',
27
+ IconExperimental: 'experimental-icon',
28
+ SvgWrapper: ({ icon }: { icon: string }) => <span data-icon={icon} />,
29
+ Tag: ({ tag }: { tag?: string }) => <span data-tag={tag}>{tag}</span>,
30
+ }));
31
+
32
+ describe('Tag', () => {
33
+ it('renders inline svg strings before splitting comma-separated tags', () => {
34
+ const markup = renderToStaticMarkup(
35
+ <Tag tag='<svg xmlns="http://www.w3.org/2000/svg" width="30" height="20" transform="translate(0, 0)" stroke="white"><text x="0" y="15">test</text></svg>' />,
36
+ );
37
+
38
+ expect(markup).toContain('<svg');
39
+ expect(markup).toContain('transform="translate(0, 0)"');
40
+ });
41
+
42
+ it('renders public folder image paths as images', () => {
43
+ const markup = renderToStaticMarkup(<Tag tag="/my.svg" />);
44
+
45
+ expect(markup).toContain('<img');
46
+ expect(markup).toContain('src="/base/my.svg"');
47
+ });
48
+
49
+ it('keeps rendering multiple common tags separated by commas', () => {
50
+ const markup = renderToStaticMarkup(<Tag tag="new, experimental" />);
51
+
52
+ expect(markup).toContain('data-tag="new"');
53
+ expect(markup).toContain('data-tag="experimental"');
54
+ });
55
+ });
@@ -1,4 +1,8 @@
1
- import { isDataUrl, isExternalUrl } from '@rspress/core/runtime';
1
+ import {
2
+ isDataUrl,
3
+ isExternalUrl,
4
+ normalizeImagePath,
5
+ } from '@rspress/core/runtime';
2
6
  import {
3
7
  Badge,
4
8
  IconDeprecated,
@@ -15,6 +19,8 @@ const BADGE_TAGS = {
15
19
  danger: 'danger',
16
20
  } as const;
17
21
 
22
+ const IMAGE_EXT_REGEXP = /\.(?:avif|gif|ico|jpe?g|png|svg|webp)(?:[?#].*)?$/i;
23
+
18
24
  function parseCommonTagsArrayStr(tagStr: string): string[] | null {
19
25
  const tags = tagStr
20
26
  .split(',')
@@ -24,12 +30,20 @@ function parseCommonTagsArrayStr(tagStr: string): string[] | null {
24
30
  return tags;
25
31
  }
26
32
 
33
+ function isPublicFolderPath(tag: string): boolean {
34
+ return tag.startsWith('/');
35
+ }
36
+
27
37
  const getTagType = (tag: string) => {
28
38
  const normalizedTag = tag.trim();
29
39
  const isSvgTagString = normalizedTag.startsWith('<svg');
30
- const isPic = isExternalUrl(normalizedTag) || isDataUrl(normalizedTag);
40
+ const isPic =
41
+ isExternalUrl(normalizedTag) ||
42
+ isDataUrl(normalizedTag) ||
43
+ (isPublicFolderPath(normalizedTag) && IMAGE_EXT_REGEXP.test(normalizedTag));
31
44
 
32
- const tagsArray = parseCommonTagsArrayStr(normalizedTag);
45
+ const tagsArray =
46
+ isSvgTagString || isPic ? null : parseCommonTagsArrayStr(normalizedTag);
33
47
 
34
48
  return {
35
49
  isSvgTagString,
@@ -67,14 +81,14 @@ export const Tag = ({ tag }: { tag?: string }) => {
67
81
  return (
68
82
  <div
69
83
  // eslint-disable-next-line react/no-danger
70
- dangerouslySetInnerHTML={{ __html: tag }}
84
+ dangerouslySetInnerHTML={{ __html: normalizedTag }}
71
85
  style={{ width: 20, marginRight: 4 }}
72
86
  ></div>
73
87
  );
74
88
  }
75
89
 
76
90
  if (isPic) {
77
- return <img src={tag} />;
91
+ return <img src={normalizeImagePath(normalizedTag)} />;
78
92
  }
79
93
 
80
94
  if (normalizedTag === 'experimental') {