@rspress/core 2.0.23 → 2.1.0-beta.2
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/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/CdnTabs/index.test.tsx +71 -0
- package/dist/eject-theme/components/CdnTabs/index.tsx +175 -0
- package/dist/eject-theme/components/DocContent/index.tsx +0 -3
- package/dist/eject-theme/components/FallbackHeading/index.tsx +6 -1
- package/dist/eject-theme/components/Link/getHref.ts +1 -0
- package/dist/eject-theme/components/Link/index.tsx +9 -21
- package/dist/eject-theme/components/Link/useLinkNavigate.ts +43 -54
- package/dist/eject-theme/components/NavTitle/index.test.tsx +78 -0
- package/dist/eject-theme/components/NavTitle/index.tsx +9 -5
- package/dist/eject-theme/components/PackageManagerTabs/index.test.tsx +79 -1
- package/dist/eject-theme/components/PackageManagerTabs/index.tsx +25 -12
- package/dist/eject-theme/components/Search/NoSearchResult.scss +1 -2
- package/dist/eject-theme/components/Search/SearchPanel.scss +75 -63
- package/dist/eject-theme/components/Search/SuggestItem.scss +28 -41
- package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +4 -1
- package/dist/eject-theme/components/Search/useSearchPanel.ts +103 -36
- package/dist/eject-theme/components/Sidebar/SidebarItem.scss +8 -0
- package/dist/eject-theme/components/Sidebar/SidebarSectionHeader.scss +3 -0
- package/dist/eject-theme/components/SocialLinks/GithubStars.test.tsx +4 -1
- package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +1 -1
- package/dist/entry/worker.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/node/PluginDriver.d.ts +5 -0
- package/dist/node/PluginDriver.js +17 -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 +19 -7
- 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/mdx/rehypePlugins/headerAnchor.js +1 -0
- package/dist/node/mdx/remarkPlugins/link.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/{DEFAULT_I18N_TEXT.d.ts → i18n/DEFAULT_I18N_TEXT.d.ts} +28 -0
- package/dist/node/runtimeModule/{DEFAULT_I18N_TEXT.js → i18n/DEFAULT_I18N_TEXT.js} +28 -0
- package/dist/node/runtimeModule/i18n/getI18nData.d.ts +11 -0
- package/dist/node/runtimeModule/{i18n.js → i18n/getI18nData.js} +35 -22
- package/dist/node/runtimeModule/i18n/rsbuildPlugin.d.ts +5 -0
- package/dist/node/runtimeModule/i18n/rsbuildPlugin.js +21 -0
- 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.d.ts +2 -1
- package/dist/node/runtimeModule/siteData/createSiteData.js +3 -3
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.d.ts +2 -1
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +3 -4
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +2 -2
- package/dist/node/serve.js +1 -1
- package/dist/node/sitemap.d.ts +7 -0
- package/dist/node/sitemap.js +86 -0
- package/dist/node/ssg/alternateLinks.js +1 -1
- package/dist/node/ssg/htmlFile.js +1 -1
- package/dist/node/ssg/renderHtmlTemplate.js +1 -1
- 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 +6 -3
- package/dist/{a~0.js → p~0.js} +23 -18
- package/dist/runtime/App.js +20 -29
- package/dist/runtime/BrowserOnly.d.ts +1 -1
- package/dist/runtime/BrowserOnly.js +53 -20
- package/dist/runtime/ClientApp.d.ts +3 -2
- package/dist/runtime/ClientApp.js +31 -21
- package/dist/runtime/ErrorRoute.d.ts +1 -0
- package/dist/runtime/ErrorRoute.js +30 -0
- package/dist/runtime/NoSSR.d.ts +7 -3
- package/dist/runtime/NoSSR.js +30 -9
- package/dist/runtime/PageRoute.d.ts +2 -0
- package/dist/runtime/PageRoute.js +70 -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/useWebMcp.d.ts +36 -0
- package/dist/runtime/hooks/useWebMcp.js +80 -0
- package/dist/runtime/index.d.ts +6 -3
- package/dist/runtime/index.js +6 -5
- package/dist/runtime/initPageData.d.ts +0 -3
- package/dist/runtime/initPageData.js +9 -45
- package/dist/runtime/pageDataLoader.d.ts +11 -0
- package/dist/runtime/pageDataLoader.js +7 -0
- package/dist/runtime/react.d.ts +5 -0
- package/dist/runtime/react.js +4 -0
- package/dist/runtime/reactDom.d.ts +6 -0
- package/dist/runtime/reactDom.js +2 -1
- package/dist/runtime/socialLinks.d.ts +1 -0
- package/dist/runtime/socialLinks.js +3 -0
- package/dist/runtime/ssrClientEntry.js +14 -6
- package/dist/runtime/ssrMdServerEntry.js +10 -21
- package/dist/runtime/ssrServerEntry.js +10 -21
- package/dist/static/assets/package.json +58 -0
- package/dist/theme/assets/bun.js +101 -0
- package/dist/theme/assets/deno.js +15 -0
- package/dist/theme/assets/jsdelivr.js +53 -0
- package/dist/theme/{components/PackageManagerTabs/icons/Npm.js → assets/npm.js} +4 -4
- package/dist/theme/{components/PackageManagerTabs/icons/Pnpm.js → assets/pnpm.js} +4 -4
- package/dist/theme/assets/unpkg.js +15 -0
- package/dist/theme/assets/yarn.js +22 -0
- package/dist/theme/components/CdnTabs/index.d.ts +10 -0
- package/dist/theme/components/CdnTabs/index.js +146 -0
- package/dist/theme/components/DocContent/index.js +1 -2
- package/dist/theme/components/FallbackHeading/index.js +1 -0
- package/dist/theme/components/Link/index.js +4 -17
- package/dist/theme/components/Link/useLinkNavigate.d.ts +2 -2
- package/dist/theme/components/Link/useLinkNavigate.js +22 -36
- package/dist/theme/components/NavTitle/index.js +10 -5
- package/dist/theme/components/PackageManagerTabs/index.d.ts +2 -0
- package/dist/theme/components/PackageManagerTabs/index.js +22 -12
- package/dist/theme/components/Search/NoSearchResult.css +1 -2
- package/dist/theme/components/Search/SearchPanel.css +72 -51
- package/dist/theme/components/Search/SuggestItem.css +21 -34
- package/dist/theme/components/Search/logic/providers/LocalProvider.js +4 -1
- package/dist/theme/components/Search/useSearchPanel.js +74 -26
- package/dist/theme/components/Sidebar/SidebarItem.css +5 -0
- package/dist/theme/components/Sidebar/SidebarSectionHeader.css +1 -0
- package/dist/theme/components/SocialLinks/GithubStars.js +1 -1
- package/dist/theme/hooks/useDynamicToc.js +27 -34
- 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/icons.d.ts +7 -0
- package/dist/theme/icons.js +15 -1
- package/dist/theme/index.d.ts +6 -2
- package/dist/theme/index.js +6 -2
- 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/layout/Layout/index.js +1 -2
- 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/y~0.js +166 -0
- package/package.json +18 -18
- package/dist/b~0.js +0 -106
- package/dist/eject-theme/components/PackageManagerTabs/icons/Bun.tsx +0 -101
- package/dist/eject-theme/components/PackageManagerTabs/icons/Deno.tsx +0 -18
- package/dist/eject-theme/components/PackageManagerTabs/icons/Npm.tsx +0 -16
- package/dist/eject-theme/components/PackageManagerTabs/icons/Pnpm.tsx +0 -22
- package/dist/eject-theme/components/PackageManagerTabs/icons/Yarn.tsx +0 -18
- package/dist/node/runtimeModule/i18n.d.ts +0 -8
- package/dist/theme/components/PackageManagerTabs/icons/Bun.d.ts +0 -2
- package/dist/theme/components/PackageManagerTabs/icons/Bun.js +0 -137
- package/dist/theme/components/PackageManagerTabs/icons/Deno.d.ts +0 -2
- package/dist/theme/components/PackageManagerTabs/icons/Deno.js +0 -15
- package/dist/theme/components/PackageManagerTabs/icons/Npm.d.ts +0 -2
- package/dist/theme/components/PackageManagerTabs/icons/Pnpm.d.ts +0 -2
- package/dist/theme/components/PackageManagerTabs/icons/Yarn.d.ts +0 -2
- package/dist/theme/components/PackageManagerTabs/icons/Yarn.js +0 -22
- package/dist/theme/logic/useScrollAfterNav.d.ts +0 -5
- package/dist/theme/logic/useScrollAfterNav.js +0 -35
- package/dist/theme/logic/useScrollReset.d.ts +0 -5
- package/dist/theme/logic/useScrollReset.js +0 -12
package/dist/cli/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { logger, cac } from "../
|
|
2
|
-
import { package_namespaceObject } from "../
|
|
1
|
+
import { logger, cac } from "../p~0.js";
|
|
2
|
+
import { package_namespaceObject } from "../y~0.js";
|
|
3
3
|
import { loadConfigFile, resolveDocRoot } from "../config/loadConfigFile.js";
|
|
4
4
|
import { dev } from "../node/dev.js";
|
|
5
5
|
import { build } from "../node/build.js";
|
|
@@ -16,10 +16,13 @@ function markMovable(value) {
|
|
|
16
16
|
value: true
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
+
function withNullPrototype(source) {
|
|
20
|
+
return Object.assign(Object.create(null), source);
|
|
21
|
+
}
|
|
19
22
|
function isTaskQueue(value) {
|
|
20
23
|
return "object" == typeof value && null !== value && "size" in value && "function" == typeof value.shift && "function" == typeof value.remove && "function" == typeof value.push;
|
|
21
24
|
}
|
|
22
25
|
const kRequestCountField = 0;
|
|
23
26
|
const kResponseCountField = 1;
|
|
24
27
|
const kFieldCount = 2;
|
|
25
|
-
export { isMovable, isTaskQueue, isTransferable, kFieldCount, kQueueOptions, kRequestCountField, kResponseCountField, kTransferable, kValue, markMovable };
|
|
28
|
+
export { isMovable, isTaskQueue, isTransferable, kFieldCount, kQueueOptions, kRequestCountField, kResponseCountField, kTransferable, kValue, markMovable, withNullPrototype };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../
|
|
1
|
+
import { node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../p~0.js";
|
|
2
2
|
async function loadConfigFile(customConfigFile) {
|
|
3
3
|
const { loadConfig } = await import("@rsbuild/core");
|
|
4
4
|
const result = await loadConfig({
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, rs } from '@rstest/core';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import { renderToMarkdownString } from 'react-render-to-markdown';
|
|
4
|
+
import { CdnTabs } from './index';
|
|
5
|
+
|
|
6
|
+
rs.mock('@rspress/core/theme', () => ({
|
|
7
|
+
getCustomMDXComponent: () => ({
|
|
8
|
+
pre: 'pre',
|
|
9
|
+
}),
|
|
10
|
+
Tab: ({ children }: { children: ReactNode }) => children,
|
|
11
|
+
Tabs: ({ children }: { children: ReactNode }) => children,
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
const originalSsgMd = import.meta.env.SSG_MD;
|
|
15
|
+
|
|
16
|
+
const setSsgMd = (value: boolean | undefined) => {
|
|
17
|
+
if (value === undefined) {
|
|
18
|
+
delete (import.meta.env as unknown as Record<string, unknown>).SSG_MD;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
(import.meta.env as unknown as Record<string, unknown>).SSG_MD = value;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
setSsgMd(originalSsgMd);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('CdnTabs', () => {
|
|
30
|
+
it('renders CSS and JavaScript tags for the default CDNs in SSG markdown', async () => {
|
|
31
|
+
setSsgMd(true);
|
|
32
|
+
|
|
33
|
+
const markdown = await renderToMarkdownString(
|
|
34
|
+
<CdnTabs
|
|
35
|
+
package="bootstrap@5"
|
|
36
|
+
files={['dist/css/bootstrap.min.css', 'dist/js/bootstrap.min.js']}
|
|
37
|
+
/>,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
expect(markdown).toContain('```html [jsDelivr]');
|
|
41
|
+
expect(markdown).toContain(
|
|
42
|
+
'<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5/dist/css/bootstrap.min.css" />',
|
|
43
|
+
);
|
|
44
|
+
expect(markdown).toContain(
|
|
45
|
+
'<script src="https://unpkg.com/bootstrap@5/dist/js/bootstrap.min.js"></script>',
|
|
46
|
+
);
|
|
47
|
+
expect(markdown).toContain('```html [unpkg]');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('supports scoped packages and a custom CDN order', async () => {
|
|
51
|
+
setSsgMd(true);
|
|
52
|
+
|
|
53
|
+
const markdown = await renderToMarkdownString(
|
|
54
|
+
<CdnTabs
|
|
55
|
+
package="@scope/package@5"
|
|
56
|
+
files={['dist/bundle.js']}
|
|
57
|
+
cdns={['unpkg', 'jsdelivr']}
|
|
58
|
+
/>,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
expect(markdown.indexOf('```html [unpkg]')).toBeLessThan(
|
|
62
|
+
markdown.indexOf('```html [jsDelivr]'),
|
|
63
|
+
);
|
|
64
|
+
expect(markdown).toContain(
|
|
65
|
+
'<script src="https://unpkg.com/@scope/package@5/dist/bundle.js"></script>',
|
|
66
|
+
);
|
|
67
|
+
expect(markdown).toContain(
|
|
68
|
+
'<script src="https://cdn.jsdelivr.net/npm/@scope/package@5/dist/bundle.js"></script>',
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCustomMDXComponent,
|
|
3
|
+
IconJsdelivr,
|
|
4
|
+
IconUnpkg,
|
|
5
|
+
SvgWrapper,
|
|
6
|
+
Tab,
|
|
7
|
+
Tabs,
|
|
8
|
+
} from '@rspress/core/theme';
|
|
9
|
+
import { Fragment, useMemo } from 'react';
|
|
10
|
+
|
|
11
|
+
export type CdnName = 'jsdelivr' | 'unpkg';
|
|
12
|
+
|
|
13
|
+
export type CdnTabsProps = {
|
|
14
|
+
/** Package name and version, e.g. `bootstrap@5`. */
|
|
15
|
+
package: string;
|
|
16
|
+
/** CSS and JavaScript asset paths within the package. */
|
|
17
|
+
files: ReadonlyArray<string>;
|
|
18
|
+
/** CDNs to display, in tab order. Defaults to jsDelivr and unpkg. */
|
|
19
|
+
cdns?: ReadonlyArray<CdnName>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const DEFAULT_CDNS: ReadonlyArray<CdnName> = ['jsdelivr', 'unpkg'];
|
|
23
|
+
|
|
24
|
+
const CDN_INFO: Record<CdnName, { label: string; baseUrl: string }> = {
|
|
25
|
+
jsdelivr: {
|
|
26
|
+
label: 'jsDelivr',
|
|
27
|
+
baseUrl: 'https://cdn.jsdelivr.net/npm/',
|
|
28
|
+
},
|
|
29
|
+
unpkg: {
|
|
30
|
+
label: 'unpkg',
|
|
31
|
+
baseUrl: 'https://unpkg.com/',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function encodePath(path: string): string {
|
|
36
|
+
return path
|
|
37
|
+
.split('/')
|
|
38
|
+
.map(segment => encodeURIComponent(segment).replace(/%40/gi, '@'))
|
|
39
|
+
.join('/');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getAssetUrl(cdn: CdnName, packageName: string, file: string): string {
|
|
43
|
+
return `${CDN_INFO[cdn].baseUrl}${encodePath(packageName)}/${encodePath(file)}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type AssetTag = {
|
|
47
|
+
tag: 'link' | 'script';
|
|
48
|
+
attributes: Record<string, string>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
function getAssetTags(
|
|
52
|
+
cdn: CdnName,
|
|
53
|
+
packageName: string,
|
|
54
|
+
files: ReadonlyArray<string>,
|
|
55
|
+
): AssetTag[] {
|
|
56
|
+
return files.flatMap<AssetTag>(file => {
|
|
57
|
+
const url = getAssetUrl(cdn, packageName, file);
|
|
58
|
+
if (file.toLowerCase().endsWith('.css')) {
|
|
59
|
+
return [{ tag: 'link', attributes: { rel: 'stylesheet', href: url } }];
|
|
60
|
+
}
|
|
61
|
+
if (file.toLowerCase().endsWith('.js')) {
|
|
62
|
+
return [{ tag: 'script', attributes: { src: url } }];
|
|
63
|
+
}
|
|
64
|
+
return [];
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getHtmlSnippet(tags: AssetTag[]): string {
|
|
69
|
+
return tags
|
|
70
|
+
.map(({ tag, attributes }) => {
|
|
71
|
+
const attrs = Object.entries(attributes)
|
|
72
|
+
.map(([name, value]) => `${name}="${value}"`)
|
|
73
|
+
.join(' ');
|
|
74
|
+
return tag === 'link'
|
|
75
|
+
? `<${tag} ${attrs} />`
|
|
76
|
+
: `<${tag} ${attrs}></${tag}>`;
|
|
77
|
+
})
|
|
78
|
+
.join('\n');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function CdnTabs({
|
|
82
|
+
package: packageName,
|
|
83
|
+
files,
|
|
84
|
+
cdns = DEFAULT_CDNS,
|
|
85
|
+
}: CdnTabsProps) {
|
|
86
|
+
const Pre = useMemo(
|
|
87
|
+
() => getCustomMDXComponent().pre,
|
|
88
|
+
[getCustomMDXComponent],
|
|
89
|
+
);
|
|
90
|
+
const tabs = cdns.map(cdn => ({
|
|
91
|
+
cdn,
|
|
92
|
+
label: CDN_INFO[cdn].label,
|
|
93
|
+
tags: getAssetTags(cdn, packageName, files),
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
if (import.meta.env.SSG_MD) {
|
|
97
|
+
return tabs
|
|
98
|
+
.map(
|
|
99
|
+
({ label, tags }) =>
|
|
100
|
+
`\n\`\`\`html [${label}]\n${getHtmlSnippet(tags)}\n\`\`\`\n`,
|
|
101
|
+
)
|
|
102
|
+
.join('');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<Tabs groupId="cdn">
|
|
107
|
+
{tabs.map(({ cdn, label, tags }) => (
|
|
108
|
+
<Tab
|
|
109
|
+
key={cdn}
|
|
110
|
+
value={cdn}
|
|
111
|
+
label={
|
|
112
|
+
<span style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
|
113
|
+
<SvgWrapper
|
|
114
|
+
icon={cdn === 'jsdelivr' ? IconJsdelivr : IconUnpkg}
|
|
115
|
+
width="1em"
|
|
116
|
+
height="1em"
|
|
117
|
+
aria-hidden="true"
|
|
118
|
+
/>
|
|
119
|
+
{label}
|
|
120
|
+
</span>
|
|
121
|
+
}
|
|
122
|
+
>
|
|
123
|
+
<Pre
|
|
124
|
+
lang="html"
|
|
125
|
+
className="shiki css-variables"
|
|
126
|
+
style={{
|
|
127
|
+
backgroundColor: 'var(--shiki-background)',
|
|
128
|
+
color: 'var(--shiki-foreground)',
|
|
129
|
+
}}
|
|
130
|
+
>
|
|
131
|
+
<code style={{ whiteSpace: 'pre' }}>
|
|
132
|
+
{/* These generated tags have a fixed grammar, so highlight them directly. */}
|
|
133
|
+
{tags.map(({ tag, attributes }, index) => (
|
|
134
|
+
<Fragment key={index}>
|
|
135
|
+
{index > 0 ? '\n' : null}
|
|
136
|
+
<span className="line">
|
|
137
|
+
{'<'}
|
|
138
|
+
<span style={{ color: 'var(--shiki-token-keyword)' }}>
|
|
139
|
+
{tag}
|
|
140
|
+
</span>
|
|
141
|
+
{Object.entries(attributes).map(([name, value]) => (
|
|
142
|
+
<Fragment key={name}>
|
|
143
|
+
{' '}
|
|
144
|
+
<span style={{ color: 'var(--shiki-token-function)' }}>
|
|
145
|
+
{name}
|
|
146
|
+
</span>
|
|
147
|
+
{'='}
|
|
148
|
+
<span
|
|
149
|
+
style={{
|
|
150
|
+
color: 'var(--shiki-token-string-expression)',
|
|
151
|
+
}}
|
|
152
|
+
>{`"${value}"`}</span>
|
|
153
|
+
</Fragment>
|
|
154
|
+
))}
|
|
155
|
+
{tag === 'link' ? (
|
|
156
|
+
' />'
|
|
157
|
+
) : (
|
|
158
|
+
<>
|
|
159
|
+
{'></'}
|
|
160
|
+
<span style={{ color: 'var(--shiki-token-keyword)' }}>
|
|
161
|
+
{tag}
|
|
162
|
+
</span>
|
|
163
|
+
{'>'}
|
|
164
|
+
</>
|
|
165
|
+
)}
|
|
166
|
+
</span>
|
|
167
|
+
</Fragment>
|
|
168
|
+
))}
|
|
169
|
+
</code>
|
|
170
|
+
</Pre>
|
|
171
|
+
</Tab>
|
|
172
|
+
))}
|
|
173
|
+
</Tabs>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
Callout,
|
|
5
5
|
FallbackHeading,
|
|
6
6
|
getCustomMDXComponent,
|
|
7
|
-
useScrollAfterNav,
|
|
8
7
|
} from '@rspress/core/theme';
|
|
9
8
|
import './doc.scss';
|
|
10
9
|
|
|
@@ -38,8 +37,6 @@ export function DocContent({
|
|
|
38
37
|
*/
|
|
39
38
|
afterDocContent?: React.ReactNode;
|
|
40
39
|
}) {
|
|
41
|
-
useScrollAfterNav();
|
|
42
|
-
|
|
43
40
|
const mdxComponents = {
|
|
44
41
|
...getCustomMDXComponent(),
|
|
45
42
|
...components,
|
|
@@ -50,7 +50,12 @@ export function FallbackHeading({
|
|
|
50
50
|
titleSlug && (
|
|
51
51
|
<Element id={titleSlug}>
|
|
52
52
|
<span {...renderInlineMarkdown(title)}></span>
|
|
53
|
-
<A
|
|
53
|
+
<A
|
|
54
|
+
className="rp-header-anchor"
|
|
55
|
+
href={`#${titleSlug}`}
|
|
56
|
+
aria-hidden
|
|
57
|
+
tabIndex={-1}
|
|
58
|
+
>
|
|
54
59
|
#
|
|
55
60
|
</A>
|
|
56
61
|
</Element>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cleanUrl, isExternalUrl } from '@rspress/shared';
|
|
2
|
+
// eslint-disable-next-line no-restricted-imports -- Existing cross-directory dependency; retained until this component is eject-safe.
|
|
2
3
|
import { cleanUrlByConfig, removeBase, withBase } from '../../../runtime/utils';
|
|
3
4
|
|
|
4
5
|
type LinkType = 'external' | 'hashOnly' | 'relative' | 'internal';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { preloadLink } from '@rspress/core/runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import nprogress from 'nprogress';
|
|
4
3
|
import type React from 'react';
|
|
5
4
|
import type { ComponentProps, TransitionStartFunction } from 'react';
|
|
6
5
|
import { forwardRef } from 'react';
|
|
@@ -35,8 +34,6 @@ export interface LinkProps extends ComponentProps<'a'> {
|
|
|
35
34
|
startTransition?: TransitionStartFunction;
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
nprogress.configure({ showSpinner: false });
|
|
39
|
-
|
|
40
37
|
/**
|
|
41
38
|
* What's the difference between <Link> and <a>?
|
|
42
39
|
* Link can tell whether it's in current site or external site.
|
|
@@ -76,22 +73,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
|
|
|
76
73
|
);
|
|
77
74
|
}
|
|
78
75
|
|
|
79
|
-
if (linkType === 'hashOnly') {
|
|
80
|
-
return (
|
|
81
|
-
<a
|
|
82
|
-
ref={ref}
|
|
83
|
-
href={href}
|
|
84
|
-
className={clsx(className, 'rp-link')}
|
|
85
|
-
onClick={onClick}
|
|
86
|
-
onMouseEnter={onMouseEnter}
|
|
87
|
-
{...otherProps}
|
|
88
|
-
>
|
|
89
|
-
{children}
|
|
90
|
-
</a>
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (linkType === 'relative') {
|
|
76
|
+
if (linkType === 'hashOnly' || linkType === 'relative') {
|
|
95
77
|
return (
|
|
96
78
|
<a
|
|
97
79
|
ref={ref}
|
|
@@ -99,14 +81,20 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
|
|
|
99
81
|
className={clsx(className, 'rp-link')}
|
|
100
82
|
onMouseEnter={event => {
|
|
101
83
|
onMouseEnter?.(event);
|
|
102
|
-
|
|
84
|
+
if (linkType === 'relative') {
|
|
85
|
+
preloadLink(routePath);
|
|
86
|
+
}
|
|
103
87
|
}}
|
|
104
88
|
onTouchStart={() => {
|
|
105
|
-
|
|
89
|
+
if (linkType === 'relative') {
|
|
90
|
+
preloadLink(routePath);
|
|
91
|
+
}
|
|
106
92
|
}}
|
|
107
93
|
onClick={e => {
|
|
108
94
|
onClick?.(e);
|
|
109
95
|
if (
|
|
96
|
+
e.defaultPrevented ||
|
|
97
|
+
e.currentTarget.hasAttribute('download') ||
|
|
110
98
|
// left click only
|
|
111
99
|
e.button !== 0 ||
|
|
112
100
|
// `target` are usually used for open link in new window/tab
|
|
@@ -1,35 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
initPageData,
|
|
3
2
|
isActive,
|
|
4
3
|
pathnameToRouteService,
|
|
5
4
|
useLocation,
|
|
6
|
-
useNavigate
|
|
5
|
+
useNavigate,
|
|
7
6
|
useSite,
|
|
8
|
-
warmPageData,
|
|
9
7
|
} from '@rspress/core/runtime';
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
startTransition as reactStartTransition,
|
|
13
|
-
type TransitionStartFunction,
|
|
14
|
-
useCallback,
|
|
15
|
-
} from 'react';
|
|
8
|
+
import { type TransitionStartFunction, useCallback } from 'react';
|
|
16
9
|
import { getHref } from './getHref';
|
|
17
10
|
|
|
18
|
-
nprogress.configure({ showSpinner: false });
|
|
19
|
-
|
|
20
11
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
12
|
+
* Navigate with Rspress link normalization. The router loader handles page
|
|
13
|
+
* loading for both this helper and the native useNavigate hook.
|
|
23
14
|
*/
|
|
24
|
-
export function useLinkNavigate(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const { pathname: currPagePathname } = useLocation();
|
|
32
|
-
const navigate = useNavigateInner();
|
|
15
|
+
export function useLinkNavigate({
|
|
16
|
+
startTransition,
|
|
17
|
+
}: { startTransition?: TransitionStartFunction } = {}): (
|
|
18
|
+
href: string,
|
|
19
|
+
) => Promise<void> {
|
|
20
|
+
const { pathname } = useLocation();
|
|
21
|
+
const navigate = useNavigate();
|
|
33
22
|
const { site } = useSite();
|
|
34
23
|
const useTransitions = site?.route?.useTransitions;
|
|
35
24
|
|
|
@@ -37,45 +26,45 @@ export function useLinkNavigate(
|
|
|
37
26
|
async (href: string) => {
|
|
38
27
|
const { linkType, removeBaseHref, routePath, withBaseHref } =
|
|
39
28
|
getHref(href);
|
|
40
|
-
if (linkType === 'external'
|
|
29
|
+
if (linkType === 'external') {
|
|
41
30
|
window.location.assign(href);
|
|
42
31
|
return;
|
|
43
32
|
}
|
|
33
|
+
// Keep same-page links client-side, including on a 404 page, so clicking
|
|
34
|
+
// a parent menu link does not reload the document and close its submenu.
|
|
35
|
+
if (
|
|
36
|
+
linkType !== 'hashOnly' &&
|
|
37
|
+
!isActive(removeBaseHref, pathname) &&
|
|
38
|
+
!pathnameToRouteService(routePath)
|
|
39
|
+
) {
|
|
40
|
+
window.location.assign(withBaseHref);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
clearTimeout(timer);
|
|
58
|
-
nprogress.done();
|
|
59
|
-
} else {
|
|
60
|
-
window.location.assign(withBaseHref);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (isTransitionable) {
|
|
65
|
-
startTransition(() => {
|
|
66
|
-
return navigate(removeBaseHref, { replace: false });
|
|
67
|
-
});
|
|
68
|
-
} else {
|
|
69
|
-
navigate(removeBaseHref, { replace: false });
|
|
70
|
-
}
|
|
71
|
-
};
|
|
44
|
+
// Native hash navigation creates history entries without router keys.
|
|
45
|
+
// Preserve the current query and let the router track each anchor visit.
|
|
46
|
+
const hashUrl =
|
|
47
|
+
linkType === 'hashOnly'
|
|
48
|
+
? new URL(href, window.location.href)
|
|
49
|
+
: undefined;
|
|
50
|
+
const to = hashUrl
|
|
51
|
+
? { search: hashUrl.search, hash: hashUrl.hash }
|
|
52
|
+
: removeBaseHref;
|
|
53
|
+
const options = hashUrl
|
|
54
|
+
? { replace: hashUrl.href === window.location.href }
|
|
55
|
+
: undefined;
|
|
72
56
|
|
|
73
|
-
if (
|
|
74
|
-
|
|
57
|
+
if (useTransitions && startTransition) {
|
|
58
|
+
let navigation: void | Promise<void> = undefined;
|
|
59
|
+
startTransition(() => {
|
|
60
|
+
navigation = navigate(to, options);
|
|
61
|
+
return navigation;
|
|
62
|
+
});
|
|
63
|
+
await navigation;
|
|
75
64
|
} else {
|
|
76
|
-
|
|
65
|
+
await navigate(to, options);
|
|
77
66
|
}
|
|
78
67
|
},
|
|
79
|
-
[useTransitions,
|
|
68
|
+
[useTransitions, pathname, navigate, startTransition],
|
|
80
69
|
);
|
|
81
70
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { afterEach, describe, expect, it, rs } from '@rstest/core';
|
|
3
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
4
|
+
import { NavTitle } from './index';
|
|
5
|
+
|
|
6
|
+
type Logo =
|
|
7
|
+
string | { dark: string; light: string; width?: number; height?: number };
|
|
8
|
+
|
|
9
|
+
const defaultSite = {
|
|
10
|
+
title: 'Rspress',
|
|
11
|
+
lang: 'en',
|
|
12
|
+
themeConfig: { locales: [] as { lang: string; title?: string }[] },
|
|
13
|
+
logo: '/logo.svg' as Logo,
|
|
14
|
+
logoText: '',
|
|
15
|
+
logoHref: '',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
let site = defaultSite;
|
|
19
|
+
let lang = 'en';
|
|
20
|
+
|
|
21
|
+
rs.mock('@rspress/core/runtime', () => ({
|
|
22
|
+
addLeadingSlash: (path: string) => (path.startsWith('/') ? path : `/${path}`),
|
|
23
|
+
addTrailingSlash: (path: string) => (path.endsWith('/') ? path : `${path}/`),
|
|
24
|
+
normalizeImagePath: (path: string) => path,
|
|
25
|
+
useLang: () => lang,
|
|
26
|
+
useSite: () => ({ site }),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
rs.mock('@rspress/core/theme', () => ({
|
|
30
|
+
Link: ({
|
|
31
|
+
children,
|
|
32
|
+
className,
|
|
33
|
+
href,
|
|
34
|
+
}: {
|
|
35
|
+
children: React.ReactNode;
|
|
36
|
+
className?: string;
|
|
37
|
+
href: string;
|
|
38
|
+
}) => (
|
|
39
|
+
<a className={className} href={href}>
|
|
40
|
+
{children}
|
|
41
|
+
</a>
|
|
42
|
+
),
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
site = defaultSite;
|
|
47
|
+
lang = 'en';
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('NavTitle', () => {
|
|
51
|
+
it('uses the site title as the logo alt and applies configured image dimensions', () => {
|
|
52
|
+
site = {
|
|
53
|
+
...defaultSite,
|
|
54
|
+
logo: {
|
|
55
|
+
light: '/logo-light.png',
|
|
56
|
+
dark: '/logo-dark.png',
|
|
57
|
+
width: 120,
|
|
58
|
+
height: 32,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const markup = renderToStaticMarkup(<NavTitle />);
|
|
63
|
+
|
|
64
|
+
expect(markup).toContain('alt="Rspress"');
|
|
65
|
+
expect(markup.match(/id="logo"/g)).toHaveLength(1);
|
|
66
|
+
expect(markup.match(/width="120"/g)).toHaveLength(2);
|
|
67
|
+
expect(markup.match(/height="32"/g)).toHaveLength(2);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('marks the logo decorative when adjacent logo text names the link', () => {
|
|
71
|
+
site = { ...defaultSite, logoText: 'Rspress docs' };
|
|
72
|
+
const markup = renderToStaticMarkup(<NavTitle />);
|
|
73
|
+
|
|
74
|
+
expect(markup).toContain('alt=""');
|
|
75
|
+
expect(markup).toContain('>Rspress docs</span>');
|
|
76
|
+
expect(markup).not.toContain('alt="logo"');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -22,6 +22,7 @@ export const NavTitle = () => {
|
|
|
22
22
|
const langRoutePrefix = lang === defaultLang ? '/' : addTrailingSlash(lang);
|
|
23
23
|
|
|
24
24
|
const { logo: rawLogo, logoText, logoHref } = site;
|
|
25
|
+
const alt = logoText ? '' : title;
|
|
25
26
|
const logo = useMemo(() => {
|
|
26
27
|
if (!rawLogo) {
|
|
27
28
|
return null;
|
|
@@ -30,7 +31,7 @@ export const NavTitle = () => {
|
|
|
30
31
|
return (
|
|
31
32
|
<img
|
|
32
33
|
src={normalizeImagePath(rawLogo)}
|
|
33
|
-
alt=
|
|
34
|
+
alt={alt}
|
|
34
35
|
id="logo"
|
|
35
36
|
className="rspress-logo rp-nav__title__logo-image"
|
|
36
37
|
/>
|
|
@@ -40,19 +41,22 @@ export const NavTitle = () => {
|
|
|
40
41
|
<>
|
|
41
42
|
<img
|
|
42
43
|
src={normalizeImagePath(rawLogo.light)}
|
|
43
|
-
alt=
|
|
44
|
+
alt={alt}
|
|
44
45
|
id="logo"
|
|
46
|
+
width={rawLogo.width}
|
|
47
|
+
height={rawLogo.height}
|
|
45
48
|
className="rspress-logo rp-nav__title__logo-image rp-nav__title__logo-image--light"
|
|
46
49
|
/>
|
|
47
50
|
<img
|
|
48
51
|
src={normalizeImagePath(rawLogo.dark)}
|
|
49
|
-
alt=
|
|
50
|
-
|
|
52
|
+
alt={alt}
|
|
53
|
+
width={rawLogo.width}
|
|
54
|
+
height={rawLogo.height}
|
|
51
55
|
className="rspress-logo rp-nav__title__logo-image rp-nav__title__logo-image--dark"
|
|
52
56
|
/>
|
|
53
57
|
</>
|
|
54
58
|
);
|
|
55
|
-
}, [rawLogo]);
|
|
59
|
+
}, [rawLogo, alt]);
|
|
56
60
|
|
|
57
61
|
return (
|
|
58
62
|
<div className="rp-nav__title">
|