@rspress/core 2.0.10 → 2.0.12

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 (115) hide show
  1. package/dist/0~execa.js +1 -1
  2. package/dist/3323.js +8 -0
  3. package/dist/{2240.js → 6162.js} +1 -4
  4. package/dist/8006.js +1 -1
  5. package/dist/8857.js +1 -1
  6. package/dist/common-Qw-RoVFD.js +25 -0
  7. package/dist/eject-theme/components/Llms/LlmsContainer.tsx +1 -2
  8. package/dist/eject-theme/components/Llms/LlmsCopyButton.tsx +1 -2
  9. package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +1 -2
  10. package/dist/eject-theme/components/PackageManagerTabs/index.tsx +16 -17
  11. package/dist/eject-theme/components/Prompt/icons.tsx +1 -1
  12. package/dist/eject-theme/components/Prompt/index.scss +325 -380
  13. package/dist/eject-theme/components/Search/SearchPanel.tsx +1 -6
  14. package/dist/eject-theme/components/Search/logic/search.ts +10 -5
  15. package/dist/eject-theme/components/Search/logic/util.test.ts +20 -1
  16. package/dist/eject-theme/components/Search/logic/util.ts +4 -1
  17. package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +1 -1
  18. package/dist/eject-theme/components/Tabs/index.tsx +48 -41
  19. package/dist/entry/process.d.ts +1 -0
  20. package/dist/entry/process.js +65 -0
  21. package/dist/entry/utils.d.ts +7 -0
  22. package/dist/entry/utils.js +2 -0
  23. package/dist/entry/worker.d.ts +1 -0
  24. package/dist/entry/worker.js +74 -0
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.js +1 -0
  27. package/dist/node/PluginDriver.js +1 -1
  28. package/dist/node/auto-nav-sidebar/index.js +1 -1
  29. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  30. package/dist/node/auto-nav-sidebar/normalize.d.ts +1 -1
  31. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  32. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  33. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  34. package/dist/node/index.d.ts +1 -0
  35. package/dist/node/initRsbuild.js +1 -1
  36. package/dist/node/mdx/options.js +2 -1
  37. package/dist/node/mdx/processor.js +1 -1
  38. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  39. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  40. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  41. package/dist/node/mdx/rehypePlugins/transformers/add-title.js +3 -6
  42. package/dist/node/mdx/rehypePlugins/transformers/index.d.ts +1 -1
  43. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  44. package/dist/node/mdx/remarkPlugins/containerSyntax.d.ts +1 -1
  45. package/dist/node/mdx/remarkPlugins/fileCodeBlock.d.ts +1 -0
  46. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +9 -4
  47. package/dist/node/mdx/remarkPlugins/image.d.ts +1 -1
  48. package/dist/node/mdx/remarkPlugins/image.js +2 -1
  49. package/dist/node/mdx/remarkPlugins/link.d.ts +1 -1
  50. package/dist/node/mdx/remarkPlugins/link.js +1 -1
  51. package/dist/node/route/RoutePage.js +1 -1
  52. package/dist/node/route/RouteService.js +1 -1
  53. package/dist/node/route/extractPageData.js +1 -1
  54. package/dist/node/route/normalizeRoutePath.js +1 -1
  55. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +140 -140
  56. package/dist/node/runtimeModule/i18n.js +1 -1
  57. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  58. package/dist/node/runtimeModule/pageData/rsbuildPlugin.d.ts +1 -1
  59. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  60. package/dist/node/runtimeModule/searchHooks.js +1 -1
  61. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  62. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  63. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  64. package/dist/node/serve.js +1 -1
  65. package/dist/node/ssg/renderPages.js +2 -2
  66. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  67. package/dist/node/ssg/ssgEnv.js +1 -1
  68. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  69. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  70. package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
  71. package/dist/node/ssg-md/renderPage.js +1 -1
  72. package/dist/node/ssg-md/renderPages.js +1 -1
  73. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  74. package/dist/node/utils/checkLanguageParity.js +1 -1
  75. package/dist/node/utils/createHash.js +1 -1
  76. package/dist/node/utils/flattenMdxContent.js +1 -1
  77. package/dist/node/utils/getPageKey.js +1 -1
  78. package/dist/node/utils/reactAlias.js +1 -1
  79. package/dist/runtime/BrowserOnly.d.ts +7 -0
  80. package/dist/runtime/BrowserOnly.js +40 -0
  81. package/dist/runtime/BrowserOnly.test.d.ts +1 -0
  82. package/dist/runtime/index.d.ts +1 -0
  83. package/dist/runtime/index.js +1 -0
  84. package/dist/theme/components/DocContent/docComponents/a.d.ts +1 -1
  85. package/dist/theme/components/DocContent/docComponents/hr.d.ts +1 -1
  86. package/dist/theme/components/DocContent/docComponents/img.d.ts +1 -1
  87. package/dist/theme/components/DocContent/docComponents/index.d.ts +18 -18
  88. package/dist/theme/components/DocContent/docComponents/list.d.ts +3 -3
  89. package/dist/theme/components/DocContent/docComponents/paragraph.d.ts +3 -3
  90. package/dist/theme/components/DocContent/docComponents/table.d.ts +3 -3
  91. package/dist/theme/components/DocContent/docComponents/title.d.ts +6 -6
  92. package/dist/theme/components/Nav/hooks.d.ts +1 -1
  93. package/dist/theme/components/PackageManagerTabs/index.js +17 -17
  94. package/dist/theme/components/Prompt/icons.js +1 -1
  95. package/dist/theme/components/Prompt/index.css +11 -37
  96. package/dist/theme/components/Search/SearchPanel.js +1 -2
  97. package/dist/theme/components/Search/logic/search.js +5 -3
  98. package/dist/theme/components/Search/logic/util.js +2 -1
  99. package/dist/theme/components/Sidebar/SidebarItem.js +1 -0
  100. package/dist/theme/components/Tabs/index.d.ts +8 -4
  101. package/dist/theme/components/Tabs/index.js +19 -19
  102. package/dist/theme/layout/DocLayout/index.css +4 -0
  103. package/dist/theme/layout/DocLayout/index.js +3 -2
  104. package/dist/theme/logic/useThemeState.d.ts +5 -10
  105. package/dist/theme/logic/useThemeState.js +15 -20
  106. package/dist/utils-B--2TaWv.js +34 -0
  107. package/dist/utils-De75vAgL.js +7 -0
  108. package/package.json +13 -13
  109. package/dist/3425.js +0 -6
  110. package/dist/runtime/getSidebarDataGroup.test.js +0 -68
  111. package/dist/runtime/hooks/useWindowSize.test.js +0 -36
  112. package/dist/runtime/route.test.js +0 -154
  113. package/dist/runtime/utils.test.js +0 -34
  114. package/dist/theme/components/Search/logic/util.test.js +0 -51
  115. /package/dist/{2287.js → 2235.js} +0 -0
