@rspress/core 2.0.13 → 2.0.15

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 (200) hide show
  1. package/dist/0~execa.js +1 -1
  2. package/dist/0~rslib-runtime.js +9 -5
  3. package/dist/3358.js +1 -1
  4. package/dist/5580.js +2 -2
  5. package/dist/{2633.js → 6010.js} +12 -9
  6. package/dist/6646.js +3 -0
  7. package/dist/8005.js +1 -1
  8. package/dist/{7275.js → 9958.js} +3 -2
  9. package/dist/cli/index.js +1 -1
  10. package/dist/eject-theme/components/Banner/index.scss +11 -0
  11. package/dist/eject-theme/components/Banner/index.tsx +5 -1
  12. package/dist/eject-theme/components/DocContent/doc.scss +2 -2
  13. package/dist/eject-theme/components/HomeBackground/useNavTransparent.tsx +2 -2
  14. package/dist/eject-theme/components/HoverGroup/index.scss +1 -1
  15. package/dist/eject-theme/components/LastUpdated/index.tsx +8 -2
  16. package/dist/eject-theme/components/Link/index.tsx +6 -0
  17. package/dist/eject-theme/components/Nav/NavMenu.scss +1 -1
  18. package/dist/eject-theme/components/Nav/hooks.tsx +18 -14
  19. package/dist/eject-theme/components/Nav/index.tsx +4 -1
  20. package/dist/eject-theme/components/NavScreen/NavScreenAppearance.tsx +4 -1
  21. package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.scss +3 -0
  22. package/dist/eject-theme/components/NavScreen/NavScreenMenuOthers.tsx +4 -1
  23. package/dist/eject-theme/components/Outline/index.tsx +0 -6
  24. package/dist/eject-theme/components/Search/SearchPanel.tsx +24 -17
  25. package/dist/eject-theme/components/Search/logic/search.ts +15 -16
  26. package/dist/eject-theme/components/SidebarMenu/index.tsx +10 -3
  27. package/dist/eject-theme/components/SidebarMenu/useSidebarMenu.tsx +12 -3
  28. package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +120 -0
  29. package/dist/eject-theme/components/SocialLinks/SocialLink.tsx +5 -0
  30. package/dist/eject-theme/components/SocialLinks/index.scss +17 -0
  31. package/dist/eject-theme/components/Tag/index.test.tsx +55 -0
  32. package/dist/eject-theme/components/Tag/index.tsx +19 -5
  33. package/dist/index.d.ts +1 -1
  34. package/dist/node/PluginDriver.js +4 -4
  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 +1 -1
  38. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  39. package/dist/node/auto-nav-sidebar/walk.d.ts +4 -2
  40. package/dist/node/auto-nav-sidebar/walk.js +3 -3
  41. package/dist/node/constants.d.ts +2 -1
  42. package/dist/node/constants.js +12 -6
  43. package/dist/node/initRsbuild.js +21 -19
  44. package/dist/node/last-updated/index.d.ts +3 -3
  45. package/dist/node/last-updated/index.js +24 -9
  46. package/dist/node/mdx/options.js +8 -1
  47. package/dist/node/mdx/processor.js +3 -1
  48. package/dist/node/mdx/rehypePlugins/headerAnchor.d.ts +1 -1
  49. package/dist/node/mdx/rehypePlugins/headerAnchor.js +10 -6
  50. package/dist/node/mdx/remarkPlugins/link.js +91 -16
  51. package/dist/node/mdx/remarkPlugins/toc.d.ts +8 -1
  52. package/dist/node/mdx/remarkPlugins/toc.js +44 -15
  53. package/dist/node/route/RoutePage.js +1 -1
  54. package/dist/node/route/RouteService.d.ts +6 -0
  55. package/dist/node/route/RouteService.js +41 -7
  56. package/dist/node/route/extractPageData.js +1 -1
  57. package/dist/node/route/normalizeRoutePath.js +1 -1
  58. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +7 -0
  59. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +7 -0
  60. package/dist/node/runtimeModule/i18n.js +1 -1
  61. package/dist/node/runtimeModule/pageData/createPageData.js +2 -1
  62. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  63. package/dist/node/runtimeModule/searchHooks.js +1 -1
  64. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  65. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +12 -2
  66. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +33 -9
  67. package/dist/node/serve.js +1 -1
  68. package/dist/node/ssg/htmlFile.d.ts +2 -0
  69. package/dist/node/ssg/htmlFile.js +14 -0
  70. package/dist/node/ssg/renderPage.js +1 -1
  71. package/dist/node/ssg/renderPageWorker.d.ts +3 -6
  72. package/dist/node/ssg/renderPageWorker.js +24 -4
  73. package/dist/node/ssg/renderPages.d.ts +1 -1
  74. package/dist/node/ssg/renderPages.js +18 -17
  75. package/dist/node/ssg/rsbuildPluginCSR.js +2 -1
  76. package/dist/node/ssg/rsbuildPluginSSG.js +6 -4
  77. package/dist/node/ssg/ssgEnv.js +1 -1
  78. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  79. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  80. package/dist/node/ssg-md/renderPage.js +1 -1
  81. package/dist/node/ssg-md/renderPages.js +2 -2
  82. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +3 -2
  83. package/dist/node/utils/checkLanguageParity.js +1 -1
  84. package/dist/node/utils/createHash.js +1 -1
  85. package/dist/node/utils/flattenMdxContent.js +1 -1
  86. package/dist/node/utils/getPageKey.js +1 -1
  87. package/dist/node/utils/reactAlias.js +1 -1
  88. package/dist/runtime/App.d.ts +2 -1
  89. package/dist/runtime/ClientApp.d.ts +1 -1
  90. package/dist/runtime/Content.d.ts +1 -1
  91. package/dist/runtime/NoSSR.d.ts +1 -1
  92. package/dist/theme/components/Badge/index.d.ts +1 -1
  93. package/dist/theme/components/Banner/index.css +11 -0
  94. package/dist/theme/components/Banner/index.js +1 -0
  95. package/dist/theme/components/CodeBlock/index.d.ts +1 -1
  96. package/dist/theme/components/CodeButtonGroup/CopyCodeButton.d.ts +1 -1
  97. package/dist/theme/components/CodeButtonGroup/index.d.ts +1 -1
  98. package/dist/theme/components/DocContent/doc.css +2 -2
  99. package/dist/theme/components/DocContent/docComponents/a.d.ts +1 -1
  100. package/dist/theme/components/DocContent/docComponents/code.d.ts +1 -1
  101. package/dist/theme/components/DocContent/docComponents/hr.d.ts +1 -1
  102. package/dist/theme/components/DocContent/docComponents/img.d.ts +1 -1
  103. package/dist/theme/components/DocContent/docComponents/index.d.ts +18 -18
  104. package/dist/theme/components/DocContent/docComponents/list.d.ts +3 -3
  105. package/dist/theme/components/DocContent/docComponents/paragraph.d.ts +3 -3
  106. package/dist/theme/components/DocContent/docComponents/pre.d.ts +1 -1
  107. package/dist/theme/components/DocContent/docComponents/table.d.ts +3 -3
  108. package/dist/theme/components/DocContent/docComponents/title.d.ts +6 -6
  109. package/dist/theme/components/DocContent/index.d.ts +1 -1
  110. package/dist/theme/components/DocFooter/index.d.ts +1 -1
  111. package/dist/theme/components/EditLink/index.d.ts +1 -1
  112. package/dist/theme/components/FallbackHeading/index.d.ts +1 -1
  113. package/dist/theme/components/HomeBackground/index.d.ts +1 -1
  114. package/dist/theme/components/HomeBackground/useNavTransparent.d.ts +1 -1
  115. package/dist/theme/components/HomeBackground/useNavTransparent.js +2 -2
  116. package/dist/theme/components/HomeFeature/useCardAnimation.d.ts +1 -1
  117. package/dist/theme/components/HomeFooter/index.d.ts +1 -1
  118. package/dist/theme/components/HomeHero/index.d.ts +1 -1
  119. package/dist/theme/components/HoverGroup/index.css +1 -1
  120. package/dist/theme/components/HoverGroup/index.d.ts +1 -1
  121. package/dist/theme/components/HoverGroup/useHoverGroup.d.ts +1 -1
  122. package/dist/theme/components/LastUpdated/index.d.ts +1 -1
  123. package/dist/theme/components/LastUpdated/index.js +13 -3
  124. package/dist/theme/components/Link/index.js +6 -0
  125. package/dist/theme/components/Llms/LlmsContainer.d.ts +1 -1
  126. package/dist/theme/components/Llms/LlmsCopyButton.d.ts +1 -1
  127. package/dist/theme/components/Llms/LlmsCopyRow.d.ts +1 -1
  128. package/dist/theme/components/Llms/LlmsOpenRow.d.ts +1 -1
  129. package/dist/theme/components/Llms/LlmsViewOptions.d.ts +1 -1
  130. package/dist/theme/components/Nav/NavMenu.css +1 -1
  131. package/dist/theme/components/Nav/NavMenu.d.ts +9 -9
  132. package/dist/theme/components/Nav/hooks.js +6 -3
  133. package/dist/theme/components/Nav/index.d.ts +1 -1
  134. package/dist/theme/components/Nav/index.js +2 -1
  135. package/dist/theme/components/NavHamburger/index.d.ts +1 -1
  136. package/dist/theme/components/NavScreen/NavScreenAppearance.d.ts +1 -1
  137. package/dist/theme/components/NavScreen/NavScreenAppearance.js +2 -1
  138. package/dist/theme/components/NavScreen/NavScreenLangs.d.ts +1 -1
  139. package/dist/theme/components/NavScreen/NavScreenMenu.d.ts +1 -1
  140. package/dist/theme/components/NavScreen/NavScreenMenuItem.css +10 -1
  141. package/dist/theme/components/NavScreen/NavScreenMenuItem.d.ts +5 -5
  142. package/dist/theme/components/NavScreen/NavScreenMenuOthers.d.ts +1 -1
  143. package/dist/theme/components/NavScreen/NavScreenMenuOthers.js +2 -1
  144. package/dist/theme/components/NavScreen/NavScreenVersions.d.ts +1 -1
  145. package/dist/theme/components/NavScreen/index.d.ts +2 -2
  146. package/dist/theme/components/NavTitle/index.d.ts +1 -1
  147. package/dist/theme/components/Outline/ScrollToTop.d.ts +1 -1
  148. package/dist/theme/components/Outline/index.d.ts +1 -1
  149. package/dist/theme/components/Outline/index.js +1 -3
  150. package/dist/theme/components/Overview/index.d.ts +1 -1
  151. package/dist/theme/components/OverviewGroup/index.d.ts +1 -1
  152. package/dist/theme/components/PackageManagerTabs/icons/Bun.d.ts +1 -1
  153. package/dist/theme/components/PackageManagerTabs/icons/Deno.d.ts +1 -1
  154. package/dist/theme/components/PackageManagerTabs/icons/Npm.d.ts +1 -1
  155. package/dist/theme/components/PackageManagerTabs/icons/Pnpm.d.ts +1 -1
  156. package/dist/theme/components/PackageManagerTabs/icons/Yarn.d.ts +1 -1
  157. package/dist/theme/components/PackageManagerTabs/index.d.ts +1 -1
  158. package/dist/theme/components/PrevNextPage/index.d.ts +1 -1
  159. package/dist/theme/components/Prompt/index.d.ts +1 -1
  160. package/dist/theme/components/ReadPercent/index.d.ts +1 -1
  161. package/dist/theme/components/Root/index.d.ts +1 -1
  162. package/dist/theme/components/Search/NoSearchResult.d.ts +1 -1
  163. package/dist/theme/components/Search/SearchButton.d.ts +1 -1
  164. package/dist/theme/components/Search/SearchPanel.d.ts +1 -1
  165. package/dist/theme/components/Search/SearchPanel.js +12 -7
  166. package/dist/theme/components/Search/SuggestItem.d.ts +1 -1
  167. package/dist/theme/components/Search/index.d.ts +1 -1
  168. package/dist/theme/components/Search/logic/search.js +12 -7
  169. package/dist/theme/components/Sidebar/SidebarDivider.d.ts +1 -1
  170. package/dist/theme/components/Sidebar/SidebarGroup.d.ts +1 -1
  171. package/dist/theme/components/Sidebar/SidebarItem.d.ts +2 -2
  172. package/dist/theme/components/Sidebar/SidebarSectionHeader.d.ts +1 -1
  173. package/dist/theme/components/Sidebar/index.d.ts +2 -2
  174. package/dist/theme/components/SidebarMenu/index.d.ts +3 -0
  175. package/dist/theme/components/SidebarMenu/index.js +4 -3
  176. package/dist/theme/components/SidebarMenu/useSidebarMenu.d.ts +3 -2
  177. package/dist/theme/components/SidebarMenu/useSidebarMenu.js +7 -3
  178. package/dist/theme/components/SocialLinks/GithubStars.d.ts +7 -0
  179. package/dist/theme/components/SocialLinks/GithubStars.js +85 -0
  180. package/dist/theme/components/SocialLinks/SocialLink.d.ts +1 -1
  181. package/dist/theme/components/SocialLinks/SocialLink.js +5 -0
  182. package/dist/theme/components/SocialLinks/index.css +19 -0
  183. package/dist/theme/components/SocialLinks/index.d.ts +1 -1
  184. package/dist/theme/components/SourceCode/index.d.ts +1 -1
  185. package/dist/theme/components/Steps/index.d.ts +1 -1
  186. package/dist/theme/components/SvgWrapper/index.d.ts +1 -1
  187. package/dist/theme/components/SwitchAppearance/index.d.ts +1 -1
  188. package/dist/theme/components/Tag/index.d.ts +1 -1
  189. package/dist/theme/components/Tag/index.js +9 -5
  190. package/dist/theme/components/Toc/TocItem.d.ts +1 -1
  191. package/dist/theme/components/Toc/index.d.ts +1 -1
  192. package/dist/theme/layout/DocLayout/index.d.ts +1 -1
  193. package/dist/theme/layout/DocLayout/index.js +1 -1
  194. package/dist/theme/layout/HomeLayout/index.d.ts +1 -1
  195. package/dist/theme/layout/Layout/index.d.ts +1 -1
  196. package/dist/theme/layout/NotFountLayout/index.d.ts +1 -1
  197. package/dist/theme/logic/useThemeState.d.ts +6 -7
  198. package/dist/theme/logic/useThemeState.js +19 -15
  199. package/package.json +20 -21
  200. package/dist/559.js +0 -1
