@rspress/core 2.0.22 → 2.1.0-beta.1
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.
- package/bin/rspress.js +3 -1
- package/dist/{v~0.js → b~0.js} +19 -16
- package/dist/cli/index.js +2 -2
- package/dist/{common-Qw-RoVFD.js → common-Bo3KCGim.js} +4 -1
- package/dist/config/loadConfigFile.js +1 -1
- package/dist/eject-theme/components/Link/getHref.ts +1 -0
- package/dist/eject-theme/components/Link/index.tsx +0 -3
- package/dist/eject-theme/components/Link/useLinkNavigate.ts +29 -54
- package/dist/eject-theme/components/Search/SearchPanel.tsx +9 -5
- package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +5 -2
- package/dist/eject-theme/components/Search/useSearchPanel.ts +105 -37
- package/dist/eject-theme/components/SocialLinks/GithubStars.test.tsx +4 -1
- package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +1 -1
- package/dist/eject-theme/components/SocialLinks/SocialLink.tsx +2 -2
- package/dist/eject-theme/components/SourceCode/index.tsx +1 -1
- package/dist/entry/worker.js +1 -1
- package/dist/{o~0.js → h~0.js} +18 -29
- package/dist/index.d.ts +1 -1
- package/dist/node/PluginDriver.js +8 -2
- package/dist/node/auto-nav-sidebar/index.js +1 -1
- package/dist/node/auto-nav-sidebar/locales.js +1 -1
- package/dist/node/auto-nav-sidebar/normalize.js +1 -1
- package/dist/node/auto-nav-sidebar/utils.js +1 -1
- package/dist/node/auto-nav-sidebar/walk.js +1 -1
- package/dist/node/constants.js +1 -1
- package/dist/node/eject.js +1 -1
- package/dist/node/initRsbuild.js +9 -5
- package/dist/node/llms.d.ts +1 -1
- package/dist/node/llms.js +2 -2
- package/dist/node/logger/hint.d.ts +1 -0
- package/dist/node/logger/hint.js +8 -2
- package/dist/node/route/RoutePage.js +1 -1
- package/dist/node/route/RouteService.js +1 -1
- package/dist/node/route/extractPageData.js +1 -1
- package/dist/node/route/normalizeRoutePath.js +1 -1
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +28 -0
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +28 -0
- package/dist/node/runtimeModule/i18n.js +1 -1
- package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
- package/dist/node/runtimeModule/searchHooks.js +2 -2
- package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
- package/dist/node/serve.js +1 -1
- package/dist/node/sitemap.d.ts +2 -0
- package/dist/node/sitemap.js +103 -0
- package/dist/node/ssg/alternateLinks.js +1 -1
- package/dist/node/ssg/htmlFile.js +1 -1
- package/dist/node/ssg/renderHtmlTemplate.js +4 -3
- package/dist/node/ssg/renderPage.js +1 -1
- package/dist/node/ssg/renderPageWorker.js +1 -1
- package/dist/node/ssg/renderPages.js +2 -2
- package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
- package/dist/node/ssg/ssgEnv.js +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
- package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
- package/dist/node/ssg-md/renderPage.js +5 -4
- package/dist/node/ssg-md/renderPages.js +2 -2
- package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
- package/dist/node/utils/checkLanguageParity.js +1 -1
- package/dist/node/utils/createHash.js +1 -1
- package/dist/node/utils/flattenMdxContent.js +1 -1
- package/dist/node/utils/getPageKey.js +1 -1
- package/dist/node/utils/reactAlias.js +5 -2
- package/dist/n~0.js +11 -10
- package/dist/runtime/App.js +15 -27
- package/dist/runtime/ClientApp.d.ts +3 -2
- package/dist/runtime/ClientApp.js +27 -21
- package/dist/runtime/ErrorRoute.d.ts +1 -0
- package/dist/runtime/ErrorRoute.js +30 -0
- package/dist/runtime/PageRoute.d.ts +2 -0
- package/dist/runtime/PageRoute.js +58 -0
- package/dist/runtime/createServerRouter.d.ts +4 -0
- package/dist/runtime/createServerRouter.js +17 -0
- package/dist/runtime/csrClientEntry.js +5 -2
- package/dist/runtime/hooks/createExternalStore.d.ts +4 -0
- package/dist/runtime/hooks/createExternalStore.js +20 -0
- package/dist/runtime/hooks/useGlobalComponents.d.ts +1 -0
- package/dist/runtime/hooks/useGlobalComponents.js +10 -0
- package/dist/runtime/hooks/useI18n.js +5 -3
- package/dist/runtime/hooks/useI18nText.d.ts +1 -0
- package/dist/runtime/hooks/useI18nText.js +10 -0
- package/dist/runtime/hooks/usePages.d.ts +2 -0
- package/dist/runtime/hooks/usePages.js +12 -3
- package/dist/runtime/hooks/useSearchHooks.d.ts +8 -0
- package/dist/runtime/hooks/useSearchHooks.js +14 -0
- package/dist/runtime/hooks/useSite.d.ts +1 -0
- package/dist/runtime/hooks/useSite.js +9 -2
- package/dist/runtime/hooks/useWebMcp.d.ts +36 -0
- package/dist/runtime/hooks/useWebMcp.js +80 -0
- package/dist/runtime/index.d.ts +6 -2
- package/dist/runtime/index.js +8 -2
- package/dist/runtime/initPageData.d.ts +0 -3
- package/dist/runtime/initPageData.js +13 -49
- package/dist/runtime/pageDataLoader.d.ts +11 -0
- package/dist/runtime/pageDataLoader.js +7 -0
- package/dist/runtime/route.js +5 -5
- package/dist/runtime/ssrClientEntry.js +14 -6
- package/dist/runtime/ssrMdServerEntry.js +10 -21
- package/dist/runtime/ssrServerEntry.js +10 -21
- package/dist/runtime/utils.js +6 -6
- package/dist/static/assets/package.json +58 -0
- package/dist/theme/components/Link/index.js +0 -4
- package/dist/theme/components/Link/useLinkNavigate.d.ts +2 -2
- package/dist/theme/components/Link/useLinkNavigate.js +13 -35
- package/dist/theme/components/Search/SearchPanel.js +8 -6
- package/dist/theme/components/Search/logic/providers/LocalProvider.js +5 -2
- package/dist/theme/components/Search/useSearchPanel.js +75 -27
- package/dist/theme/components/SocialLinks/GithubStars.js +1 -1
- package/dist/theme/components/SocialLinks/SocialLink.js +2 -2
- package/dist/theme/components/SourceCode/index.js +1 -1
- package/dist/theme/hooks/useWebMcpNavigation.d.ts +6 -0
- package/dist/theme/hooks/useWebMcpNavigation.js +123 -0
- package/dist/theme/hooks/useWebMcpPageList.d.ts +6 -0
- package/dist/theme/hooks/useWebMcpPageList.js +25 -0
- package/dist/theme/hooks/useWebMcpPageReading.d.ts +7 -0
- package/dist/theme/hooks/useWebMcpPageReading.js +23 -0
- package/dist/theme/hooks/useWebMcpSiteInfo.d.ts +6 -0
- package/dist/theme/hooks/useWebMcpSiteInfo.js +22 -0
- package/dist/theme/index.d.ts +5 -0
- package/dist/theme/index.js +5 -0
- package/dist/theme/layout/ErrorLayout/index.css +52 -0
- package/dist/theme/layout/ErrorLayout/index.d.ts +8 -0
- package/dist/theme/layout/ErrorLayout/index.js +76 -0
- package/dist/theme/logic/utils.d.ts +0 -2
- package/dist/theme/logic/utils.js +56 -6
- package/dist/theme/webMcp/tools.d.ts +56 -0
- package/dist/theme/webMcp/tools.js +122 -0
- package/dist/theme/webMcp/types.d.ts +35 -0
- package/dist/theme/webMcp/types.js +0 -0
- package/dist/tinypool~0.js +19 -49
- package/dist/tu~0.js +3 -0
- package/package.json +17 -17
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as __rspack_external_virtual_search_hooks_705b6e40 from "virtual-search-hooks";
|
|
2
|
+
import { createExternalStore } from "./createExternalStore.js";
|
|
3
|
+
const store = createExternalStore({
|
|
4
|
+
...__rspack_external_virtual_search_hooks_705b6e40
|
|
5
|
+
});
|
|
6
|
+
function useSearchHooks() {
|
|
7
|
+
return store.useValue();
|
|
8
|
+
}
|
|
9
|
+
if (import.meta.webpackHot) import.meta.webpackHot.accept('virtual-search-hooks', ()=>{
|
|
10
|
+
store.update({
|
|
11
|
+
...__rspack_external_virtual_search_hooks_705b6e40
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
export { useSearchHooks };
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import virtual_site_data from "virtual-site-data";
|
|
2
|
+
import { createExternalStore } from "./createExternalStore.js";
|
|
3
|
+
let siteData = virtual_site_data;
|
|
4
|
+
const store = createExternalStore(siteData);
|
|
2
5
|
function useSite() {
|
|
3
6
|
return {
|
|
4
|
-
site:
|
|
7
|
+
site: store.useValue()
|
|
5
8
|
};
|
|
6
9
|
}
|
|
7
|
-
|
|
10
|
+
if (import.meta.webpackHot) import.meta.webpackHot.accept('virtual-site-data', ()=>{
|
|
11
|
+
siteData = virtual_site_data;
|
|
12
|
+
store.update(siteData);
|
|
13
|
+
});
|
|
14
|
+
export { siteData, useSite };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface WebMcpExecuteOptions {
|
|
2
|
+
/** Cancellation requested by the browser or agent. */
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
}
|
|
5
|
+
export interface WebMcpOptions<TInput = unknown, TResult = unknown> {
|
|
6
|
+
name: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
description: string;
|
|
9
|
+
/** JSON Schema describing the input. Validate untrusted inputs in execute. */
|
|
10
|
+
inputSchema?: Record<string, unknown>;
|
|
11
|
+
annotations?: {
|
|
12
|
+
readOnlyHint?: boolean;
|
|
13
|
+
untrustedContentHint?: boolean;
|
|
14
|
+
consequentialHint?: boolean;
|
|
15
|
+
debugging?: boolean;
|
|
16
|
+
};
|
|
17
|
+
execute(input: TInput, options: WebMcpExecuteOptions): TResult | Promise<TResult>;
|
|
18
|
+
/** Register only while enabled. Defaults to true. */
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
/** Additional secure origins allowed to discover this tool. */
|
|
21
|
+
exposedTo?: string[];
|
|
22
|
+
}
|
|
23
|
+
export interface WebMcpState {
|
|
24
|
+
supported: boolean;
|
|
25
|
+
registered: boolean;
|
|
26
|
+
/** Registration error. Execution errors are returned to the caller. */
|
|
27
|
+
error: Error | null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Registers a component-owned tool with the native browser WebMCP API.
|
|
31
|
+
* Calls use the latest committed handler; disabling or unmounting unregisters
|
|
32
|
+
* the tool. Safe during SSR and in browsers without WebMCP support.
|
|
33
|
+
* @returns Browser support, registration status, and any registration error.
|
|
34
|
+
* @unstable
|
|
35
|
+
*/
|
|
36
|
+
export declare function useWebMcp<TInput = unknown, TResult = unknown>(options: WebMcpOptions<TInput, TResult>): WebMcpState;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
const useCommittedEffect = "u" < typeof window ? useEffect : useLayoutEffect;
|
|
3
|
+
const toError = (error)=>error instanceof Error ? error : new Error(String(error));
|
|
4
|
+
function useWebMcp(options) {
|
|
5
|
+
const { execute, enabled = true, exposedTo, ...descriptor } = options;
|
|
6
|
+
const current = useRef(execute);
|
|
7
|
+
useCommittedEffect(()=>{
|
|
8
|
+
current.current = execute;
|
|
9
|
+
});
|
|
10
|
+
let key = '';
|
|
11
|
+
let preparationError = null;
|
|
12
|
+
try {
|
|
13
|
+
key = JSON.stringify({
|
|
14
|
+
descriptor,
|
|
15
|
+
exposedTo
|
|
16
|
+
});
|
|
17
|
+
} catch (error) {
|
|
18
|
+
preparationError = toError(error);
|
|
19
|
+
}
|
|
20
|
+
const preparationMessage = preparationError?.message;
|
|
21
|
+
const [state, setState] = useState({
|
|
22
|
+
supported: false,
|
|
23
|
+
registered: false,
|
|
24
|
+
error: null
|
|
25
|
+
});
|
|
26
|
+
useEffect(()=>{
|
|
27
|
+
const context = "u" < typeof document ? void 0 : document.modelContext;
|
|
28
|
+
const supported = 'function' == typeof context?.registerTool;
|
|
29
|
+
if (!supported || !enabled || void 0 !== preparationMessage) return void setState({
|
|
30
|
+
supported,
|
|
31
|
+
registered: false,
|
|
32
|
+
error: void 0 === preparationMessage ? null : new Error(preparationMessage)
|
|
33
|
+
});
|
|
34
|
+
const controller = new AbortController();
|
|
35
|
+
const metadata = JSON.parse(key);
|
|
36
|
+
setState({
|
|
37
|
+
supported: true,
|
|
38
|
+
registered: false,
|
|
39
|
+
error: null
|
|
40
|
+
});
|
|
41
|
+
const failed = (error)=>{
|
|
42
|
+
if (controller.signal.aborted) return;
|
|
43
|
+
controller.abort();
|
|
44
|
+
setState({
|
|
45
|
+
supported: true,
|
|
46
|
+
registered: false,
|
|
47
|
+
error: toError(error)
|
|
48
|
+
});
|
|
49
|
+
console.error(`[Rspress] Failed to register ${metadata.descriptor.name}:`, error);
|
|
50
|
+
};
|
|
51
|
+
try {
|
|
52
|
+
const registration = context.registerTool({
|
|
53
|
+
...metadata.descriptor,
|
|
54
|
+
execute: (input, executionOptions)=>{
|
|
55
|
+
executionOptions?.signal?.throwIfAborted();
|
|
56
|
+
return current.current(input, executionOptions ?? {});
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
signal: controller.signal,
|
|
60
|
+
exposedTo: metadata.exposedTo
|
|
61
|
+
});
|
|
62
|
+
Promise.resolve(registration).then(()=>{
|
|
63
|
+
if (!controller.signal.aborted) setState({
|
|
64
|
+
supported: true,
|
|
65
|
+
registered: true,
|
|
66
|
+
error: null
|
|
67
|
+
});
|
|
68
|
+
}, failed);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
failed(error);
|
|
71
|
+
}
|
|
72
|
+
return ()=>controller.abort();
|
|
73
|
+
}, [
|
|
74
|
+
key,
|
|
75
|
+
enabled,
|
|
76
|
+
preparationMessage
|
|
77
|
+
]);
|
|
78
|
+
return state;
|
|
79
|
+
}
|
|
80
|
+
export { useWebMcp };
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -7,18 +7,22 @@ export { useActiveMatcher } from './hooks/useActiveMatcher.js';
|
|
|
7
7
|
export { ThemeContext, useDark } from './hooks/useDark.js';
|
|
8
8
|
export { useFrontmatter } from './hooks/useFrontmatter.js';
|
|
9
9
|
export { useI18n } from './hooks/useI18n.js';
|
|
10
|
+
export { useI18nText } from './hooks/useI18nText.js';
|
|
10
11
|
export { useLang } from './hooks/useLang.js';
|
|
11
12
|
export { useLocaleSiteData } from './hooks/useLocaleSiteData.js';
|
|
12
13
|
export { useNav } from './hooks/useNav.js';
|
|
13
14
|
export { PageContext, usePage } from './hooks/usePage.js';
|
|
14
15
|
export { usePageData } from './hooks/usePageData.js';
|
|
15
|
-
export { usePages } from './hooks/usePages.js';
|
|
16
|
+
export { usePages, searchIndexHash } from './hooks/usePages.js';
|
|
16
17
|
export { getSidebarDataGroup, useSidebar, useSidebarDynamic, } from './hooks/useSidebar.js';
|
|
17
18
|
export { useSite } from './hooks/useSite.js';
|
|
18
19
|
export { useVersion } from './hooks/useVersion.js';
|
|
20
|
+
export { useWebMcp, type WebMcpOptions, type WebMcpState, type WebMcpExecuteOptions, } from './hooks/useWebMcp.js';
|
|
19
21
|
export { useWindowSize } from './hooks/useWindowSize.js';
|
|
20
|
-
export { initPageData
|
|
22
|
+
export { initPageData } from './initPageData.js';
|
|
21
23
|
export { NoSSR } from './NoSSR.js';
|
|
22
24
|
export { safePreconnect, safePreload } from './reactDom.js';
|
|
23
25
|
export { isActive, pathnameToRouteService, preloadLink } from './route.js';
|
|
24
26
|
export { addLeadingSlash, addTrailingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase, withSiteOrigin, } from './utils.js';
|
|
27
|
+
export declare const socialLinks: Record<string, string>;
|
|
28
|
+
export { useSearchHooks, type SearchHooks } from './hooks/useSearchHooks.js';
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import virtual_social_links from "virtual-social-links";
|
|
1
2
|
export * from "react-router-dom";
|
|
3
|
+
const socialLinks = virtual_social_links;
|
|
2
4
|
export { isDataUrl, isExternalUrl, matchNavbar, matchSidebar, normalizeHref } from "@rspress/shared";
|
|
3
5
|
export { Head, useHead } from "@unhead/react";
|
|
4
6
|
export { BrowserOnly } from "./BrowserOnly.js";
|
|
@@ -7,18 +9,22 @@ export { useActiveMatcher } from "./hooks/useActiveMatcher.js";
|
|
|
7
9
|
export { ThemeContext, useDark } from "./hooks/useDark.js";
|
|
8
10
|
export { useFrontmatter } from "./hooks/useFrontmatter.js";
|
|
9
11
|
export { useI18n } from "./hooks/useI18n.js";
|
|
12
|
+
export { useI18nText } from "./hooks/useI18nText.js";
|
|
10
13
|
export { useLang } from "./hooks/useLang.js";
|
|
11
14
|
export { useLocaleSiteData } from "./hooks/useLocaleSiteData.js";
|
|
12
15
|
export { useNav } from "./hooks/useNav.js";
|
|
13
16
|
export { PageContext, usePage } from "./hooks/usePage.js";
|
|
14
17
|
export { usePageData } from "./hooks/usePageData.js";
|
|
15
|
-
export { usePages } from "./hooks/usePages.js";
|
|
18
|
+
export { searchIndexHash, usePages } from "./hooks/usePages.js";
|
|
16
19
|
export { getSidebarDataGroup, useSidebar, useSidebarDynamic } from "./hooks/useSidebar.js";
|
|
17
20
|
export { useSite } from "./hooks/useSite.js";
|
|
18
21
|
export { useVersion } from "./hooks/useVersion.js";
|
|
22
|
+
export { useWebMcp } from "./hooks/useWebMcp.js";
|
|
19
23
|
export { useWindowSize } from "./hooks/useWindowSize.js";
|
|
20
|
-
export { initPageData
|
|
24
|
+
export { initPageData } from "./initPageData.js";
|
|
21
25
|
export { NoSSR } from "./NoSSR.js";
|
|
22
26
|
export { safePreconnect, safePreload } from "./reactDom.js";
|
|
23
27
|
export { isActive, pathnameToRouteService, preloadLink } from "./route.js";
|
|
24
28
|
export { addLeadingSlash, addTrailingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase, withSiteOrigin } from "./utils.js";
|
|
29
|
+
export { useSearchHooks } from "./hooks/useSearchHooks.js";
|
|
30
|
+
export { socialLinks };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import { type PageDataLegacy } from '@rspress/shared';
|
|
2
2
|
export type Page = PageDataLegacy['page'];
|
|
3
|
-
export declare function warmPageData(routePath: string, data: Page): void;
|
|
4
|
-
export declare function consumeCachedPageData(routePath: string): Page | undefined;
|
|
5
|
-
export declare function setCurrentPageData(routePath: string, data: Page): void;
|
|
6
3
|
export declare function initPageData(routePath: string): Promise<Page>;
|
|
@@ -1,42 +1,8 @@
|
|
|
1
1
|
import { MDX_OR_MD_REGEXP, cleanUrl } from "@rspress/shared";
|
|
2
|
-
import { pageData } from "
|
|
3
|
-
import virtual_site_data from "virtual-site-data";
|
|
2
|
+
import { pageData } from "./hooks/usePages.js";
|
|
4
3
|
import { pathnameToRouteService } from "./route.js";
|
|
4
|
+
import { siteData } from "./hooks/useSite.js";
|
|
5
5
|
import { isEqualPath } from "./utils.js";
|
|
6
|
-
const slots = [
|
|
7
|
-
void 0,
|
|
8
|
-
void 0,
|
|
9
|
-
void 0
|
|
10
|
-
];
|
|
11
|
-
function warmPageData(routePath, data) {
|
|
12
|
-
slots[0] = {
|
|
13
|
-
routePath,
|
|
14
|
-
data
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function consumeCachedPageData(routePath) {
|
|
18
|
-
if (slots[0]?.routePath === routePath) {
|
|
19
|
-
const data = slots[0].data;
|
|
20
|
-
slots[2] = slots[1];
|
|
21
|
-
slots[1] = slots[0];
|
|
22
|
-
slots[0] = void 0;
|
|
23
|
-
return data;
|
|
24
|
-
}
|
|
25
|
-
if (slots[2]?.routePath === routePath) {
|
|
26
|
-
const data = slots[2].data;
|
|
27
|
-
slots[0] = slots[1];
|
|
28
|
-
slots[1] = slots[2];
|
|
29
|
-
slots[2] = void 0;
|
|
30
|
-
return data;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function setCurrentPageData(routePath, data) {
|
|
34
|
-
slots[2] = slots[1];
|
|
35
|
-
slots[1] = {
|
|
36
|
-
routePath,
|
|
37
|
-
data
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
6
|
async function initPageData(routePath) {
|
|
41
7
|
const matchedRoute = pathnameToRouteService(routePath);
|
|
42
8
|
if (matchedRoute) {
|
|
@@ -57,18 +23,16 @@ async function initPageData(routePath) {
|
|
|
57
23
|
toc
|
|
58
24
|
};
|
|
59
25
|
}
|
|
60
|
-
let lang =
|
|
61
|
-
let version =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (result) version = result;
|
|
71
|
-
}
|
|
26
|
+
let lang = siteData.lang || '';
|
|
27
|
+
let version = siteData.multiVersion?.default || '';
|
|
28
|
+
const path = routePath.replace(/^\//, '').split('/').slice(0, 2);
|
|
29
|
+
if (siteData.locales.length) {
|
|
30
|
+
const result = siteData.locales.find(({ lang })=>path.includes(lang));
|
|
31
|
+
if (result) lang = result.lang;
|
|
32
|
+
}
|
|
33
|
+
if (siteData.multiVersion.versions) {
|
|
34
|
+
const result = siteData.multiVersion.versions.find((version)=>path.includes(version));
|
|
35
|
+
if (result) version = result;
|
|
72
36
|
}
|
|
73
37
|
return {
|
|
74
38
|
pagePath: '',
|
|
@@ -83,4 +47,4 @@ async function initPageData(routePath) {
|
|
|
83
47
|
_relativePath: ''
|
|
84
48
|
};
|
|
85
49
|
}
|
|
86
|
-
export {
|
|
50
|
+
export { initPageData };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LoaderFunctionArgs } from 'react-router-dom';
|
|
2
|
+
export declare const PAGE_ROUTE_ID = "rspress-page";
|
|
3
|
+
export declare function pageDataLoader({ request }: LoaderFunctionArgs): Promise<import("@rspress/shared").BaseRuntimePageInfo & {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
headingTitle?: string;
|
|
6
|
+
pagePath: string;
|
|
7
|
+
lastUpdatedTime?: string;
|
|
8
|
+
lastUpdatedAuthor?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
pageType: import("@rspress/shared").PageType;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { initPageData } from "./initPageData.js";
|
|
2
|
+
import { removeBase } from "./utils.js";
|
|
3
|
+
const PAGE_ROUTE_ID = 'rspress-page';
|
|
4
|
+
function pageDataLoader({ request }) {
|
|
5
|
+
return initPageData(removeBase(new URL(request.url).pathname));
|
|
6
|
+
}
|
|
7
|
+
export { PAGE_ROUTE_ID, pageDataLoader };
|
package/dist/runtime/route.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cleanUrl, normalizeHref } from "@rspress/shared";
|
|
2
2
|
import { routes } from "virtual-routes";
|
|
3
|
-
import
|
|
3
|
+
import { siteData } from "./hooks/useSite.js";
|
|
4
4
|
import { removeBase, removeTrailingSlash } from "./utils.js";
|
|
5
5
|
function normalizeRoutePath(routePath) {
|
|
6
6
|
return cleanUrl(decodeURIComponent(routePath)).replace(/\.html$/, '').replace(/\/index$/, '/').toLowerCase();
|
|
@@ -45,11 +45,11 @@ function pathnameToRouteService(pathname) {
|
|
|
45
45
|
return route;
|
|
46
46
|
}
|
|
47
47
|
function redirectToCleanUrl(location, history) {
|
|
48
|
-
if (
|
|
48
|
+
if (siteData.route?.cleanUrlsRedirect === false) return false;
|
|
49
49
|
const matchedRoute = pathnameToRouteService(removeBase(location.pathname));
|
|
50
50
|
if (!matchedRoute) return false;
|
|
51
|
-
const canonicalRoutePath = normalizeHref(matchedRoute.path, Boolean(
|
|
52
|
-
const canonicalPathname = `${removeTrailingSlash(
|
|
51
|
+
const canonicalRoutePath = normalizeHref(matchedRoute.path, Boolean(siteData.route?.cleanUrls));
|
|
52
|
+
const canonicalPathname = `${removeTrailingSlash(siteData.base)}${canonicalRoutePath}`;
|
|
53
53
|
if (location.pathname === canonicalPathname) return false;
|
|
54
54
|
history.replaceState(history.state, '', `${canonicalPathname}${location.search}${location.hash}`);
|
|
55
55
|
return true;
|
|
@@ -59,7 +59,7 @@ function isActive(itemLink, currentPathname) {
|
|
|
59
59
|
return null !== linkMatched;
|
|
60
60
|
}
|
|
61
61
|
const preloadLink = (link)=>{
|
|
62
|
-
if (
|
|
62
|
+
if (siteData?.route?.prefetchLink === false) return;
|
|
63
63
|
const route = pathnameToRouteService(link);
|
|
64
64
|
if (route) route.preload();
|
|
65
65
|
};
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { removeBase } from "@rspress/core/runtime";
|
|
3
3
|
import { startTransition } from "react";
|
|
4
|
-
import { hydrateRoot } from "react-dom/client";
|
|
5
|
-
import { ClientApp } from "./ClientApp.js";
|
|
6
|
-
import { initPageData
|
|
4
|
+
import { createRoot, hydrateRoot } from "react-dom/client";
|
|
5
|
+
import { ClientApp, createClientRouter } from "./ClientApp.js";
|
|
6
|
+
import { initPageData } from "./initPageData.js";
|
|
7
7
|
import { redirectToCleanUrl } from "./route.js";
|
|
8
8
|
async function renderInBrowser() {
|
|
9
9
|
redirectToCleanUrl(window.location, window.history);
|
|
10
10
|
const container = document.getElementById('__rspress_root');
|
|
11
11
|
const pathname = removeBase(window.location.pathname);
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
let initialPageData;
|
|
13
|
+
try {
|
|
14
|
+
initialPageData = await initPageData(pathname);
|
|
15
|
+
} catch {
|
|
16
|
+
createRoot(container).render(/*#__PURE__*/ jsx(ClientApp, {
|
|
17
|
+
router: createClientRouter()
|
|
18
|
+
}));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const router = createClientRouter(initialPageData);
|
|
14
22
|
startTransition(()=>{
|
|
15
23
|
hydrateRoot(container, /*#__PURE__*/ jsx(ClientApp, {
|
|
16
|
-
|
|
24
|
+
router: router
|
|
17
25
|
}), {
|
|
18
26
|
onRecoverableError (error, errorInfo) {
|
|
19
27
|
if (error instanceof Error) console.warn('hydrateRoot recoverable error:', error, errorInfo);
|
|
@@ -1,33 +1,22 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { ThemeContext } from "@rspress/core/runtime";
|
|
3
3
|
import { UnheadProvider } from "@unhead/react/server";
|
|
4
4
|
import { renderToMarkdownString } from "react-render-to-markdown";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { initPageData } from "./initPageData.js";
|
|
5
|
+
import { StaticRouterProvider } from "virtual-react-router-server";
|
|
6
|
+
import { createServerRouter } from "./createServerRouter.js";
|
|
8
7
|
const DEFAULT_THEME = 'light';
|
|
9
|
-
async function preloadRoute(pathname) {
|
|
10
|
-
const route = pathnameToRouteService(pathname);
|
|
11
|
-
await route?.preload();
|
|
12
|
-
}
|
|
13
8
|
async function render(routePath, head) {
|
|
14
|
-
const
|
|
15
|
-
await preloadRoute(routePath);
|
|
9
|
+
const { router, context } = await createServerRouter(routePath);
|
|
16
10
|
const appMd = await renderToMarkdownString(/*#__PURE__*/ jsx(ThemeContext.Provider, {
|
|
17
11
|
value: {
|
|
18
12
|
theme: DEFAULT_THEME
|
|
19
13
|
},
|
|
20
|
-
children: /*#__PURE__*/ jsx(
|
|
21
|
-
value:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
basename: removeTrailingSlash(withBase('/')),
|
|
27
|
-
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
28
|
-
value: head,
|
|
29
|
-
children: /*#__PURE__*/ jsx(App, {})
|
|
30
|
-
})
|
|
14
|
+
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
15
|
+
value: head,
|
|
16
|
+
children: /*#__PURE__*/ jsx(StaticRouterProvider, {
|
|
17
|
+
router: router,
|
|
18
|
+
context: context,
|
|
19
|
+
hydrate: false
|
|
31
20
|
})
|
|
32
21
|
})
|
|
33
22
|
}));
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { PassThrough } from "node:stream";
|
|
3
3
|
import { text as consumers_text } from "node:stream/consumers";
|
|
4
|
-
import {
|
|
4
|
+
import { ThemeContext } from "@rspress/core/runtime";
|
|
5
5
|
import { UnheadProvider } from "@unhead/react/server";
|
|
6
6
|
import { renderToPipeableStream } from "react-dom/server";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { initPageData } from "./initPageData.js";
|
|
7
|
+
import { StaticRouterProvider } from "virtual-react-router-server";
|
|
8
|
+
import { createServerRouter } from "./createServerRouter.js";
|
|
10
9
|
const DEFAULT_THEME = 'light';
|
|
11
|
-
async function preloadRoute(pathname) {
|
|
12
|
-
const route = pathnameToRouteService(pathname);
|
|
13
|
-
await route?.preload();
|
|
14
|
-
}
|
|
15
10
|
function renderToHtml(app) {
|
|
16
11
|
return new Promise((resolve, reject)=>{
|
|
17
12
|
const passThrough = new PassThrough();
|
|
@@ -28,23 +23,17 @@ function renderToHtml(app) {
|
|
|
28
23
|
});
|
|
29
24
|
}
|
|
30
25
|
async function render(routePath, head) {
|
|
31
|
-
const
|
|
32
|
-
await preloadRoute(routePath);
|
|
26
|
+
const { router, context } = await createServerRouter(routePath);
|
|
33
27
|
const appHtml = await renderToHtml(/*#__PURE__*/ jsx(ThemeContext.Provider, {
|
|
34
28
|
value: {
|
|
35
29
|
theme: DEFAULT_THEME
|
|
36
30
|
},
|
|
37
|
-
children: /*#__PURE__*/ jsx(
|
|
38
|
-
value:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
basename: removeTrailingSlash(withBase('/')),
|
|
44
|
-
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
45
|
-
value: head,
|
|
46
|
-
children: /*#__PURE__*/ jsx(App, {})
|
|
47
|
-
})
|
|
31
|
+
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
32
|
+
value: head,
|
|
33
|
+
children: /*#__PURE__*/ jsx(StaticRouterProvider, {
|
|
34
|
+
router: router,
|
|
35
|
+
context: context,
|
|
36
|
+
hydrate: false
|
|
48
37
|
})
|
|
49
38
|
})
|
|
50
39
|
}));
|
package/dist/runtime/utils.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { addLeadingSlash, addTrailingSlash, isDataUrl, isExternalUrl, isProduction, normalizeHref, removeBase, removeHash, removeTrailingSlash, withBase, withSiteOrigin } from "@rspress/shared";
|
|
2
|
-
import
|
|
2
|
+
import { siteData } from "./hooks/useSite.js";
|
|
3
3
|
function utils_withBase(url = '/') {
|
|
4
|
-
return withBase(url,
|
|
4
|
+
return withBase(url, siteData.base);
|
|
5
5
|
}
|
|
6
6
|
function utils_withSiteOrigin(url) {
|
|
7
|
-
return withSiteOrigin(url,
|
|
7
|
+
return withSiteOrigin(url, siteData.siteOrigin);
|
|
8
8
|
}
|
|
9
9
|
function utils_removeBase(url) {
|
|
10
|
-
return removeBase(url,
|
|
10
|
+
return removeBase(url, siteData.base);
|
|
11
11
|
}
|
|
12
12
|
function isEqualPath(a, b) {
|
|
13
13
|
return utils_removeBase(normalizeHref(removeHash(a), true)) === utils_removeBase(normalizeHref(removeHash(b), true));
|
|
14
14
|
}
|
|
15
15
|
function normalizeHrefInRuntime(link) {
|
|
16
|
-
const cleanUrls = Boolean(
|
|
16
|
+
const cleanUrls = Boolean(siteData?.route?.cleanUrls);
|
|
17
17
|
return normalizeHref(link, cleanUrls);
|
|
18
18
|
}
|
|
19
19
|
function cleanUrlByConfig(link) {
|
|
20
|
-
if (
|
|
20
|
+
if (siteData?.route?.cleanUrls) return normalizeHref(link, true);
|
|
21
21
|
return link;
|
|
22
22
|
}
|
|
23
23
|
function normalizeImagePath(imagePath) {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tinypool",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "2.2.0",
|
|
5
|
+
"description": "A minimal and tiny Node.js Worker Thread Pool implementation, a fork of piscina, but with fewer features",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/tinylibs/tinypool#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/tinylibs/tinypool.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/tinylibs/tinypool/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"fast",
|
|
17
|
+
"worker threads",
|
|
18
|
+
"thread pool"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": "^20.0.0 || >=22.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^20.12.8",
|
|
38
|
+
"clean-publish": "^3.4.4",
|
|
39
|
+
"eslint": "^9.4.0",
|
|
40
|
+
"eslint-config-prettier": "^9.1.0",
|
|
41
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
42
|
+
"eslint-plugin-unicorn": "^53.0.0",
|
|
43
|
+
"prettier": "^3.3.2",
|
|
44
|
+
"tsdown": "^0.11.3",
|
|
45
|
+
"typescript": "^5.4.5",
|
|
46
|
+
"typescript-eslint": "^7.13.0",
|
|
47
|
+
"vite": "^5.2.11",
|
|
48
|
+
"vitest": "^4.0.1"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"test": "vitest",
|
|
52
|
+
"bench": "vitest bench",
|
|
53
|
+
"dev": "tsdown --watch ./src",
|
|
54
|
+
"build": "tsdown",
|
|
55
|
+
"lint": "eslint --max-warnings=0",
|
|
56
|
+
"typecheck": "tsc --noEmit"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { preloadLink } from "@rspress/core/runtime";
|
|
3
3
|
import clsx from "clsx";
|
|
4
|
-
import nprogress from "nprogress";
|
|
5
4
|
import { forwardRef } from "react";
|
|
6
5
|
import "./index.css";
|
|
7
6
|
import { getHref } from "./getHref.js";
|
|
8
7
|
import { useLinkNavigate } from "./useLinkNavigate.js";
|
|
9
|
-
nprogress.configure({
|
|
10
|
-
showSpinner: false
|
|
11
|
-
});
|
|
12
8
|
const Link = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
13
9
|
const { href = '/', children, className = '', onClick, onMouseEnter, startTransition, ...otherProps } = props;
|
|
14
10
|
const { linkType, removeBaseHref, routePath, withBaseHref } = getHref(href);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type TransitionStartFunction } from 'react';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Navigate with Rspress link normalization. The router loader handles page
|
|
4
|
+
* loading for both this helper and the native useNavigate hook.
|
|
5
5
|
*/
|
|
6
6
|
export declare function useLinkNavigate({ startTransition, }?: {
|
|
7
7
|
startTransition?: TransitionStartFunction;
|