@rspress/core 2.0.0-rc.3 → 2.0.0-rc.5

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 (168) hide show
  1. package/dist/{0~7675.723d12b2.js → 0~7675.4468968d.js} +4 -4
  2. package/dist/1820.985588a0.js +5 -0
  3. package/dist/{3521.56e42d70.js → 5341.9eb6b114.js} +12 -12
  4. package/dist/{5485.077f14ff.js → 5485.b9ce9bdf.js} +5 -5
  5. package/dist/6289.29817fb4.js +4 -0
  6. package/dist/8813.4b28f4bb.js +1 -0
  7. package/dist/_private/react/render.js +1 -1
  8. package/dist/cli/config/loadConfigFile.js +2 -2
  9. package/dist/cli/index.44f3184c.js +2 -0
  10. package/dist/cli/index.js +3 -3
  11. package/dist/eject-theme/components/CodeBlock/index.tsx +1 -1
  12. package/dist/eject-theme/components/FallbackHeading/index.tsx +4 -0
  13. package/dist/eject-theme/components/HomeBackground/useNavTransparent.tsx +2 -1
  14. package/dist/eject-theme/components/HomeHero/index.scss +8 -0
  15. package/dist/eject-theme/components/HomeHero/index.tsx +11 -2
  16. package/dist/eject-theme/components/HoverGroup/index.scss +3 -2
  17. package/dist/eject-theme/components/HoverGroup/index.tsx +104 -22
  18. package/dist/eject-theme/components/Nav/NavMenu.scss +1 -1
  19. package/dist/eject-theme/components/Nav/NavMenu.tsx +50 -28
  20. package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.tsx +26 -11
  21. package/dist/eject-theme/components/Overview/index.tsx +11 -0
  22. package/dist/eject-theme/components/OverviewGroup/index.tsx +46 -0
  23. package/dist/eject-theme/components/Steps/index.scss +1 -0
  24. package/dist/index.js +6 -11
  25. package/dist/node/PluginDriver.js +3 -3
  26. package/dist/node/auto-nav-sidebar/index.js +3 -3
  27. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  28. package/dist/node/auto-nav-sidebar/normalize.js +2 -2
  29. package/dist/node/auto-nav-sidebar/utils.js +2 -2
  30. package/dist/node/auto-nav-sidebar/walk.js +13 -9
  31. package/dist/node/constants.js +2 -2
  32. package/dist/node/eject.js +2 -5
  33. package/dist/node/initRsbuild.js +14 -9
  34. package/dist/node/last-updated/index.js +1 -1
  35. package/dist/node/logger/hint.js +1 -1
  36. package/dist/node/mdx/loader.7c249a26.js +12 -0
  37. package/dist/node/mdx/options.js +3 -3
  38. package/dist/node/mdx/processor.js +2 -2
  39. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  40. package/dist/node/mdx/rehypePlugins/headerAnchor.js +4 -4
  41. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  42. package/dist/node/mdx/rehypePlugins/transformers/index.js +5 -5
  43. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  44. package/dist/node/mdx/remarkPlugins/containerSyntax.js +1 -1
  45. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +3 -3
  46. package/dist/node/mdx/remarkPlugins/image.js +2 -3
  47. package/dist/node/mdx/remarkPlugins/link.js +3 -3
  48. package/dist/node/mdx/remarkPlugins/toc.js +3 -3
  49. package/dist/node/medium-zoom/index.js +1 -1
  50. package/dist/node/route/RoutePage.js +1 -1
  51. package/dist/node/route/RouteService.js +3 -3
  52. package/dist/node/route/extractPageData.js +4 -5
  53. package/dist/node/route/normalizeRoutePath.js +2 -2
  54. package/dist/node/runtimeModule/i18n.js +2 -2
  55. package/dist/node/runtimeModule/pageData/createPageData.js +2 -2
  56. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  57. package/dist/node/runtimeModule/searchHooks.js +1 -1
  58. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  59. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  60. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  61. package/dist/node/serve.js +1 -1
  62. package/dist/node/ssg/renderPage.js +2 -2
  63. package/dist/node/ssg/renderPageWorker.165b5d46.js +1 -0
  64. package/dist/node/ssg/renderPageWorker.js +2 -2
  65. package/dist/node/ssg/renderPages.js +3 -3
  66. package/dist/node/ssg/rsbuildPluginSSG.js +2 -2
  67. package/dist/node/ssg/ssgEnv.js +1 -1
  68. package/dist/node/ssg-md/llms/emitLlmsTxt.js +9 -7
  69. package/dist/node/ssg-md/llms/llmsTxt.js +2 -2
  70. package/dist/node/ssg-md/remarkSplitMdx.js +2 -2
  71. package/dist/node/ssg-md/renderPage.js +2 -2
  72. package/dist/node/ssg-md/renderPages.js +2 -2
  73. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +2 -2
  74. package/dist/node/utils/checkLanguageParity.js +1 -1
  75. package/dist/node/utils/createHash.js +1 -1
  76. package/dist/node/utils/error.js +1 -1
  77. package/dist/node/utils/flattenMdxContent.js +4 -5
  78. package/dist/node/utils/fs.js +1 -1
  79. package/dist/node/utils/getPageKey.js +1 -1
  80. package/dist/node/utils/normalizePath.js +3 -3
  81. package/dist/node/utils/reactAlias.js +2 -2
  82. package/dist/runtime/App.js +4 -2
  83. package/dist/runtime/Content.d.ts +4 -0
  84. package/dist/runtime/Content.js +18 -0
  85. package/dist/runtime/NoSSR.d.ts +3 -0
  86. package/dist/runtime/NoSSR.js +14 -0
  87. package/dist/runtime/getSidebarDataGroup.test.js +68 -0
  88. package/dist/runtime/hooks/useActiveMatcher.d.ts +1 -0
  89. package/dist/runtime/hooks/useActiveMatcher.js +14 -0
  90. package/dist/runtime/hooks/useDark.d.ts +7 -0
  91. package/dist/runtime/hooks/useDark.js +7 -0
  92. package/dist/runtime/hooks/useFrontmatter.d.ts +4 -0
  93. package/dist/runtime/hooks/useFrontmatter.js +9 -0
  94. package/dist/runtime/hooks/useI18n.d.ts +2 -0
  95. package/dist/runtime/hooks/useI18n.js +14 -0
  96. package/dist/runtime/hooks/useLang.d.ts +1 -0
  97. package/dist/runtime/hooks/useLang.js +6 -0
  98. package/dist/runtime/hooks/useLocaleSiteData.d.ts +18 -0
  99. package/dist/runtime/hooks/useLocaleSiteData.js +20 -0
  100. package/dist/runtime/hooks/useNav.d.ts +1 -0
  101. package/dist/runtime/hooks/useNav.js +12 -0
  102. package/dist/runtime/hooks/usePage.d.ts +10 -0
  103. package/dist/runtime/hooks/usePage.js +9 -0
  104. package/dist/runtime/hooks/usePageData.d.ts +5 -0
  105. package/dist/runtime/hooks/usePageData.js +16 -0
  106. package/dist/runtime/hooks/usePages.d.ts +4 -0
  107. package/dist/runtime/hooks/usePages.js +7 -0
  108. package/dist/runtime/hooks/useSidebar.d.ts +16 -0
  109. package/dist/runtime/hooks/useSidebar.js +67 -0
  110. package/dist/runtime/hooks/useSite.d.ts +4 -0
  111. package/dist/runtime/hooks/useSite.js +7 -0
  112. package/dist/runtime/hooks/useVersion.d.ts +1 -0
  113. package/dist/runtime/hooks/useVersion.js +6 -0
  114. package/dist/runtime/hooks/useWindowSize.d.ts +9 -0
  115. package/dist/runtime/hooks/useWindowSize.js +31 -0
  116. package/dist/runtime/hooks/useWindowSize.test.js +36 -0
  117. package/dist/runtime/index.d.ts +21 -0
  118. package/dist/runtime/index.js +22 -0
  119. package/dist/runtime/route.d.ts +36 -0
  120. package/dist/runtime/route.js +53 -0
  121. package/dist/runtime/route.test.js +154 -0
  122. package/dist/runtime/ssrMdServerEntry.js +1 -1
  123. package/dist/runtime/utils.d.ts +12 -0
  124. package/dist/runtime/utils.js +34 -0
  125. package/dist/runtime/utils.test.js +34 -0
  126. package/dist/shiki-transformers.js +2 -2
  127. package/dist/theme/components/CodeBlock/index.js +1 -1
  128. package/dist/theme/components/FallbackHeading/index.js +4 -1
  129. package/dist/theme/components/HomeBackground/useNavTransparent.js +1 -1
  130. package/dist/theme/components/HomeHero/index.css +6 -0
  131. package/dist/theme/components/HomeHero/index.js +10 -3
  132. package/dist/theme/components/HoverGroup/index.css +3 -2
  133. package/dist/theme/components/HoverGroup/index.js +88 -17
  134. package/dist/theme/components/Nav/NavMenu.css +1 -1
  135. package/dist/theme/components/Nav/NavMenu.d.ts +6 -1
  136. package/dist/theme/components/Nav/NavMenu.js +47 -45
  137. package/dist/theme/components/NavScreen/NavScreenMenuItem.d.ts +1 -1
  138. package/dist/theme/components/NavScreen/NavScreenMenuItem.js +21 -11
  139. package/dist/theme/components/Overview/index.js +12 -1
  140. package/dist/theme/components/OverviewGroup/index.js +33 -0
  141. package/dist/theme/components/Steps/index.css +1 -0
  142. package/dist/theme/index.d.ts +1 -1
  143. package/dist/theme/index.js +1 -1
  144. package/dist/theme/layout/DocLayout/index.js +10 -0
  145. package/dist/theme/layout/HomeLayout/index.js +40 -0
  146. package/dist/theme/layout/Layout/index.js +10 -6
  147. package/dist/theme/logic/useScrollAfterNav.js +2 -2
  148. package/dist/theme/logic/useScrollReset.js +2 -2
  149. package/dist/theme/logic/useStorageValue.js +6 -3
  150. package/dist/theme/logic/{useAppearance.d.ts → useThemeState.d.ts} +4 -1
  151. package/dist/theme/logic/useThemeState.js +50 -0
  152. package/dist/theme/styles/scrollbar.css +14 -2
  153. package/dist/theme/styles/vars/base-vars.css +2 -2
  154. package/dist/theme/styles/vars/code-vars.css +2 -2
  155. package/nav-json-schema.json +2 -2
  156. package/package.json +10 -11
  157. package/static/MediumZoom.tsx +1 -1
  158. package/dist/4669.12208c6a.js +0 -2
  159. package/dist/6289.c67fe0d5.js +0 -5
  160. package/dist/8813.9da1f210.js +0 -2
  161. package/dist/9643.f109822d.js +0 -5
  162. package/dist/cli/index.cb89dbd1.js +0 -3
  163. package/dist/node/mdx/loader.e1578c62.js +0 -13
  164. package/dist/node/ssg/renderPageWorker.474f9f73.js +0 -2
  165. package/dist/runtime.72d450ac.js +0 -1
  166. package/dist/runtime.d.ts +0 -2
  167. package/dist/runtime.js +0 -4
  168. package/dist/theme/logic/useAppearance.js +0 -64