@@ -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') {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { EditLink, Feature, FrontMatterMeta, Header, Hero, I18nText, LocalSearchOptions, Nav, NavItem, NavItemWithChildren, NavItemWithLink, NavItemWithLinkAndChildren, NormalizedSidebarGroup, PageIndexInfo, RemotePageInfo, RouteMeta, RspressPlugin, Sidebar, SidebarData, SidebarDivider, SidebarGroup, SidebarItem, SidebarSectionHeader, SocialLink, UserConfig, } from '@rspress/shared';
1
+ export type { DarkMode, EditLink, Feature, FrontMatterMeta, Header, Hero, I18nText, LocalSearchOptions, Nav, NavItem, NavItemWithChildren, NavItemWithLink, NavItemWithLinkAndChildren, NormalizedSidebarGroup, PageIndexInfo, RemotePageInfo, RouteMeta, RspressPlugin, Sidebar, SidebarData, SidebarDivider, SidebarGroup, SidebarItem, SidebarSectionHeader, SocialLink, UserConfig, } from '@rspress/shared';
2
2
  export { getSidebarDataGroup, normalizeHref, normalizePosixPath, RSPRESS_TEMP_DIR, removeTrailingSlash, withBase, } from '@rspress/shared';
3
3
  export { logger } from '@rspress/shared/logger';