@@ -1,16 +1,11 @@
1
- declare global {
2
- interface Window {
3
- MODERN_THEME?: string;
4
- RSPRESS_THEME?: string;
5
- }
6
- }
7
1
  /** Resolved theme value used in the app */
8
- type ThemeValue = 'light' | 'dark';
2
+ export type ThemeValue = 'light' | 'dark';
9
3
  /** Theme config value stored in localStorage */
10
- type ThemeConfigValue = ThemeValue | 'auto';
4
+ export type ThemeConfigValue = ThemeValue | 'auto';
5
+ export declare const getStoredThemeConfig: (theme: ThemeValue, prefersDark: boolean) => ThemeConfigValue;
6
+ export declare const getResolvedTheme: (config: ThemeConfigValue, prefersDark: boolean) => ThemeValue;
11
7
  /**
12
8
  * State provider for theme context.
13
9
  * @internal
14
10
  */
15
- export declare function useThemeState(): readonly [ThemeValue, (value: ThemeValue, storeValue?: ThemeConfigValue) => void];
16
- export {};
11
+ export declare function useThemeState(): readonly [ThemeValue, (value: ThemeValue) => void];
@@ -1,9 +1,15 @@
1
1
  import { useSite } from "@rspress/core/runtime";
2
- import { useCallback, useLayoutEffect, useMemo } from "react";
2
+ import { useCallback, useLayoutEffect } from "react";
3
3
  import { useMediaQuery } from "./useMediaQuery.js";