@@ -0,0 +1,22 @@
1
+ import { isDataUrl, isExternalUrl, matchNavbar, matchSidebar, normalizeHref } from "@rspress/shared";
2
+ import { Head } from "@unhead/react";
3
+ import { Content } from "./Content.js";
4
+ import { useActiveMatcher } from "./hooks/useActiveMatcher.js";
5
+ import { ThemeContext, useDark } from "./hooks/useDark.js";
6
+ import { useFrontmatter } from "./hooks/useFrontmatter.js";
7
+ import { useI18n } from "./hooks/useI18n.js";
8
+ import { useLang } from "./hooks/useLang.js";
9
+ import { useLocaleSiteData } from "./hooks/useLocaleSiteData.js";
10
+ import { useNav } from "./hooks/useNav.js";
11
+ import { PageContext, usePage } from "./hooks/usePage.js";
12
+ import { usePageData } from "./hooks/usePageData.js";
13
+ import { usePages } from "./hooks/usePages.js";
14
+ import { getSidebarDataGroup, useSidebar, useSidebarDynamic } from "./hooks/useSidebar.js";
15
+ import { useSite } from "./hooks/useSite.js";
16
+ import { useVersion } from "./hooks/useVersion.js";
17
+ import { useWindowSize } from "./hooks/useWindowSize.js";
18
+ import { NoSSR } from "./NoSSR.js";
19
+ import { isActive, pathnameToRouteService, preloadLink } from "./route.js";
20
+ import { addLeadingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase } from "./utils.js";
21
+ export * from "react-router-dom";
22
+ export { Content, Head, NoSSR, PageContext, ThemeContext, addLeadingSlash, cleanUrlByConfig, getSidebarDataGroup, isActive, isDataUrl, isEqualPath, isExternalUrl, isProduction, matchNavbar, matchSidebar, normalizeHref, normalizeHrefInRuntime, normalizeImagePath, pathnameToRouteService, preloadLink, removeBase, removeTrailingSlash, routePathToMdPath, useActiveMatcher, useDark, useFrontmatter, useI18n, useLang, useLocaleSiteData, useNav, usePage, usePageData, usePages, useSidebar, useSidebarDynamic, useSite, useVersion, useWindowSize, withBase };
@@ -0,0 +1,36 @@
1
+ import type { Route } from '@rspress/shared';
2
+ /**
3
+ * Simple implementation of matchPath to check if a pattern matches a pathname
4
+ * Better performance alternative of `import { matchPath } from 'react-router-dom'`
5
+ * @param pattern - The route pattern to match against
6
+ * @param pathname - The pathname to check
7
+ * @returns Match object if matched, null otherwise
8
+ *
9
+ * @example
10
+ * matchPath('/api/config', '/api/config') // { path: '/api/config' }
11
+ * matchPath('/api/config/', '/api/config') // { path: '/api/config/' }
12
+ * matchPath('/api/config', '/api/other') // null
13
+ */
14
+ export declare function matchPath(pattern: string, pathname: string): {
15
+ path: string;
16
+ } | null;
17
+ /**
18
+ * this is a bridge of two core features Sidebar and RouteService
19
+ * @param pathname useLocation().pathname
20
+ * @returns
21
+ */
22
+ export declare function pathnameToRouteService(pathname: string): Route | undefined;
23
+ /**
24
+ * link: /api/config
25
+ * currentPathname:
26
+ * 0. /api/config
27
+ * 1. /api/config.html
28
+ * 2. /api/config/
29
+ * 3. /api/config/index
30
+ * 4. /api/config/index.html
31
+ * @param itemLink
32
+ * @param currentPathname
33
+ * @returns
34
+ */
35
+ export declare function isActive(itemLink: string, currentPathname: string): boolean;
36
+ export declare const preloadLink: (link: string) => void;
@@ -0,0 +1,53 @@
1
+ import { cleanUrl } from "@rspress/shared";
2
+ import { routes } from "virtual-routes";
3
+ function normalizeRoutePath(routePath) {
4
+ return cleanUrl(decodeURIComponent(routePath)).replace(/\.html$/, '').replace(/\/index$/, '/').toLowerCase();
5
+ }
6
+ function matchPath(pattern, pathname) {
7
+ const normalizedPattern = normalizeRoutePath(pattern);
8
+ const normalizedPathname = normalizeRoutePath(pathname);
9
+ const normalizedPatternWithSlash = normalizedPattern.endsWith('/') ? normalizedPattern : `${normalizedPattern}/`;
10
+ const normalizedPathnameWithSlash = normalizedPathname.endsWith('/') ? normalizedPathname : `${normalizedPathname}/`;
11
+ if (normalizedPatternWithSlash === normalizedPathnameWithSlash) return {
12
+ path: pattern
13
+ };
14
+ return null;
15
+ }
16
+ const sortedRoutes = [
17
+ ...routes
18
+ ].sort((a, b)=>{
19
+ const pathA = a.path || '';
20
+ const pathB = b.path || '';
21
+ return pathB.length - pathA.length;
22
+ });
23
+ function matchRoutes(_routes, pathname) {
24
+ for (const route of sortedRoutes){
25
+ const routePath = route.path || '';
26
+ const match = matchPath(routePath, pathname);
27
+ if (match) return [
28
+ {
29
+ route
30
+ }
31
+ ];
32
+ }
33
+ return null;
34
+ }
35
+ const cache = new Map();
36
+ function pathnameToRouteService(pathname) {
37
+ const normalizedPathname = normalizeRoutePath(pathname);
38
+ const cacheItem = cache.get(normalizedPathname);
39
+ if (cacheItem) return cacheItem;
40
+ const matched = matchRoutes(routes, normalizedPathname);
41
+ const route = matched?.[0]?.route;
42
+ if (route) cache.set(normalizedPathname, route);
43
+ return route;
44
+ }
45
+ function isActive(itemLink, currentPathname) {
46
+ const linkMatched = matchPath(itemLink, currentPathname);
47
+ return null !== linkMatched;
48
+ }
49
+ const preloadLink = (link)=>{
50
+ const route = pathnameToRouteService(link);
51
+ if (route) route.preload();
52
+ };
53
+ export { isActive, matchPath, pathnameToRouteService, preloadLink };
@@ -0,0 +1,154 @@
1
+ import { describe, expect, it, rs } from "@rstest/core";
2
+ import { isActive, matchPath, pathnameToRouteService } from "./route.js";
3
+ rs.mock('virtual-routes', ()=>{
4
+ const element = rs.fn();
5
+ const routes = [
6
+ {
7
+ path: '/api/config',
8
+ element,
9
+ filePath: 'api/config.mdx',
10
+ preload: async ()=>{},
11
+ lang: '',
12
+ version: ''
13
+ },
14
+ {
15
+ path: '/api/config/',
16
+ element,
17
+ filePath: 'api/config/index.mdx',
18
+ preload: async ()=>{},
19
+ lang: '',
20
+ version: ''
21
+ },
22
+ {
23
+ path: '/',
24
+ element,
25
+ filePath: 'index.mdx',
26
+ preload: async ()=>{},
27
+ lang: '',
28
+ version: ''
29
+ }
30
+ ];
31
+ return {
32
+ routes
33
+ };
34
+ });
35
+ describe('matchPath', ()=>{
36
+ it('should match exact paths', ()=>{
37
+ expect(matchPath('/api/config', '/api/config')).toEqual({
38
+ path: '/api/config'
39
+ });
40
+ expect(matchPath('/api/config/', '/api/config/')).toEqual({
41
+ path: '/api/config/'
42
+ });
43
+ });
44
+ it('should normalize trailing slashes', ()=>{
45
+ expect(matchPath('/api/config', '/api/config/')).toEqual({
46
+ path: '/api/config'
47
+ });
48
+ expect(matchPath('/api/config/', '/api/config')).toEqual({
49
+ path: '/api/config/'
50
+ });
51
+ expect(matchPath('/api/config/', '/api/config/index.html')).toEqual({
52
+ path: '/api/config/'
53
+ });
54
+ });
55
+ it('should return null for non-matching paths', ()=>{
56
+ expect(matchPath('/api/config', '/api/other')).toBeNull();
57
+ expect(matchPath('/api', '/api/config')).toBeNull();
58
+ expect(matchPath('/api', '/api/index.md')).toBeNull();
59
+ });
60
+ it('should handle case-insensitive matching', ()=>{
61
+ expect(matchPath('/api/config', '/API/CONFIG')).toEqual({
62
+ path: '/api/config'
63
+ });
64
+ expect(matchPath('/api/config', '/Api/Config')).toEqual({
65
+ path: '/api/config'
66
+ });
67
+ expect(matchPath('/api/config', '/api/CONFIG.html')).toEqual({
68
+ path: '/api/config'
69
+ });
70
+ expect(matchPath('/api/config/', '/API/CONFIG/')).toEqual({
71
+ path: '/api/config/'
72
+ });
73
+ expect(matchPath('/api/config/', '/API/CONFIG/index.html')).toEqual({
74
+ path: '/api/config/'
75
+ });
76
+ });
77
+ });
78
+ describe('isActive', ()=>{
79
+ it('should return true for matching normalized paths', ()=>{
80
+ expect(isActive('/api/config', '/api/config')).toBe(true);
81
+ expect(isActive('/api/config', '/api/config.html')).toBe(true);
82
+ expect(isActive('/api/config', '/api/config/')).toBe(true);
83
+ });
84
+ it('should return false for non-matching paths', ()=>{
85
+ expect(isActive('/api/config', '/api/other')).toBe(false);
86
+ });
87
+ it('should handle hash and search parameters correctly', ()=>{
88
+ expect(isActive('/api/config', '/api/config#hash')).toBe(true);
89
+ expect(isActive('/api/config', '/api/config?query=value')).toBe(true);
90
+ expect(isActive('/api/config', '/api/config.html#hash')).toBe(true);
91
+ expect(isActive('/api/config', '/api/config.html?query=value')).toBe(true);
92
+ expect(isActive('/api/config', '/api/config.html?query=value#hash')).toBe(true);
93
+ expect(isActive('/api/config#different', '/api/config#hash')).toBe(true);
94
+ });
95
+ it('should handle case-insensitive matching', ()=>{
96
+ expect(isActive('/api/config', '/API/CONFIG')).toBe(true);
97
+ expect(isActive('/api/config', '/Api/Config')).toBe(true);
98
+ expect(isActive('/api/config', '/api/CONFIG.html')).toBe(true);
99
+ expect(isActive('/api/config', '/API/CONFIG/')).toBe(true);
100
+ expect(isActive('/api/config', '/API/CONFIG/index.html')).toBe(true);
101
+ expect(isActive('/api/config', '/api/CONFIG#hash')).toBe(true);
102
+ expect(isActive('/api/config', '/API/config?query=value')).toBe(true);
103
+ });
104
+ });
105
+ describe('pathnameToRouteService', ()=>{
106
+ it('0. /api/config', ()=>{
107
+ const pathname = '/api/config';
108
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
109
+ });
110
+ it('1. /api/config.html', ()=>{
111
+ const pathname = '/api/config.html';
112
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
113
+ });
114
+ it('2. /api/config/', ()=>{
115
+ const pathname = '/api/config/';
116
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
117
+ });
118
+ it('3. /api/config/index', ()=>{
119
+ const pathname = '/api/config/index';
120
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
121
+ });
122
+ it('4. /api/config/index.html', ()=>{
123
+ const pathname = '/api/config/index.html';
124
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
125
+ });
126
+ it('5. /', ()=>{
127
+ expect(pathnameToRouteService('/index.html')?.path).toMatchInlineSnapshot('"/"');
128
+ expect(pathnameToRouteService('/index.md')?.path).toMatchInlineSnapshot("undefined");
129
+ });
130
+ it('6. /api/config.html#hash - should handle hash correctly', ()=>{
131
+ const pathname = '/api/config.html#hash';
132
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
133
+ });
134
+ it('7. /api/config.html?query=value - should handle query params correctly', ()=>{
135
+ const pathname = '/api/config.html?query=value';
136
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
137
+ });
138
+ it('8. /api/config.html?query=value#hash - should handle both query and hash', ()=>{
139
+ const pathname = '/api/config.html?query=value#hash';
140
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
141
+ });
142
+ it('9. /api/config#hash - should handle hash without .html', ()=>{
143
+ const pathname = '/api/config#hash';
144
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
145
+ });
146
+ it('10. Case-insensitive route matching', ()=>{
147
+ expect(pathnameToRouteService('/API/CONFIG')?.path).toMatchInlineSnapshot('"/api/config/"');
148
+ expect(pathnameToRouteService('/Api/Config')?.path).toMatchInlineSnapshot('"/api/config/"');
149
+ expect(pathnameToRouteService('/API/CONFIG.html')?.path).toMatchInlineSnapshot('"/api/config/"');
150
+ expect(pathnameToRouteService('/API/CONFIG/')?.path).toMatchInlineSnapshot('"/api/config/"');
151
+ expect(pathnameToRouteService('/API/CONFIG/index.html')?.path).toMatchInlineSnapshot('"/api/config/"');
152
+ expect(pathnameToRouteService('/api/CONFIG#hash')?.path).toMatchInlineSnapshot('"/api/config/"');
153
+ });
154
+ });
@@ -1,6 +1,6 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { renderToMarkdownString } from "@rspress/core/_private/react";
3
- import { PageContext, ThemeContext, pathnameToRouteService, removeTrailingSlash, withBase } from "@rspress/runtime";
3
+ import { PageContext, ThemeContext, pathnameToRouteService, removeTrailingSlash, withBase } from "@rspress/core/runtime";
4
4
  import { UnheadProvider } from "@unhead/react/server";