4
4
  export { getIconUrlPath, getNodeAttribute, mergeDocConfig, } from '@rspress/shared/node-utils';
@@ -1,4 +1,4 @@
1
- import { addTrailingSlash, node_path, addLeadingSlash } from "../2633.js";
1
+ import { addTrailingSlash, node_path, addLeadingSlash } from "../6010.js";
2
2
  import { createError } from "./utils/error.js";
3
3
  import { haveNavSidebarConfig as auto_nav_sidebar_haveNavSidebarConfig } from "./auto-nav-sidebar/index.js";
4
4
  class PluginDriver {
@@ -25,11 +25,11 @@ class PluginDriver {
25
25
  this.clearPlugins();
26
26
  const config = this.#config;
27
27
  const themeConfig = config?.themeConfig || {};
28
- const enableLastUpdated = themeConfig?.lastUpdated;
28
+ const lastUpdatedConfig = themeConfig?.lastUpdated;
29
29
  const mediumZoomConfig = config?.mediumZoom ?? true;
30
- if (enableLastUpdated) {
30
+ if (lastUpdatedConfig) {
31
31
  const { pluginLastUpdated } = await import("./last-updated/index.js");
32
- this.addPlugin(pluginLastUpdated());
32
+ this.addPlugin(pluginLastUpdated('object' == typeof lastUpdatedConfig ? lastUpdatedConfig.author : false));
33
33
  }
34
34
  if (mediumZoomConfig) {
35
35
  const { pluginMediumZoom } = await import("./medium-zoom/index.js");
@@ -1,4 +1,4 @@
1
- import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../2633.js";
1
+ import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../6010.js";
2
2
  import { processLocales, combineWalkResult } from "./locales.js";
3
3
  import { walk } from "./walk.js";
4
4
  async function runAutoNavSide(config, metaFileSet, mdFileSet) {
@@ -1,4 +1,4 @@
1
- import { node_path } from "../../2633.js";
1
+ import { node_path } from "../../6010.js";
2
2
  import { walk } from "./walk.js";
3
3
  function combineWalkResult(walks, versions) {
4
4
  return walks.reduce((acc, cur, curIndex)=>({
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../0~rslib-runtime.js";
2
2
  import "../../7986.js";
3
- import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../2633.js";
3
+ import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../6010.js";
4
4
  import { createError } from "../utils/error.js";
5
5
  import { pathExists, extractInfoFromFrontmatterWithAbsolutePath, readJson } from "./utils.js";
6
6
  import { absolutePathToRoutePath, addRoutePrefix } from "../route/RoutePage.js";
@@ -1,4 +1,4 @@
1
- import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../2633.js";
1
+ import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../6010.js";
2
2
  import { createError } from "../utils/error.js";
3
3
  async function pathExists(path) {
4
4
  try {
@@ -1,5 +1,7 @@
1
- import { type NavItem, type Sidebar } from '@rspress/shared';
1
+ import { type NavItem } from '@rspress/shared';
2
2
  export declare function walk(workDir: string, docsDir: string, extensions: string[], metaFileSet: Set<string>, mdFileSet: Set<string>): Promise<{
3
3
  nav: NavItem[];
4
- sidebar: Sidebar;
4
+ sidebar: {
5
+ [x: string]: (import("@rspress/shared").SidebarDivider | import("@rspress/shared").SidebarGroup | import("@rspress/shared").SidebarItem | import("@rspress/shared").SidebarSectionHeader)[];
6
+ };
5
7
  }>;
@@ -1,4 +1,4 @@
1
- import { isExternalUrl, node_path, promises } from "../../2633.js";
1
+ import { isExternalUrl, node_path, promises } from "../../6010.js";
2
2
  import { pathExists } from "../utils/fs.js";
3
3
  import { readJson } from "./utils.js";
4
4
  import { addRoutePrefix } from "../route/RoutePage.js";
@@ -34,7 +34,7 @@ async function walk(workDir, docsDir, extensions, metaFileSet, mdFileSet) {
34
34
  return {
35
35
  nav: navConfig,
36
36
  sidebar: {
37
- '/': await scanSideMeta(workDir, docsDir, extensions, metaFileSet, mdFileSet)
37
+ [addRoutePrefix(workDir, docsDir, '/')]: await scanSideMeta(workDir, docsDir, extensions, metaFileSet, mdFileSet)
38
38
  }
39
39
  };
40
40
  }
@@ -57,7 +57,7 @@ async function walk(workDir, docsDir, extensions, metaFileSet, mdFileSet) {
57
57
  return {
58
58
  nav: [],
59
59
  sidebar: {
60
- '/': await scanSideMeta(workDir, docsDir, extensions, metaFileSet, mdFileSet)
60
+ [addRoutePrefix(workDir, docsDir, '/')]: await scanSideMeta(workDir, docsDir, extensions, metaFileSet, mdFileSet)
61
61
  }
62
62
  };
63
63
  }
@@ -1,7 +1,8 @@
1
+ import { type DarkMode } from '@rspress/shared';
1
2
  export declare const RSPRESS_VERSION: string;
2
3
  export declare const isProduction: () => boolean;
3
4
  export declare const importStatementRegex: RegExp;
4
- export declare const inlineThemeScript: string;
5
+ export declare const getInlineThemeScript: (darkMode: DarkMode | undefined) => string;
5
6
  export declare const PACKAGE_ROOT: string;
6
7
  export declare const DEFAULT_THEME: string;
7
8
  export declare const EJECTED_THEME: string;
@@ -1,17 +1,23 @@
1
- import { createRequire, node_path, package_namespaceObject } from "../7275.js";
1
+ import { isDarkModeSwitchEnabled, node_path, package_namespaceObject, getDefaultDarkModeValue, createRequire } from "../9958.js";
2
2
  const constants_require = createRequire(import.meta.url);
3
3
  const RSPRESS_VERSION = package_namespaceObject.rE;
4
4
  const APPEARANCE_KEY = 'rspress-theme-appearance';
5
5
  const isProduction = ()=>'production' === process.env.NODE_ENV;
6
6
  const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
7
- const inlineThemeScript = `{
8
- const saved = localStorage.getItem('${APPEARANCE_KEY}')
7
+ const getInlineThemeScript = (darkMode)=>{
8
+ const defaultTheme = getDefaultDarkModeValue(darkMode);
9
+ const shouldReadStorage = isDarkModeSwitchEnabled(darkMode);
10
+ return `{
11
+ const saved = ${shouldReadStorage ? `localStorage.getItem('${APPEARANCE_KEY}')` : 'null'}
9
12
  const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
10
- const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
13
+ const defaultTheme = '${defaultTheme}'
14
+ const theme = saved === 'light' || saved === 'dark' || saved === 'auto' ? saved : defaultTheme
15
+ const isDark = theme === 'auto' ? preferDark : theme === 'dark'
11
16
  document.documentElement.classList.toggle('dark', isDark)
12
17
  document.documentElement.classList.toggle('rp-dark', isDark)
13
18
  document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
14
19
  }`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
20
+ };
15
21
  const PACKAGE_ROOT = node_path.dirname(constants_require.resolve('@rspress/core/package.json'));
16
22
  const DEFAULT_THEME = node_path.join(PACKAGE_ROOT, 'dist/theme');
17
23
  const EJECTED_THEME = node_path.join(PACKAGE_ROOT, 'dist/eject-theme');
@@ -25,9 +31,9 @@ const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
25
31
  const HEAD_MARKER = '<!--<?- HEAD ?>-->';
26
32
  const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
27
33
  const DEFAULT_TITLE = 'Rspress';
34
+ const PUBLIC_DIR = 'public';
28
35
  const NODE_SSG_BUNDLE_FOLDER = '__ssg__';
29
36
  const NODE_SSG_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
30
37
  const NODE_SSG_MD_BUNDLE_FOLDER = '__ssg_md__';
31
38
  const NODE_SSG_MD_BUNDLE_NAME = 'rspress-ssg-md-entry.cjs';
32
- var constants_PUBLIC_DIR = "public";
33
- export { APP_HTML_MARKER, CSR_CLIENT_ENTRY, DEFAULT_THEME, DEFAULT_TITLE, EJECTED_THEME, HEAD_MARKER, META_GENERATOR, NODE_SSG_BUNDLE_FOLDER, NODE_SSG_BUNDLE_NAME, NODE_SSG_MD_BUNDLE_FOLDER, NODE_SSG_MD_BUNDLE_NAME, OUTPUT_DIR, PACKAGE_ROOT, RSPRESS_VERSION, SSG_MD_SERVER_ENTRY, SSR_CLIENT_ENTRY, SSR_SERVER_ENTRY, TEMPLATE_PATH, constants_PUBLIC_DIR as PUBLIC_DIR, importStatementRegex, inlineThemeScript, isProduction };
39
+ export { APP_HTML_MARKER, CSR_CLIENT_ENTRY, DEFAULT_THEME, DEFAULT_TITLE, EJECTED_THEME, HEAD_MARKER, META_GENERATOR, NODE_SSG_BUNDLE_FOLDER, NODE_SSG_BUNDLE_NAME, NODE_SSG_MD_BUNDLE_FOLDER, NODE_SSG_MD_BUNDLE_NAME, OUTPUT_DIR, PACKAGE_ROOT, PUBLIC_DIR, RSPRESS_VERSION, SSG_MD_SERVER_ENTRY, SSR_CLIENT_ENTRY, SSR_SERVER_ENTRY, TEMPLATE_PATH, getInlineThemeScript, importStatementRegex, isProduction };
@@ -1,6 +1,6 @@
1
- import { external_node_process_cwd, node_path, external_node_url_fileURLToPath, addTrailingSlash, PLUGIN_REACT_NAME, external_node_module_createRequire, removeTrailingSlash, pluginVirtualModule, pluginReact, MDX_OR_MD_REGEXP } from "../2633.js";
1
+ import { external_node_process_cwd, node_path, external_node_url_fileURLToPath, addTrailingSlash, PLUGIN_REACT_NAME, external_node_module_createRequire, removeTrailingSlash, normalizeDarkMode, pluginReact, pluginVirtualModule, MDX_OR_MD_REGEXP } from "../6010.js";
2
2
  import { createError } from "./utils/error.js";
3
- import { 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";
3
+ import { CSR_CLIENT_ENTRY, SSR_CLIENT_ENTRY, OUTPUT_DIR, SSG_MD_SERVER_ENTRY, NODE_SSG_BUNDLE_FOLDER, isProduction, PACKAGE_ROOT, SSR_SERVER_ENTRY, TEMPLATE_PATH, NODE_SSG_MD_BUNDLE_FOLDER, DEFAULT_THEME, NODE_SSG_MD_BUNDLE_NAME, getInlineThemeScript, DEFAULT_TITLE, NODE_SSG_BUNDLE_NAME } from "./constants.js";
4
4
  import { hintBuilderPluginsBreakingChange, hintThemeBreakingChange } from "./logger/hint.js";
5
5
  import { resolveReactRouterDomAlias, resolveReactRenderToMarkdownAlias, resolveReactAlias } from "./utils/reactAlias.js";
6
6
  import { rsbuildPluginDocVM } from "./runtimeModule/pageData/rsbuildPlugin.js";
@@ -14,11 +14,18 @@ import { siteDataVMPlugin } from "./runtimeModule/siteData/rsbuildPlugin.js";
14
14
  import { rsbuildPluginSSG } from "./ssg/rsbuildPluginSSG.js";
15
15
  import { rsbuildPluginCSR } from "./ssg/rsbuildPluginCSR.js";
16
16
  import { rsbuildPluginSSGMD } from "./ssg-md/rsbuildPluginSSGMD.js";
17
- import { package_namespaceObject } from "../7275.js";
17
+ import { package_namespaceObject } from "../9958.js";
18
18
  function isPluginIncluded(config, pluginName) {
19
19
  return Boolean(config.builderConfig?.plugins?.some((plugin)=>plugin && plugin.name === pluginName));
20
20
  }
21
21
  const initRsbuild_require = external_node_module_createRequire(import.meta.url);
22
+ const RAW_QUERY_REGEXP = /[?&]raw(?:&|=|$)/;
23
+ const NODE_RSPACK_OPTIMIZATION = {
24
+ concatenateModules: false,
25
+ moduleIds: 'named',
26
+ chunkIds: 'named',
27
+ minimize: false
28
+ };
22
29
  async function getVirtualModulesFromPlugins(pluginDriver) {
23
30
  const runtimeModule = {};
24
31
  const modulesByPlugin = await pluginDriver.addRuntimeModules();
@@ -109,9 +116,9 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
109
116
  favicon: normalizeIcon(config?.icon),
110
117
  template: TEMPLATE_PATH,
111
118
  tags: [
112
- config.themeConfig?.darkMode !== false ? {
119
+ 'force-light' !== normalizeDarkMode(config.themeConfig?.darkMode) ? {
113
120
  tag: "script",
114
- children: inlineThemeScript,
121
+ children: getInlineThemeScript(config.themeConfig?.darkMode),
115
122
  append: false
116
123
  } : null
117
124
  ].filter(Boolean)
@@ -155,6 +162,9 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
155
162
  }
156
163
  },
157
164
  performance: {
165
+ printFileSize: {
166
+ compressed: true
167
+ },
158
168
  ...'false' !== process.env.RSPRESS_PERSISTENT_CACHE ? {
159
169
  buildCache: {
160
170
  buildDependencies: [
@@ -199,10 +209,10 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
199
209
  const isSsgMd = 'node_md' === environment.name;
200
210
  const jsModuleRule = chain.module.rule(CHAIN_ID.RULE.JS).oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN);
201
211
  const swcLoaderOptions = jsModuleRule.use(CHAIN_ID.USE.SWC).get('options');
202
- chain.module.rule('MDX').type("javascript/auto").test(MDX_OR_MD_REGEXP).resolve.merge({
212
+ chain.module.rule('mdx').test(MDX_OR_MD_REGEXP).resolve.merge({
203
213
  conditionNames: jsModuleRule.resolve.conditionNames.values(),
204
214
  mainFields: jsModuleRule.resolve.mainFields.values()
205
- }).end().oneOf('MDXCompile').use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(external_node_url_fileURLToPath(new URL('./mdx/loader.js', import.meta.url))).options({
215
+ }).end().oneOf('mdx-raw').type('asset/source').resourceQuery(RAW_QUERY_REGEXP).end().oneOf('mdx').type("javascript/auto").use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(external_node_url_fileURLToPath(new URL('./mdx/loader.js', import.meta.url))).options({
206
216
  config,
207
217
  docDirectory: userDocRoot,
208
218
  routeService,
@@ -286,9 +296,9 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
286
296
  'import.meta.env.SSG_MD': JSON.stringify(false)
287
297
  }
288
298
  },
289
- performance: {
290
- printFileSize: {
291
- compressed: true
299
+ tools: {
300
+ rspack: {
301
+ optimization: NODE_RSPACK_OPTIMIZATION
292
302
  }
293
303
  },
294
304
  output: {
@@ -310,10 +320,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
310
320
  },
311
321
  tools: {
312
322
  rspack: {
313
- optimization: {
314
- moduleIds: 'named',
315
- chunkIds: 'named'
316
- }
323
+ optimization: NODE_RSPACK_OPTIMIZATION
317
324
  }
318
325
  },
319
326
  source: {
@@ -326,11 +333,6 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
326
333
  'import.meta.env.SSG_MD': JSON.stringify(true)
327
334
  }
328
335
  },
329
- performance: {
330
- printFileSize: {
331
- compressed: true
332
- }
333
- },
334
336
  output: {
335
337
  emitAssets: false,
336
338
  target: 'node',
@@ -1,5 +1,5 @@
1
- import type { RspressPlugin } from '@rspress/shared';
1
+ import type { LastUpdatedAuthor, RspressPlugin } from '@rspress/shared';
2
2
  /**
3
- * The plugin is used to add the last updated time to the page.
3
+ * The plugin is used to add the last updated time and author to the page.
4
4
  */
5
- export declare function pluginLastUpdated(): RspressPlugin;
5
+ export declare function pluginLastUpdated(authorOption?: LastUpdatedAuthor): RspressPlugin;
@@ -2,26 +2,41 @@ import { execa } from "../../0~execa.js";
2
2
  function transform(timestamp, lang) {
3
3
  return new Date(timestamp).toLocaleString(lang || 'zh');
4
4
  }
5
- async function getGitLastUpdatedTimeStamp(filePath) {
6
- let lastUpdated;
5
+ async function getGitInfo(filePath) {
7
6
  try {
8
7
  const { stdout } = await execa('git', [
9
8
  'log',
10
9
  '-1',
11
- '--format=%at',
10
+ '--format=%at%n%an%n%ae',
11
+ '--',
12
12
  filePath
13
13
  ]);
14
- lastUpdated = 1000 * Number(stdout);
15
- } catch (_e) {}
16
- return lastUpdated;
14
+ const [at, an, ae] = stdout.split('\n');
15
+ if (!at) return;
16
+ return {
17
+ timestamp: 1000 * Number(at),
18
+ authorName: an ?? '',
19
+ authorEmail: ae ?? ''
20
+ };
21
+ } catch (_e) {
22
+ return;
23
+ }
17
24
  }
18
- function pluginLastUpdated() {
25
+ function pluginLastUpdated(authorOption = false) {
19
26
  return {
20
27
  name: '@rspress/plugin-last-updated',
21
28
  async extendPageData (pageData) {
22
29
  const { _filepath, lang } = pageData;
23
- const lastUpdated = await getGitLastUpdatedTimeStamp(_filepath);
24
- if (lastUpdated) pageData.lastUpdatedTime = transform(lastUpdated, lang);
30
+ const info = await getGitInfo(_filepath);
31
+ if (!info) return;
32
+ pageData.lastUpdatedTime = transform(info.timestamp, lang);
33
+ if (false === authorOption) return;
34
+ const display = 'function' == typeof authorOption ? authorOption({
35
+ name: info.authorName,
36
+ email: info.authorEmail,
37
+ filePath: _filepath
38
+ }) : info.authorName;
39
+ pageData.lastUpdatedAuthor = display;
25
40
  }
26
41
  };
27
42
  }
@@ -28,7 +28,13 @@ async function createMDXOptions(options) {
28
28
  remark_gfm,
29
29
  cjkFriendlyEmphasis && remark_cjk_friendly,
30
30
  cjkFriendlyEmphasis && remark_cjk_friendly_gfm_strikethrough,
31
- remarkToc,
31
+ [
32
+ remarkToc,
33
+ {
34
+ routeService,
35
+ fallbackHeadingTitle: config?.themeConfig?.fallbackHeadingTitle
36
+ }
37
+ ],
32
38
  !isSsgMd && remarkContainerSyntax,
33
39
  [
34
40
  remarkFileCodeBlock,
@@ -46,6 +52,7 @@ async function createMDXOptions(options) {
46
52
  routeService,
47
53
  remarkLinkOptions: {
48
54
  checkDeadLinks: false,
55
+ checkAnchors: false,
49
56
  autoPrefix: true
50
57
  },
51
58
  __base: config?.base
@@ -29,7 +29,9 @@ async function compile(options) {
29
29
  const compiler = createProcessor(mdxOptions);
30
30
  compiler.data('pageMeta', {
31
31
  toc: [],
32
- title: ''
32
+ title: '',
33
+ headingTitle: '',
34
+ frontmatter
33
35
  });
34
36
  const vFile = await compiler.process({
35
37
  value: preprocessedContent,
@@ -5,4 +5,4 @@ import type { Plugin } from 'unified';
5
5
  * same as rehype-slug + rehype-autolink-headings, but support custom id.
6
6
  */
7
7
  export declare const rehypeHeaderAnchor: Plugin<[], Root>;
8
- export declare const collectHeaderText: (node: Element) => string[];
8
+ export declare const collectHeaderText: (node: Element, allowCustomId?: boolean) => string[];