@rspress/core 2.0.15 → 2.0.17
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 +6 -1
- package/dist/0~execa.js +1 -1
- package/dist/{9882.js → 102.js} +1 -1
- package/dist/{9958.js → 7448.js} +1 -1
- package/dist/{5580.js → 8629.js} +2455 -6
- package/dist/cli/index.d.ts +8 -1
- package/dist/cli/index.js +105 -102
- package/dist/config/loadConfigFile.js +1 -1
- package/dist/eject-theme/components/Callout/index.scss +32 -0
- package/dist/eject-theme/components/Callout/index.tsx +9 -1
- package/dist/eject-theme/components/Link/index.tsx +1 -1
- package/dist/eject-theme/components/Link/useLinkNavigate.ts +17 -4
- package/dist/eject-theme/components/Llms/LlmsContainer.tsx +1 -1
- package/dist/eject-theme/components/Overview/index.tsx +1 -2
- package/dist/eject-theme/components/Overview/utils.ts +4 -10
- package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +3 -1
- package/dist/eject-theme/components/SidebarMenu/useClickOutside.ts +1 -2
- package/dist/eject-theme/components/SocialLinks/GithubStars.test.tsx +48 -0
- package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +35 -20
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/node/PluginDriver.js +1 -1
- 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 +2 -2
- 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 +2 -2
- package/dist/node/initRsbuild.js +5 -5
- package/dist/node/logger/hint.js +1 -1
- package/dist/node/mdx/options.js +1 -1
- package/dist/node/mdx/processor.js +1 -1
- package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
- package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
- package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
- package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
- package/dist/node/mdx/remarkPlugins/containerSyntax.d.ts +2 -1
- package/dist/node/mdx/remarkPlugins/containerSyntax.js +13 -6
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +2 -2
- package/dist/node/mdx/remarkPlugins/image.js +2 -2
- package/dist/node/mdx/remarkPlugins/link.js +2 -2
- package/dist/node/mdx/remarkPlugins/toc.js +1 -1
- package/dist/node/medium-zoom/index.js +1 -1
- 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/i18n.js +3 -3
- package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
- package/dist/node/runtimeModule/searchHooks.js +1 -1
- package/dist/node/runtimeModule/siteData/createSiteData.js +6 -2
- 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/ssg/htmlFile.js +1 -1
- package/dist/node/ssg/renderPage.js +2 -2
- package/dist/node/ssg/renderPageWorker.js +2 -2
- package/dist/node/ssg/renderPages.js +3 -3
- package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
- package/dist/node/ssg/ssgEnv.js +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +3 -3
- package/dist/node/ssg-md/llms/llmsTxt.d.ts +3 -3
- package/dist/node/ssg-md/llms/llmsTxt.js +8 -8
- package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
- package/dist/node/ssg-md/renderPage.js +2 -2
- package/dist/node/ssg-md/renderPages.js +3 -3
- 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/error.js +1 -1
- package/dist/node/utils/flattenMdxContent.js +1 -1
- package/dist/node/utils/fs.js +1 -1
- package/dist/node/utils/getPageKey.js +1 -1
- package/dist/node/utils/normalizePath.js +1 -1
- package/dist/node/utils/reactAlias.js +2 -2
- package/dist/runtime/App.js +1 -1
- package/dist/runtime/ClientApp.js +4 -2
- package/dist/runtime/route.js +2 -0
- package/dist/theme/components/Callout/index.css +29 -0
- package/dist/theme/components/Callout/index.d.ts +1 -1
- package/dist/theme/components/DocContent/docComponents/index.d.ts +25 -18
- package/dist/theme/components/Link/index.d.ts +1 -1
- package/dist/theme/components/Link/useLinkNavigate.d.ts +1 -1
- package/dist/theme/components/Link/useLinkNavigate.js +13 -5
- package/dist/theme/components/Llms/LlmsContainer.d.ts +1 -2
- package/dist/theme/components/Search/SearchPanel.js +8 -8
- package/dist/theme/components/SocialLinks/GithubStars.js +27 -17
- package/dist/theme/logic/getCopyableText.js +1 -0
- package/package.json +12 -12
- package/dist/6010.js +0 -2461
- package/dist/{0~8787.js → 0~8016.js} +0 -0
- package/dist/{7986.js → 4538.js} +0 -0
- package/dist/{3358.js → 5357.js} +0 -0
- package/dist/{8005.js → 7748.js} +2 -2
- /package/dist/{5580.js.LICENSE.txt → 8629.js.LICENSE.txt} +0 -0
- /package/dist/{6646.js → 9857.js} +0 -0
- /package/dist/{9283.js → 9940.js} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __webpack_require__ } from "../../0~rslib-runtime.js";
|
|
2
|
-
import "../../
|
|
3
|
-
import { node_path, core_rspack, logger } from "../../
|
|
2
|
+
import "../../4538.js";
|
|
3
|
+
import { node_path, core_rspack, logger } from "../../8629.js";
|
|
4
4
|
import { pathExists, readJson } from "./fs.js";
|
|
5
5
|
import { PACKAGE_ROOT } from "../constants.js";
|
|
6
6
|
import { hintReactVersion } from "../logger/hint.js";
|
package/dist/runtime/App.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { PageContext, useLocation } from "@rspress/core/runtime";
|
|
3
|
-
import { Layout, Root } from "@theme";
|
|
3
|
+
import { Layout, Root } from "@rspress/core/theme";
|
|
4
4
|
import react, { useContext, useLayoutEffect } from "react";
|
|
5
5
|
import virtual_global_components from "virtual-global-components";
|
|
6
6
|
import { consumeCachedPageData, initPageData, setCurrentPageData } from "./initPageData.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { BrowserRouter, PageContext, ThemeContext, removeTrailingSlash, withBase } from "@rspress/core/runtime";
|
|
3
|
-
import { useThemeState } from "@theme";
|
|
2
|
+
import { BrowserRouter, PageContext, ThemeContext, removeTrailingSlash, useSite, withBase } from "@rspress/core/runtime";
|
|
3
|
+
import { useThemeState } from "@rspress/core/theme";
|
|
4
4
|
import { UnheadProvider, createHead } from "@unhead/react/client";
|
|
5
5
|
import { useMemo, useState } from "react";
|
|
6
6
|
import { App } from "./App.js";
|
|
@@ -8,6 +8,7 @@ const head = createHead();
|
|
|
8
8
|
function ClientApp({ initialPageData = null }) {
|
|
9
9
|
const [data, setData] = useState(initialPageData);
|
|
10
10
|
const [theme, setTheme] = useThemeState();
|
|
11
|
+
const { site } = useSite();
|
|
11
12
|
return /*#__PURE__*/ jsx(ThemeContext.Provider, {
|
|
12
13
|
value: useMemo(()=>({
|
|
13
14
|
theme,
|
|
@@ -26,6 +27,7 @@ function ClientApp({ initialPageData = null }) {
|
|
|
26
27
|
]),
|
|
27
28
|
children: /*#__PURE__*/ jsx(BrowserRouter, {
|
|
28
29
|
basename: removeTrailingSlash(withBase('/')),
|
|
30
|
+
useTransitions: site.route.useTransitions,
|
|
29
31
|
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
30
32
|
head: head,
|
|
31
33
|
children: /*#__PURE__*/ jsx(App, {})
|
package/dist/runtime/route.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { cleanUrl } from "@rspress/shared";
|
|
2
2
|
import { routes } from "virtual-routes";
|
|
3
|
+
import virtual_site_data from "virtual-site-data";
|
|
3
4
|
function normalizeRoutePath(routePath) {
|
|
4
5
|
return cleanUrl(decodeURIComponent(routePath)).replace(/\.html$/, '').replace(/\/index$/, '/').toLowerCase();
|
|
5
6
|
}
|
|
@@ -47,6 +48,7 @@ function isActive(itemLink, currentPathname) {
|
|
|
47
48
|
return null !== linkMatched;
|
|
48
49
|
}
|
|
49
50
|
const preloadLink = (link)=>{
|
|
51
|
+
if (virtual_site_data?.route?.prefetchLink === false) return;
|
|
50
52
|
const route = pathnameToRouteService(link);
|
|
51
53
|
if (route) route.preload();
|
|
52
54
|
};
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
--rp-container-info-text: #07f;
|
|
13
13
|
--rp-container-info-bg: #0095ff0f;
|
|
14
14
|
--rp-container-info-code-bg: #0095ff1a;
|
|
15
|
+
--rp-container-important-border: #8957e54d;
|
|
16
|
+
--rp-container-important-text: #8250df;
|
|
17
|
+
--rp-container-important-bg: #8957e514;
|
|
18
|
+
--rp-container-important-code-bg: #8957e51a;
|
|
15
19
|
--rp-container-warning-border: #ffc51766;
|
|
16
20
|
--rp-container-warning-text: #887233;
|
|
17
21
|
--rp-container-warning-bg: #ffc5171a;
|
|
@@ -33,6 +37,9 @@
|
|
|
33
37
|
--rp-container-tip-bg: #079c701a;
|
|
34
38
|
--rp-container-info-text: #66c2ff;
|
|
35
39
|
--rp-container-info-bg: #0095ff1a;
|
|
40
|
+
--rp-container-important-text: #b083f0;
|
|
41
|
+
--rp-container-important-border: #8957e559;
|
|
42
|
+
--rp-container-important-bg: #8957e51f;
|
|
36
43
|
--rp-container-warning-text: #fbb451;
|
|
37
44
|
--rp-container-warning-border: #ffc51740;
|
|
38
45
|
--rp-container-warning-bg: #ffc5171f;
|
|
@@ -152,6 +159,28 @@
|
|
|
152
159
|
color: var(--rp-container-info-text);
|
|
153
160
|
}
|
|
154
161
|
|
|
162
|
+
.rp-callout--important {
|
|
163
|
+
border-color: var(--rp-container-important-border);
|
|
164
|
+
background-color: var(--rp-container-important-bg);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.rp-callout--important .rp-callout__title {
|
|
168
|
+
color: var(--rp-container-important-text);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.rp-callout--important .rp-callout__title:before {
|
|
172
|
+
background-color: var(--rp-container-important-text);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.rp-callout--important :not(pre) > code {
|
|
176
|
+
color: var(--rp-container-important-text);
|
|
177
|
+
background-color: var(--rp-container-important-code-bg);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.rp-callout--important a {
|
|
181
|
+
color: var(--rp-container-important-text);
|
|
182
|
+
}
|
|
183
|
+
|
|
155
184
|
.rp-callout--warning {
|
|
156
185
|
border-color: var(--rp-container-warning-border);
|
|
157
186
|
background-color: var(--rp-container-warning-bg);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import './index.scss';
|
|
3
3
|
export interface CalloutProps {
|
|
4
|
-
type: 'tip' | 'note' | 'warning' | 'caution' | 'danger' | 'info' | 'details';
|
|
4
|
+
type: 'tip' | 'note' | 'important' | 'warning' | 'caution' | 'danger' | 'info' | 'details';
|
|
5
5
|
title?: string;
|
|
6
6
|
children: ReactNode;
|
|
7
7
|
}
|
|
@@ -1,25 +1,32 @@
|
|
|
1
|
+
import { A } from './a.js';
|
|
1
2
|
import { Code } from './code.js';
|
|
3
|
+
import { Hr } from './hr.js';
|
|
4
|
+
import { Img } from './img.js';
|
|
5
|
+
import { Li, Ol, Ul } from './list.js';
|
|
6
|
+
import { Blockquote, P, Strong } from './paragraph.js';
|
|
2
7
|
import { ShikiPre } from './pre.js';
|
|
8
|
+
import { Td, Th, Tr } from './table.js';
|
|
9
|
+
import { H1, H2, H3, H4, H5, H6 } from './title.js';
|
|
3
10
|
export declare function getCustomMDXComponent(): {
|
|
4
|
-
h1:
|
|
5
|
-
h2:
|
|
6
|
-
h3:
|
|
7
|
-
h4:
|
|
8
|
-
h5:
|
|
9
|
-
h6:
|
|
10
|
-
ul:
|
|
11
|
-
ol:
|
|
12
|
-
li:
|
|
11
|
+
h1: typeof H1;
|
|
12
|
+
h2: typeof H2;
|
|
13
|
+
h3: typeof H3;
|
|
14
|
+
h4: typeof H4;
|
|
15
|
+
h5: typeof H5;
|
|
16
|
+
h6: typeof H6;
|
|
17
|
+
ul: typeof Ul;
|
|
18
|
+
ol: typeof Ol;
|
|
19
|
+
li: typeof Li;
|
|
13
20
|
table: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").TableHTMLAttributes<HTMLTableElement>, HTMLTableElement>, "ref"> & import("react").RefAttributes<HTMLTableElement>>;
|
|
14
|
-
td:
|
|
15
|
-
th:
|
|
16
|
-
tr:
|
|
17
|
-
hr:
|
|
18
|
-
p:
|
|
19
|
-
blockquote:
|
|
20
|
-
strong:
|
|
21
|
-
a:
|
|
21
|
+
td: typeof Td;
|
|
22
|
+
th: typeof Th;
|
|
23
|
+
tr: typeof Tr;
|
|
24
|
+
hr: typeof Hr;
|
|
25
|
+
p: typeof P;
|
|
26
|
+
blockquote: typeof Blockquote;
|
|
27
|
+
strong: typeof Strong;
|
|
28
|
+
a: typeof A;
|
|
22
29
|
code: typeof Code;
|
|
23
|
-
img:
|
|
30
|
+
img: typeof Img;
|
|
24
31
|
pre: typeof ShikiPre;
|
|
25
32
|
};
|
|
@@ -29,7 +29,7 @@ export interface LinkProps extends ComponentProps<'a'> {
|
|
|
29
29
|
* Link can tell whether it's in current site or external site.
|
|
30
30
|
* 1. If external, open a new page and navigate to it.
|
|
31
31
|
* 2. If inCurrentPage, scroll to anchor.
|
|
32
|
-
* 3. If inCurrentSite, it will navigate and scroll to anchor,
|
|
32
|
+
* 3. If inCurrentSite, it will navigate and scroll to anchor, prefetch route resources when hovering over the link.
|
|
33
33
|
* 4. Link is styled.
|
|
34
34
|
*/
|
|
35
35
|
export declare const Link: React.ForwardRefExoticComponent<Omit<LinkProps, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
@@ -9,7 +9,7 @@ export declare function getHref(href: string): {
|
|
|
9
9
|
* For import { Link } from '@rspress/core/theme';
|
|
10
10
|
* useNavigate with preload logic
|
|
11
11
|
*/
|
|
12
|
-
export declare function useLinkNavigate({ startTransition }?: {
|
|
12
|
+
export declare function useLinkNavigate({ startTransition, }?: {
|
|
13
13
|
startTransition?: TransitionStartFunction;
|
|
14
14
|
}): (href: string) => Promise<void>;
|
|
15
15
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cleanUrlByConfig, initPageData, isActive, isExternalUrl, pathnameToRouteService, removeBase, useLocation, useNavigate, warmPageData, withBase } from "@rspress/core/runtime";
|
|
1
|
+
import { cleanUrlByConfig, initPageData, isActive, isExternalUrl, pathnameToRouteService, removeBase, useLocation, useNavigate, useSite, warmPageData, withBase } from "@rspress/core/runtime";
|
|
2
2
|
import nprogress from "nprogress";
|
|
3
3
|
import { startTransition as external_react_startTransition, useCallback } from "react";
|
|
4
4
|
nprogress.configure({
|
|
@@ -29,14 +29,17 @@ function getHref(href) {
|
|
|
29
29
|
linkType
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
function useLinkNavigate({ startTransition } = {
|
|
32
|
+
function useLinkNavigate({ startTransition = external_react_startTransition } = {
|
|
33
33
|
startTransition: external_react_startTransition
|
|
34
34
|
}) {
|
|
35
35
|
const { pathname: currPagePathname } = useLocation();
|
|
36
36
|
const navigate = useNavigate();
|
|
37
|
+
const { site } = useSite();
|
|
38
|
+
const useTransitions = site?.route?.useTransitions;
|
|
37
39
|
return useCallback(async (href)=>{
|
|
38
40
|
const { linkType, removeBaseHref, withBaseHref } = getHref(href);
|
|
39
41
|
if ('external' === linkType || 'hashOnly' === linkType) return void window.location.assign(href);
|
|
42
|
+
const isTransitionable = !!(useTransitions && startTransition);
|
|
40
43
|
const preloadChunkThenNavigate = async ()=>{
|
|
41
44
|
const inCurrPage = isActive(removeBaseHref, currPagePathname);
|
|
42
45
|
if (!import.meta.env.SSR && !inCurrPage) {
|
|
@@ -52,15 +55,20 @@ function useLinkNavigate({ startTransition } = {
|
|
|
52
55
|
nprogress.done();
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
|
-
navigate(removeBaseHref, {
|
|
58
|
+
if (isTransitionable) startTransition(()=>navigate(removeBaseHref, {
|
|
59
|
+
replace: false
|
|
60
|
+
}));
|
|
61
|
+
else navigate(removeBaseHref, {
|
|
56
62
|
replace: false
|
|
57
63
|
});
|
|
58
64
|
};
|
|
59
|
-
if (
|
|
65
|
+
if (isTransitionable) startTransition(preloadChunkThenNavigate);
|
|
60
66
|
else preloadChunkThenNavigate();
|
|
61
67
|
}, [
|
|
68
|
+
useTransitions,
|
|
62
69
|
currPagePathname,
|
|
63
|
-
navigate
|
|
70
|
+
navigate,
|
|
71
|
+
startTransition
|
|
64
72
|
]);
|
|
65
73
|
}
|
|
66
74
|
export { getHref, useLinkNavigate };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import './LlmsContainer.scss';
|
|
3
|
-
export
|
|
4
|
-
}
|
|
3
|
+
export type LlmsContainerProps = React.HTMLAttributes<HTMLDivElement>;
|
|
5
4
|
export declare function LlmsContainer(props: LlmsContainerProps): React.JSX.Element;
|
|
@@ -4,7 +4,7 @@ import { IconClose, IconLoading, IconSearch, SvgWrapper, Tab, Tabs, useLinkNavig
|
|
|
4
4
|
import { debounce } from "@rspress/shared/lodash-es";
|
|
5
5
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
6
6
|
import { createPortal } from "react-dom";
|
|
7
|
-
import * as
|
|
7
|
+
import * as __rspack_external_virtual_search_hooks_705b6e40 from "virtual-search-hooks";
|
|
8
8
|
import { PageSearcher } from "./logic/search.js";
|
|
9
9
|
import { RenderType } from "./logic/types.js";
|
|
10
10
|
import { NoSearchResult } from "./NoSearchResult.js";
|
|
@@ -204,24 +204,24 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
204
204
|
setQuery(newQuery);
|
|
205
205
|
if (newQuery) {
|
|
206
206
|
const searchResult = [];
|
|
207
|
-
if ("beforeSearch" in
|
|
207
|
+
if ("beforeSearch" in __rspack_external_virtual_search_hooks_705b6e40) {
|
|
208
208
|
const key = 'beforeSearch';
|
|
209
|
-
const transformedQuery = await
|
|
209
|
+
const transformedQuery = await __rspack_external_virtual_search_hooks_705b6e40[key](newQuery);
|
|
210
210
|
if (transformedQuery) newQuery = transformedQuery;
|
|
211
211
|
}
|
|
212
212
|
const defaultSearchResult = await pageSearcherRef.current?.match(newQuery);
|
|
213
213
|
if (defaultSearchResult) searchResult.push(...defaultSearchResult);
|
|
214
|
-
if ("onSearch" in
|
|
214
|
+
if ("onSearch" in __rspack_external_virtual_search_hooks_705b6e40) {
|
|
215
215
|
const key = 'onSearch';
|
|
216
|
-
const customSearchResult = await
|
|
216
|
+
const customSearchResult = await __rspack_external_virtual_search_hooks_705b6e40[key](newQuery, searchResult);
|
|
217
217
|
if (customSearchResult) searchResult.push(...customSearchResult.map((item)=>({
|
|
218
218
|
renderType: RenderType.Custom,
|
|
219
219
|
...item
|
|
220
220
|
})));
|
|
221
221
|
}
|
|
222
|
-
if ("afterSearch" in
|
|
222
|
+
if ("afterSearch" in __rspack_external_virtual_search_hooks_705b6e40) {
|
|
223
223
|
const key = 'afterSearch';
|
|
224
|
-
await
|
|
224
|
+
await __rspack_external_virtual_search_hooks_705b6e40[key](newQuery, searchResult);
|
|
225
225
|
}
|
|
226
226
|
const currQuery = searchInputRef.current?.value;
|
|
227
227
|
if (currQuery === newQuery) {
|
|
@@ -256,7 +256,7 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
256
256
|
label: item.group,
|
|
257
257
|
children: [
|
|
258
258
|
item.renderType === RenderType.Default && renderSearchResultItem(item.result, query, isSearching),
|
|
259
|
-
item.renderType === RenderType.Custom &&
|
|
259
|
+
item.renderType === RenderType.Custom && __rspack_external_virtual_search_hooks_705b6e40[renderKey](item.result)
|
|
260
260
|
]
|
|
261
261
|
}, item.group))
|
|
262
262
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
|
+
import { useStorageValue } from "../../logic/useStorageValue.js";
|
|
3
4
|
const TTL_MS = 3600000;
|
|
4
5
|
function storageKey(repo) {
|
|
5
6
|
return `rp-github-stars:${repo}`;
|
|
@@ -16,10 +17,8 @@ function parseRepo(content) {
|
|
|
16
17
|
return null;
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
-
if ("u" < typeof localStorage) return null;
|
|
20
|
+
function parseCache(raw) {
|
|
21
21
|
try {
|
|
22
|
-
const raw = localStorage.getItem(storageKey(repo));
|
|
23
22
|
if (!raw) return null;
|
|
24
23
|
const parsed = JSON.parse(raw);
|
|
25
24
|
if ('number' != typeof parsed?.count || 'number' != typeof parsed?.fetchedAt) return null;
|
|
@@ -28,14 +27,11 @@ function readCache(repo) {
|
|
|
28
27
|
return null;
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
fetchedAt: Date.now()
|
|
37
|
-
}));
|
|
38
|
-
} catch {}
|
|
30
|
+
function createCacheValue(count) {
|
|
31
|
+
return JSON.stringify({
|
|
32
|
+
count,
|
|
33
|
+
fetchedAt: Date.now()
|
|
34
|
+
});
|
|
39
35
|
}
|
|
40
36
|
function formatCount(count) {
|
|
41
37
|
if (count >= 1000000) return `${(count / 1000000).toFixed(1)}M`;
|
|
@@ -45,24 +41,38 @@ function formatCount(count) {
|
|
|
45
41
|
const GithubStars = (props)=>{
|
|
46
42
|
const { content, icon } = props;
|
|
47
43
|
const repo = parseRepo(content);
|
|
48
|
-
const [
|
|
44
|
+
const [rawCache, setRawCache] = useStorageValue(repo ? storageKey(repo) : '', null);
|
|
45
|
+
const [isMounted, setIsMounted] = useState(false);
|
|
46
|
+
const [count, setCount] = useState(null);
|
|
47
|
+
useEffect(()=>{
|
|
48
|
+
setIsMounted(true);
|
|
49
|
+
}, []);
|
|
49
50
|
useEffect(()=>{
|
|
50
|
-
if (!repo) return;
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
if (!repo) return void setCount(null);
|
|
52
|
+
if (!isMounted) return;
|
|
53
|
+
const cached = parseCache(rawCache);
|
|
54
|
+
if (cached) {
|
|
55
|
+
setCount(cached.count);
|
|
56
|
+
if (Date.now() - cached.fetchedAt < TTL_MS) return;
|
|
57
|
+
} else setCount(null);
|
|
53
58
|
let cancelled = false;
|
|
54
59
|
fetch(`https://api.github.com/repos/${repo}`).then((res)=>res.ok ? res.json() : Promise.reject(res.status)).then((data)=>{
|
|
55
60
|
if (cancelled) return;
|
|
56
61
|
if ('number' == typeof data?.stargazers_count) {
|
|
57
62
|
setCount(data.stargazers_count);
|
|
58
|
-
|
|
63
|
+
try {
|
|
64
|
+
setRawCache(createCacheValue(data.stargazers_count));
|
|
65
|
+
} catch {}
|
|
59
66
|
}
|
|
60
67
|
}).catch(()=>{});
|
|
61
68
|
return ()=>{
|
|
62
69
|
cancelled = true;
|
|
63
70
|
};
|
|
64
71
|
}, [
|
|
65
|
-
|
|
72
|
+
isMounted,
|
|
73
|
+
rawCache,
|
|
74
|
+
repo,
|
|
75
|
+
setRawCache
|
|
66
76
|
]);
|
|
67
77
|
return /*#__PURE__*/ jsxs("a", {
|
|
68
78
|
href: content,
|
|
@@ -32,6 +32,7 @@ function getBlockElement(element, rootElement) {
|
|
|
32
32
|
function toMarkdown(node, state) {
|
|
33
33
|
if (node.nodeType !== Node.ELEMENT_NODE) return '';
|
|
34
34
|
const element = node;
|
|
35
|
+
if (element.closest('pre') || element.closest('code')) return '';
|
|
35
36
|
const listItem = element.closest('li');
|
|
36
37
|
if (listItem && !state.seenNodes.has(listItem)) {
|
|
37
38
|
state.seenNodes.add(listItem);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.17",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@mdx-js/mdx": "^3.1.1",
|
|
62
62
|
"@mdx-js/react": "^3.1.1",
|
|
63
|
-
"@rsbuild/core": "^2.
|
|
64
|
-
"@rsbuild/plugin-react": "~2.0
|
|
63
|
+
"@rsbuild/core": "^2.1.5",
|
|
64
|
+
"@rsbuild/plugin-react": "~2.1.0",
|
|
65
65
|
"@shikijs/rehype": "^4.2.0",
|
|
66
66
|
"@types/unist": "^3.0.3",
|
|
67
67
|
"@unhead/react": "^2.1.15",
|
|
@@ -80,11 +80,11 @@
|
|
|
80
80
|
"react-lazy-with-preload": "^2.2.1",
|
|
81
81
|
"react-reconciler": "0.33.0",
|
|
82
82
|
"react-render-to-markdown": "19.1.0",
|
|
83
|
-
"react-router-dom": "^7.
|
|
83
|
+
"react-router-dom": "^7.18.1",
|
|
84
84
|
"rehype-external-links": "^3.0.0",
|
|
85
85
|
"rehype-raw": "^7.0.0",
|
|
86
86
|
"remark-cjk-friendly": "^2.3.1",
|
|
87
|
-
"remark-cjk-friendly-gfm-strikethrough": "^2.1
|
|
87
|
+
"remark-cjk-friendly-gfm-strikethrough": "^2.3.1",
|
|
88
88
|
"remark-gfm": "^4.0.1",
|
|
89
89
|
"remark-mdx": "^3.1.1",
|
|
90
90
|
"remark-parse": "^11.0.0",
|
|
@@ -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.
|
|
98
|
+
"@rspress/shared": "2.0.17"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@microsoft/api-extractor": "^7.58.9",
|
|
102
102
|
"@rsbuild/plugin-sass": "~1.5.3",
|
|
103
|
-
"@rsbuild/plugin-svgr": "^2.0.
|
|
104
|
-
"@rslib/core": "0.23.
|
|
103
|
+
"@rsbuild/plugin-svgr": "^2.0.5",
|
|
104
|
+
"@rslib/core": "0.23.2",
|
|
105
105
|
"@types/body-scroll-lock": "^3.1.2",
|
|
106
106
|
"@types/hast": "^3.0.4",
|
|
107
107
|
"@types/mdast": "^4.0.4",
|
|
@@ -110,19 +110,19 @@
|
|
|
110
110
|
"@types/react": "^19.2.17",
|
|
111
111
|
"@types/react-dom": "^19.2.3",
|
|
112
112
|
"@types/react-reconciler": "^0.33.0",
|
|
113
|
-
"@types/web": "^0.0.
|
|
113
|
+
"@types/web": "^0.0.352",
|
|
114
114
|
"cac": "^7.0.0",
|
|
115
115
|
"chokidar": "^3.6.0",
|
|
116
116
|
"execa": "8.0.1",
|
|
117
117
|
"mdast-util-directive": "^3.1.0",
|
|
118
118
|
"mdast-util-mdx-expression": "^2.0.1",
|
|
119
119
|
"memfs": "^4.57.8",
|
|
120
|
-
"p-map": "^7.0.
|
|
120
|
+
"p-map": "^7.0.5",
|
|
121
121
|
"picocolors": "^1.1.1",
|
|
122
|
-
"postcss": "8.5.
|
|
122
|
+
"postcss": "8.5.16",
|
|
123
123
|
"remark-directive": "^4.0.0",
|
|
124
124
|
"rsbuild-plugin-publint": "^1.0.0",
|
|
125
|
-
"rsbuild-plugin-virtual-module": "0.4.
|
|
125
|
+
"rsbuild-plugin-virtual-module": "0.4.5",
|
|
126
126
|
"tinyglobby": "^0.2.17",
|
|
127
127
|
"tinypool": "^1.1.1",
|
|
128
128
|
"ts-json-schema-generator": "^2.9.0",
|