5
5
  import { StaticRouter } from "react-router-dom";
6
6
  import { App } from "./App.js";
@@ -0,0 +1,12 @@
1
+ import { addLeadingSlash, isProduction, removeTrailingSlash } from '@rspress/shared';
2
+ declare function withBase(url?: string): string;
3
+ declare function removeBase(url: string): string;
4
+ declare function isEqualPath(a: string, b: string): boolean;
5
+ declare function normalizeHrefInRuntime(link: string): string;
6
+ /**
7
+ * we do cleanUrls in runtime side
8
+ */
9
+ declare function cleanUrlByConfig(link: string): string;
10
+ declare function normalizeImagePath(imagePath: string): string;
11
+ declare function routePathToMdPath(routePath: string): string;
12
+ export { addLeadingSlash, removeTrailingSlash, isProduction, normalizeImagePath, cleanUrlByConfig, removeBase, withBase, isEqualPath, normalizeHrefInRuntime, routePathToMdPath, };
@@ -0,0 +1,34 @@
1
+ import { addLeadingSlash, isDataUrl, isExternalUrl, isProduction, normalizeHref, removeBase, removeHash, removeTrailingSlash, withBase } from "@rspress/shared";
2
+ import virtual_site_data from "virtual-site-data";
3
+ function utils_withBase(url = '/') {
4
+ return withBase(url, virtual_site_data.base);
5
+ }
6
+ function utils_removeBase(url) {
7
+ return removeBase(url, virtual_site_data.base);
8
+ }
9
+ function isEqualPath(a, b) {
10
+ return utils_removeBase(normalizeHref(removeHash(a), true)) === utils_removeBase(normalizeHref(removeHash(b), true));
11
+ }
12
+ function normalizeHrefInRuntime(link) {
13
+ const cleanUrls = Boolean(virtual_site_data?.route?.cleanUrls);
14
+ return normalizeHref(link, cleanUrls);
15
+ }
16
+ function cleanUrlByConfig(link) {
17
+ if (virtual_site_data?.route?.cleanUrls) return normalizeHref(link, true);
18
+ return link;
19
+ }
20
+ function normalizeImagePath(imagePath) {
21
+ if (isAbsoluteUrl(imagePath)) return imagePath;
22
+ if (!imagePath.startsWith('/')) return imagePath;
23
+ return utils_withBase(imagePath);
24
+ }
25
+ function routePathToMdPath(routePath) {
26
+ let url = routePath;
27
+ url = normalizeHref(url, false);
28
+ url = url.replace(/\.html(?=#|\?|$)/, '.md');
29
+ return utils_withBase(url);
30
+ }
31
+ function isAbsoluteUrl(path) {
32
+ return isExternalUrl(path) || isDataUrl(path) || path.startsWith('//');
33
+ }
34
+ export { addLeadingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, utils_removeBase as removeBase, removeTrailingSlash, routePathToMdPath, utils_withBase as withBase };
@@ -0,0 +1,34 @@
1
+ import { describe, expect, it, rs } from "@rstest/core";
2
+ import { routePathToMdPath } from "./utils.js";
3
+ rs.mock('virtual-site-data', ()=>({
4
+ default: {
5
+ base: '/'
6
+ }
7
+ }));
8
+ describe('routePathToMdPath', ()=>{
9
+ it('should match snapshot for various paths', ()=>{
10
+ const cases = [
11
+ '/foo/bar.html',
12
+ '/foo/bar.html#hash',
13
+ '/foo/bar.html?q=1',
14
+ '/foo/bar.html?q=1#hash',
15
+ '/foo.html',
16
+ '/simple.html#my-heading',
17
+ '/query.html?foo=bar&baz=qux',
18
+ '/complex.html?id=123#section-2'
19
+ ];
20
+ const results = cases.map((path)=>routePathToMdPath(path));
21
+ expect(results).toMatchInlineSnapshot(`
22
+ [
23
+ "/foo/bar.md",
24
+ "/foo/bar.md#hash",
25
+ "/foo/bar.md?q=1",
26
+ "/foo/bar.md?q=1#hash",
27
+ "/foo.md",
28
+ "/simple.md#my-heading",
29
+ "/query.md?foo=bar&baz=qux",
30
+ "/complex.md?id=123#section-2",
31
+ ]
32
+ `);
33
+ });
34
+ });
@@ -1,6 +1,6 @@
1
1
  import "./node/mdx/rehypePlugins/transformers/index.js";
2
+ export { SHIKI_TRANSFORMER_ADD_LANG, transformerAddLang } from "./node/mdx/rehypePlugins/transformers/add-lang.js";
2
3
  export { SHIKI_TRANSFORMER_ADD_LINE_NUMBERS, transformerAddLineNumbers } from "./node/mdx/rehypePlugins/transformers/add-line-numbers.js";
3
- export { SHIKI_TRANSFORMER_META_HIGHLIGHT, transformerCompatibleMetaHighlight } from "./node/mdx/rehypePlugins/transformers/meta-highlight.js";
4
4
  export { SHIKI_TRANSFORMER_ADD_TITLE, transformerAddTitle } from "./node/mdx/rehypePlugins/transformers/add-title.js";
5
- export { SHIKI_TRANSFORMER_ADD_LANG, transformerAddLang } from "./node/mdx/rehypePlugins/transformers/add-lang.js";
6
5
  export { SHIKI_TRANSFORMER_ADD_WRAP_CODE, transformerAddWrapCode } from "./node/mdx/rehypePlugins/transformers/add-wrap-code.js";
6
+ export { SHIKI_TRANSFORMER_META_HIGHLIGHT, transformerCompatibleMetaHighlight } from "./node/mdx/rehypePlugins/transformers/meta-highlight.js";
@@ -18,7 +18,7 @@ function CodeBlock({ containerElementClassName, title, lang = 'txt', wrapCode: w
18
18
  className: clsx('rp-codeblock__content', codeWrap && 'rp-codeblock__content--code-wrap', lineNumbersProp && 'rp-codeblock__content--line-numbers'),
19
19
  children: [
20
20
  /*#__PURE__*/ jsx("div", {
21
- className: "rp-codeblock__content__scroll-container rp-scrollbar",
21
+ className: "rp-codeblock__content__scroll-container rp-scrollbar rp-scrollbar--always",
22
22
  ref: copyElementRef,
23
23
  children: children
24
24
  }),
@@ -1,4 +1,4 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { getCustomMDXComponent, renderInlineMarkdown } from "@theme";
3
3
  import { slug } from "github-slugger";
4
4
  import { useMemo } from "react";
@@ -14,6 +14,9 @@ const getHeadingMap = ()=>{
14
14
  };
15
15
  };
16
16
  function FallbackHeading({ level, title }) {
17
+ if (process.env.__SSR_MD__) return /*#__PURE__*/ jsx(Fragment, {
18
+ children: `${'#'.repeat(level)} ${title}\n\n`
19
+ });
17
20
  const titleSlug = title && slug(title.trim());
18
21
  const Element = useMemo(()=>{
19
22
  const headingMap = getHeadingMap();
@@ -29,7 +29,7 @@ const useNavTransparent = ()=>{
29
29
  topArrived
30
30
  ]);
31
31
  return /*#__PURE__*/ jsx("style", {
32
- children: "body:not(.notTopArrived) .rp-nav {background: transparent !important; border-bottom: none !important;}.rp-nav {background: color-mix(in srgb,var(--rp-c-bg) 60%,transparent);backdrop-filter: blur(25px);}"
32
+ children: "body:not(.notTopArrived) .rp-nav {background: transparent !important; border-bottom: 1px solid transparent !important;}.rp-nav {background: color-mix(in srgb,var(--rp-c-bg) 60%,transparent);backdrop-filter: blur(25px);}"
33
33
  });
34
34
  };
35
35
  export { useNavTransparent };
@@ -74,6 +74,8 @@
74
74
  padding: .5rem 1rem;
75
75
  font-size: .875rem;
76
76
  font-weight: 500;
77
+ text-decoration: none;
78
+ transition: background .2s, border-color .2s;
77
79
  display: inline-flex;
78
80
  }
79
81
 
@@ -92,6 +94,10 @@
92
94
  cursor: pointer;
93
95
  }
94
96
 
97
+ .rp-home-hero__badge:is(a):hover {
98
+ border-color: var(--rp-c-brand);
99
+ }
100
+
95
101
  .rp-home-hero__title {
96
102
  font-size: 4rem;
97
103
  font-weight: 600;
@@ -1,6 +1,6 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { normalizeImagePath, useFrontmatter } from "@rspress/core/runtime";
3
- import { Button, renderHtmlOrText } from "@theme";
3
+ import { Button, Link, renderHtmlOrText } from "@theme";
4
4
  import "./index.css";
5
5
  import clsx from "clsx";
6
6
  const DEFAULT_HERO = {
@@ -31,10 +31,17 @@ function HomeHero({ beforeHeroActions, afterHeroActions }) {
31
31
  /*#__PURE__*/ jsxs("div", {
32
32
  className: "rp-home-hero__container",
33
33
  children: [
34
- hero.badge && /*#__PURE__*/ jsx("div", {
34
+ hero.badge && ('string' == typeof hero.badge ? /*#__PURE__*/ jsx("div", {
35
35
  className: "rp-home-hero__badge",
36
36
  children: hero.badge
37
- }),
37
+ }) : hero.badge.link ? /*#__PURE__*/ jsx(Link, {
38
+ href: hero.badge.link,
39
+ className: "rp-home-hero__badge",
40
+ children: hero.badge.text
41
+ }) : /*#__PURE__*/ jsx("div", {
42
+ className: "rp-home-hero__badge",
43
+ children: hero.badge.text
44
+ })),
38
45
  /*#__PURE__*/ jsxs("div", {
39
46
  className: "rp-home-hero__content",
40
47
  children: [
@@ -43,7 +43,6 @@
43
43
  border-radius: 8px;
44
44
  flex: 1;
45
45
  align-self: stretch;
46
- padding-left: 8px;
47
46
  padding-right: 8px;
48
47
  font-size: 14px;
49
48
  font-style: normal;
@@ -54,8 +53,10 @@
54
53
  }
55
54
 
56
55
  .rp-hover-group__item__link {
56
+ align-items: center;
57
+ gap: 2px;
57
58
  height: 100%;
58
- display: block;
59
+ display: flex;
59
60
  }
60
61
 
61
62
  .rp-hover-group__item--active {
@@ -1,7 +1,89 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { Link } from "@theme";
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { matchNavbar, useLocation } from "@rspress/core/runtime";
3
+ import { Link, Tag } from "@theme";
3
4
  import clsx from "clsx";
4
5
  import "./index.css";
6
+ function HoverGroupItem({ item, activeMatcher, depth = 0 }) {
7
+ const { pathname } = useLocation();
8
+ if ('items' in item && item.items && item.items.length > 0) {
9
+ const hasLink = 'link' in item && item.link;
10
+ return /*#__PURE__*/ jsxs(Fragment, {
11
+ children: [
12
+ hasLink && /*#__PURE__*/ jsx("li", {
13
+ className: "rp-hover-group__item",
14
+ style: {
15
+ paddingLeft: `${8 + 12 * depth}px`
16
+ },
17
+ "data-depth": depth,
18
+ children: /*#__PURE__*/ jsxs(Link, {
19
+ href: item.link,
20
+ "aria-label": item.text,
21
+ className: "rp-hover-group__item__link",
22
+ children: [
23
+ item.text,
24
+ 'tag' in item && item.tag && /*#__PURE__*/ jsx(Tag, {
25
+ tag: item.tag
26
+ })
27
+ ]
28
+ })
29
+ }, item.text),
30
+ item.items.map((subItem)=>/*#__PURE__*/ jsx(HoverGroupItem, {
31
+ item: subItem,
32
+ activeMatcher: activeMatcher,
33
+ depth: depth + 1
34
+ }, subItem.text))
35
+ ]
36
+ });
37
+ }
38
+ if ('link' in item) {
39
+ const { text, link } = item;
40
+ const isActiveItem = activeMatcher ? activeMatcher(item) : matchNavbar(item, pathname);
41
+ return /*#__PURE__*/ jsx("li", {
42
+ className: clsx('rp-hover-group__item', {
43
+ 'rp-hover-group__item--active': isActiveItem
44
+ }),
45
+ style: {
46
+ paddingLeft: `${8 + 12 * depth}px`
47
+ },
48
+ "data-depth": depth,
49
+ children: link ? /*#__PURE__*/ jsxs(Link, {
50
+ href: link,
51
+ "aria-label": text,
52
+ className: "rp-hover-group__item__link",
53
+ children: [
54
+ text,
55
+ 'tag' in item && item.tag && /*#__PURE__*/ jsx(Tag, {
56
+ tag: item.tag
57
+ })
58
+ ]
59
+ }) : /*#__PURE__*/ jsxs("div", {
60
+ className: "rp-hover-group__item__link",
61
+ children: [
62
+ text,
63
+ 'tag' in item && item.tag && /*#__PURE__*/ jsx(Tag, {
64
+ tag: item.tag
65
+ })
66
+ ]
67
+ })
68
+ }, text + link);
69
+ }
70
+ return /*#__PURE__*/ jsx("li", {
71
+ className: "rp-hover-group__item",
72
+ style: {
73
+ paddingLeft: `${8 + 12 * depth}px`
74
+ },
75
+ "data-depth": depth,
76
+ children: /*#__PURE__*/ jsxs("div", {
77
+ className: "rp-hover-group__item__link",
78
+ children: [
79
+ item.text,
80
+ 'tag' in item && item.tag && /*#__PURE__*/ jsx(Tag, {
81
+ tag: item.tag
82
+ })
83
+ ]
84
+ })
85
+ }, item.text);
86
+ }
5
87
  function HoverGroup({ items, customChildren, isOpen, position = 'center', activeMatcher }) {
6
88
  return /*#__PURE__*/ jsx("ul", {
7
89
  className: clsx('rp-hover-group', {
@@ -10,21 +92,10 @@ function HoverGroup({ items, customChildren, isOpen, position = 'center', active
10
92
  'rp-hover-group--center': 'center' === position,
11
93
  'rp-hover-group--right': 'right' === position
12
94
  }),
13
- children: customChildren ?? items?.map((item)=>{
14
- const { text, link } = item;
15
- const isActiveItem = activeMatcher ? activeMatcher(item) : false;
16
- return /*#__PURE__*/ jsx("li", {
17
- className: clsx('rp-hover-group__item', {
18
- 'rp-hover-group__item--active': isActiveItem
19
- }),
20
- children: /*#__PURE__*/ jsx(Link, {
21
- href: link,
22
- "aria-label": text,
23
- className: "rp-hover-group__item__link",
24
- children: text
25
- })
26
- }, text + link);
27
- })
95
+ children: customChildren ?? items?.map((item)=>/*#__PURE__*/ jsx(HoverGroupItem, {
96
+ item: item,
97
+ activeMatcher: activeMatcher
98
+ }, item.text))
28
99
  });
29
100
  }
30
101
  export { HoverGroup };
@@ -30,7 +30,7 @@
30
30
  text-align: center;
31
31
  justify-content: center;
32
32
  align-items: center;
33
- gap: 6px;
33
+ gap: 2px;
34
34
  height: 100%;
35
35
  font-size: 14px;
36
36
  font-style: normal;
@@ -1,7 +1,12 @@
1
1
  import type { NavItem, NavItemWithChildren, NavItemWithLink, NavItemWithLinkAndChildren } from '@rspress/core';
2
2
  import type { HoverGroupProps } from '@theme';
3
+ import { type ReactNode } from 'react';
3
4
  import './NavMenu.scss';
4
5
  export declare const SvgDown: (props: React.SVGProps<SVGSVGElement>) => import("react/jsx-runtime").JSX.Element;
6
+ export declare function NavMenuItemInner({ menuItem, children, }: {
7
+ menuItem: Partial<NavItemWithLink>;
8
+ children?: ReactNode;
9
+ }): import("react/jsx-runtime").JSX.Element;
5
10
  export declare function NavMenuItemWithChildren({ menuItem, activeMatcher, }: {
6
11
  menuItem: NavItemWithChildren | NavItemWithLinkAndChildren;
7
12
  activeMatcher?: HoverGroupProps['activeMatcher'];
@@ -9,7 +14,7 @@ export declare function NavMenuItemWithChildren({ menuItem, activeMatcher, }: {
9
14
  export declare function NavMenuItemWithLink({ menuItem, }: {
10
15
  menuItem: NavItemWithLink;
11
16
  }): import("react/jsx-runtime").JSX.Element;
12
- export declare function NavMenuItem({ menuItem: item }: {
17
+ export declare function NavMenuItem({ menuItem }: {
13
18
  menuItem: NavItem;
14
19
  }): import("react/jsx-runtime").JSX.Element;
15
20
  export declare function NavMenuDivider(): import("react/jsx-runtime").JSX.Element;