4
4
  import { useStorageValue } from "./useStorageValue.js";
5
5
  const APPEARANCE_KEY = 'rspress-theme-appearance';
6
6
  const MEDIA_QUERY = '(prefers-color-scheme: dark)';
7
+ const getSystemTheme = (prefersDark)=>prefersDark ? 'dark' : 'light';
8
+ const getStoredThemeConfig = (theme, prefersDark)=>{
9
+ const systemTheme = getSystemTheme(prefersDark);
10
+ return theme === systemTheme ? 'auto' : theme;
11
+ };
12
+ const getResolvedTheme = (config, prefersDark)=>'auto' === config ? getSystemTheme(prefersDark) : config;
7
13
  const applyThemeToDOM = (theme)=>{
8
14
  if (!document?.documentElement) return;
9
15
  const root = document.documentElement;
@@ -16,35 +22,24 @@ function useThemeState() {
16
22
  const disableDarkMode = false === site.themeConfig.darkMode;
17
23
  const prefersDark = useMediaQuery(MEDIA_QUERY);
18
24
  const [storedConfig, setStoredConfig] = useStorageValue(APPEARANCE_KEY, 'auto');
19
- const resolvedTheme = useMemo(()=>{
20
- if ("u" < typeof window) return 'light';
21
- if (disableDarkMode) return 'light';
22
- const defaultTheme = window.RSPRESS_THEME;
23
- if (defaultTheme) return 'dark' === defaultTheme ? 'dark' : 'light';
24
- return 'auto' === storedConfig ? prefersDark ? 'dark' : 'light' : storedConfig;
25
- }, [
26
- disableDarkMode,
27
- prefersDark,
28
- storedConfig
29
- ]);
30
- const setTheme = useCallback((value, storeValue = value)=>{
25
+ const theme = disableDarkMode ? 'light' : getResolvedTheme(storedConfig, prefersDark);
26
+ const setTheme = useCallback((value)=>{
31
27
  if (disableDarkMode) return;
32
- setStoredConfig(storeValue);
28
+ setStoredConfig(getStoredThemeConfig(value, prefersDark));
33
29
  applyThemeToDOM(value);
34
30
  }, [
35
31
  disableDarkMode,
32
+ prefersDark,
36
33
  setStoredConfig
37
34
  ]);
38
35
  useLayoutEffect(()=>{
39
- if (disableDarkMode) return;
40
- applyThemeToDOM(resolvedTheme);
36
+ applyThemeToDOM(theme);
41
37
  }, [
42
- disableDarkMode,
43
- resolvedTheme
38
+ theme
44
39
  ]);
45
40
  return [
46
- resolvedTheme,
41
+ theme,
47
42
  setTheme
48
43
  ];
49
44
  }
50
- export { useThemeState };
45
+ export { getResolvedTheme, getStoredThemeConfig, useThemeState };
@@ -0,0 +1,34 @@
1
+ import { pathToFileURL } from "node:url";
2
+ let importESMCached;
3
+ function getImportESM() {
4
+ if (void 0 === importESMCached) importESMCached = new Function("specifier", "return import(specifier)");
5
+ return importESMCached;
6
+ }
7
+ const handlerCache = new Map();
8
+ async function getHandler(filename, name) {
9
+ let handler = handlerCache.get(`${filename}/${name}`);
10
+ if (void 0 !== handler) return handler;
11
+ try {
12
+ const handlerModule = await import(filename);
13
+ handler = "function" != typeof handlerModule.default && handlerModule.default || handlerModule;
14
+ if ("function" != typeof handler) handler = await handler[name];
15
+ } catch {}
16
+ if ("function" != typeof handler) {
17
+ handler = await getImportESM()(pathToFileURL(filename).href);
18
+ if ("function" != typeof handler) handler = await handler[name];
19
+ }
20
+ if ("function" != typeof handler) return null;
21
+ if (handlerCache.size > 1e3) {
22
+ const [handler$1] = handlerCache;
23
+ const key = handler$1[0];
24
+ handlerCache.delete(key);
25
+ }
26
+ handlerCache.set(`${filename}/${name}`, handler);
27
+ return handler;
28
+ }
29
+ function throwInNextTick(error) {
30
+ process.nextTick(()=>{
31
+ throw error;
32
+ });
33
+ }
34
+ export { getHandler, throwInNextTick };
@@ -0,0 +1,7 @@
1
+ function stdout() {
2
+ return console._stdout || process.stdout || void 0;
3
+ }
4
+ function stderr() {
5
+ return console._stderr || process.stderr || void 0;
6
+ }
7
+ export { stderr, stdout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -60,11 +60,11 @@
60
60
  "dependencies": {
61
61
  "@mdx-js/mdx": "^3.1.1",
62
62
  "@mdx-js/react": "^3.1.1",
63
- "@rsbuild/core": "^2.0.2",
63
+ "@rsbuild/core": "^2.0.6",
64
64
  "@rsbuild/plugin-react": "~2.0.0",
65
65
  "@shikijs/rehype": "^4.0.2",
66
66
  "@types/unist": "^3.0.3",
67
- "@unhead/react": "^2.1.13",
67
+ "@unhead/react": "^2.1.15",
68
68
  "body-scroll-lock": "4.0.0-beta.0",
69
69
  "clsx": "2.1.1",
70
70
  "copy-to-clipboard": "^3.3.3",
@@ -75,12 +75,12 @@
75
75
  "mdast-util-mdxjs-esm": "^2.0.1",
76
76
  "medium-zoom": "1.1.0",
77
77
  "nprogress": "^0.2.0",
78
- "react": "^19.2.5",
79
- "react-dom": "^19.2.5",
78
+ "react": "^19.2.6",
79
+ "react-dom": "^19.2.6",
80
80
  "react-lazy-with-preload": "^2.2.1",
81
81
  "react-reconciler": "0.33.0",
82
82
  "react-render-to-markdown": "19.0.1",
83
- "react-router-dom": "^7.13.2",
83
+ "react-router-dom": "^7.15.1",
84
84
  "rehype-external-links": "^3.0.0",
85
85
  "rehype-raw": "^7.0.0",
86
86
  "remark-cjk-friendly": "^2.0.1",
@@ -95,13 +95,13 @@
95
95
  "unist-util-remove": "^4.0.0",
96
96
  "unist-util-visit": "^5.1.0",
97
97
  "unist-util-visit-children": "^3.0.0",
98
- "@rspress/shared": "2.0.10"
98
+ "@rspress/shared": "2.0.12"
99
99
  },
100
100
  "devDependencies": {
101
101
  "@microsoft/api-extractor": "^7.57.7",
102
- "@rsbuild/plugin-sass": "~1.5.1",
103
- "@rsbuild/plugin-svgr": "^2.0.1",
104
- "@rslib/core": "0.21.3",
102
+ "@rsbuild/plugin-sass": "~1.5.2",
103
+ "@rsbuild/plugin-svgr": "^2.0.2",
104
+ "@rslib/core": "0.21.5",
105
105
  "@types/body-scroll-lock": "^3.1.2",
106
106
  "@types/hast": "^3.0.4",
107
107
  "@types/mdast": "^4.0.4",
@@ -110,7 +110,7 @@
110
110
  "@types/react": "^19.2.14",
111
111
  "@types/react-dom": "^19.2.3",
112
112
  "@types/react-reconciler": "^0.33.0",
113
- "@types/web": "^0.0.347",
113
+ "@types/web": "^0.0.349",
114
114
  "cac": "^7.0.0",
115
115
  "chokidar": "^3.6.0",
116
116
  "execa": "8.0.1",
@@ -119,7 +119,7 @@
119
119
  "memfs": "^4.57.2",
120
120
  "p-map": "^7.0.4",
121
121
  "picocolors": "^1.1.1",
122
- "postcss": "8.5.12",
122
+ "postcss": "8.5.14",
123
123
  "remark-directive": "^4.0.0",
124
124
  "rsbuild-plugin-publint": "^0.3.4",
125
125
  "rsbuild-plugin-virtual-module": "0.4.2",
@@ -127,7 +127,7 @@
127
127
  "tinyglobby": "^0.2.16",
128
128
  "tinypool": "^1.1.1",
129
129
  "ts-json-schema-generator": "^2.9.0",
130
- "typescript": "^5.8.2",
130
+ "typescript": "^6.0.3",
131
131
  "vfile": "^6.0.3",
132
132
  "@rspress/config": "1.0.0"
133
133
  },
package/dist/3425.js DELETED
@@ -1,6 +0,0 @@
1
- export { readFile } from "node:fs/promises";
2
- export { default as node_path } from "node:path";
3
- export { cwd } from "node:process";
4
- export { logger } from "@rspress/shared/logger";
5
- export { visit } from "unist-util-visit";
6
- export { addLeadingSlash, isExternalUrl, isProduction, normalizeHref, parseUrl, withBase } from "@rspress/shared";
@@ -1,68 +0,0 @@
1
- import { describe, expect, it, rs } from "@rstest/core";
2
- import { getSidebarDataGroup } from "./hooks/useSidebar.js";
3
- import { isActive } from "./route.js";
4
- rs.mock('virtual-i18n-text', ()=>({
5
- default: {}
6
- }));
7
- rs.mock('virtual-site-data', ()=>({
8
- default: {
9
- base: '/'
10
- }
11
- }));
12
- rs.mock('virtual-routes', ()=>({
13
- routes: []
14
- }));
15
- describe('getSidebarDataGroup', ()=>{
16
- it('when using "/"', async ()=>{
17
- expect(getSidebarDataGroup({
18
- '/': [],
19
- '/guide': [
20
- {
21
- text: 'Getting Started',
22
- link: '/guide/getting-started'
23
- }
24
- ]
25
- }, '/guide/getting-started')).toMatchInlineSnapshot(`
26
- [
27
- {
28
- "link": "/guide/getting-started",
29
- "text": "Getting Started",
30
- },
31
- ]
32
- `);
33
- });
34
- it('when using api-extractor', async ()=>{
35
- expect(getSidebarDataGroup({
36
- '/api/react': [
37
- {
38
- link: '/api/react.use',
39
- text: 'react.use'
40
- }
41
- ]
42
- }, '/api/react.use.html')).toMatchInlineSnapshot(`
43
- [
44
- {
45
- "link": "/api/react.use",
46
- "text": "react.use",
47
- },
48
- ]
49
- `);
50
- });
51
- });
52
- describe('isActive', ()=>{
53
- it('pass cases', ()=>{
54
- const routes = [
55
- '/api/config',
56
- '/api/config.html',
57
- '/api/config/',
58
- '/api/config/index',
59
- '/api/config/index.html'
60
- ];
61
- for (const route of routes)for (const route2 of routes)expect(isActive(route, route2)).toBeTruthy();
62
- });
63
- it('failed cases', ()=>{
64
- expect(isActive('/api/config', '/api/config2')).toBeFalsy();
65
- expect(isActive('/api/config', '/api/config/config2')).toBeFalsy();
66
- expect(isActive('/api/config/index', '/api/config/config2')).toBeFalsy();
67
- });
68
- });
@@ -1,36 +0,0 @@
1
- import { describe, expect, it } from "@rstest/core";
2
- import * as __rspack_external_node_fs_5ea92f0c from "node:fs";
3
- import * as __rspack_external_node_path_c5b9b54f from "node:path";
4
- describe('useWindowSize', ()=>{
5
- it('should have debounce implementation with RESIZE_DEBOUNCE_MS constant', ()=>{
6
- const filePath = __rspack_external_node_path_c5b9b54f.join(__dirname, 'useWindowSize.ts');
7
- const fileContent = __rspack_external_node_fs_5ea92f0c.readFileSync(filePath, 'utf-8');
8
- expect(fileContent).toContain('const RESIZE_DEBOUNCE_MS = 150');
9
- expect(fileContent).toContain('setTimeout');
10
- expect(fileContent).toContain('RESIZE_DEBOUNCE_MS');
11
- });
12
- it('should clear timeout with conditional check', ()=>{
13
- const filePath = __rspack_external_node_path_c5b9b54f.join(__dirname, 'useWindowSize.ts');
14
- const fileContent = __rspack_external_node_fs_5ea92f0c.readFileSync(filePath, 'utf-8');
15
- expect(fileContent).toContain('if (timeoutId) clearTimeout(timeoutId)');
16
- expect(fileContent).not.toContain('clearTimeout(timeoutId!)');
17
- });
18
- it('should register and cleanup resize event listener', ()=>{
19
- const filePath = __rspack_external_node_path_c5b9b54f.join(__dirname, 'useWindowSize.ts');
20
- const fileContent = __rspack_external_node_fs_5ea92f0c.readFileSync(filePath, 'utf-8');
21
- expect(fileContent).toContain("addEventListener('resize'");
22
- expect(fileContent).toContain("removeEventListener('resize'");
23
- });
24
- it('should set initial size immediately', ()=>{
25
- const filePath = __rspack_external_node_path_c5b9b54f.join(__dirname, 'useWindowSize.ts');
26
- const fileContent = __rspack_external_node_fs_5ea92f0c.readFileSync(filePath, 'utf-8');
27
- const setStateMatch = fileContent.match(/setSize\(\{[^}]+\}\)/g);
28
- expect(setStateMatch).toBeTruthy();
29
- expect(setStateMatch?.length).toBeGreaterThanOrEqual(2);
30
- });
31
- it('should export useWindowSize function', async ()=>{
32
- const module = await import("./useWindowSize.js");
33
- expect(module.useWindowSize).toBeDefined();
34
- expect(typeof module.useWindowSize).toBe('function');
35
- });
36
- });
@@ -1,154 +0,0 @@
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,34 +0,0 @@
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,51 +0,0 @@
1
- import { describe, expect, test } from "@rstest/core";
2
- import { backTrackHeaders } from "./util.js";
3
- describe('utils logic', ()=>{
4
- test('back track the headers', ()=>{
5
- const headers = [
6
- {
7
- depth: 1,
8
- text: '1',
9
- id: '1'
10
- },
11
- {
12
- depth: 2,
13
- text: '2',
14
- id: '2'
15
- },
16
- {
17
- depth: 3,
18
- text: '3',
19
- id: '3'
20
- },
21
- {
22
- depth: 4,
23
- text: '4',
24
- id: '4'
25
- },
26
- {
27
- depth: 5,
28
- text: '5',
29
- id: '5'
30
- }
31
- ];
32
- const res = backTrackHeaders(headers, 3);
33
- expect(res).toEqual([
34
- {
35
- depth: 2,
36
- text: '2',
37
- id: '2'
38
- },
39
- {
40
- depth: 3,
41
- text: '3',
42
- id: '3'
43
- },
44
- {
45
- depth: 4,
46
- text: '4',
47
- id: '4'
48
- }
49
- ]);
50
- });
51
- });
File without changes