@rspress/core 2.0.20 → 2.0.22
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 +12 -13
- package/dist/config/loadConfigFile.d.ts +3 -4
- package/dist/config/loadConfigFile.js +13 -17
- package/dist/{7748~0.js → d~0.js} +0 -2
- package/dist/eject-theme/components/Banner/index.tsx +50 -9
- package/dist/eject-theme/components/Callout/index.scss +6 -1
- package/dist/eject-theme/components/CodeBlock/index.scss +2 -0
- package/dist/eject-theme/components/DocContent/doc.scss +2 -2
- package/dist/eject-theme/components/Link/getHref.test.ts +33 -0
- package/dist/eject-theme/components/Link/getHref.ts +60 -0
- package/dist/eject-theme/components/Link/index.tsx +7 -6
- package/dist/eject-theme/components/Link/useLinkNavigate.ts +6 -51
- package/dist/eject-theme/components/Llms/LlmsHint.test.tsx +8 -0
- package/dist/eject-theme/components/Llms/LlmsHint.tsx +11 -3
- package/dist/eject-theme/components/Nav/NavMenu.scss +19 -3
- package/dist/eject-theme/components/Nav/NavMenu.tsx +20 -13
- package/dist/eject-theme/components/Nav/index.scss +3 -1
- package/dist/eject-theme/components/Nav/index.tsx +30 -4
- package/dist/eject-theme/components/NavHamburger/index.tsx +11 -3
- package/dist/eject-theme/components/NavList/context.ts +3 -0
- package/dist/eject-theme/components/NavList/index.tsx +24 -0
- package/dist/eject-theme/components/NavScreen/NavScreenMenu.test.tsx +59 -0
- package/dist/eject-theme/components/NavScreen/NavScreenMenu.tsx +43 -2
- package/dist/eject-theme/components/NavScreen/index.scss +0 -6
- package/dist/eject-theme/components/NavScreen/index.tsx +20 -3
- package/dist/eject-theme/components/Prompt/index.scss +2 -1
- package/dist/eject-theme/components/ReadPercent/useReadPercent.ts +1 -1
- package/dist/eject-theme/components/Search/SearchButton.scss +1 -0
- package/dist/eject-theme/components/Search/SearchPanel.scss +51 -12
- package/dist/eject-theme/components/Search/SearchPanel.tsx +54 -212
- package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +38 -16
- package/dist/eject-theme/components/Search/useSearchPanel.ts +216 -0
- package/dist/eject-theme/components/Steps/index.scss +1 -1
- package/dist/eject-theme/components/SwitchAppearance/getClipPath.test.ts +15 -0
- package/dist/eject-theme/components/SwitchAppearance/getClipPath.ts +26 -0
- package/dist/eject-theme/components/SwitchAppearance/global.scss +18 -0
- package/dist/eject-theme/components/SwitchAppearance/index.tsx +26 -35
- package/dist/eject-theme/components/Tabs/index.tsx +14 -14
- package/dist/index.js +1 -1
- package/dist/node/PluginDriver.d.ts +1 -1
- package/dist/node/PluginDriver.js +5 -9
- 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 +6 -6
- package/dist/node/auto-nav-sidebar/utils.js +1 -1
- package/dist/node/auto-nav-sidebar/walk.js +1 -1
- package/dist/node/build.d.ts +3 -2
- package/dist/node/build.js +9 -3
- package/dist/node/constants.js +1 -1
- package/dist/node/dev.d.ts +4 -4
- package/dist/node/dev.js +8 -6
- package/dist/node/eject.js +5 -5
- package/dist/node/initRsbuild.d.ts +2 -3
- package/dist/node/initRsbuild.js +9 -7
- package/dist/node/last-updated/index.js +2 -2
- package/dist/node/logger/hint.js +4 -4
- package/dist/node/mdx/options.js +1 -1
- package/dist/node/mdx/processor.js +3 -3
- 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.js +6 -5
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +5 -5
- package/dist/node/mdx/remarkPlugins/image.js +5 -5
- package/dist/node/mdx/remarkPlugins/link.js +5 -5
- package/dist/node/mdx/remarkPlugins/toc.js +1 -1
- package/dist/node/medium-zoom/index.js +1 -1
- package/dist/node/route/RoutePage.js +6 -4
- package/dist/node/route/RouteService.js +3 -3
- package/dist/node/route/extractPageData.js +20 -7
- package/dist/node/route/normalizeRoutePath.js +1 -1
- package/dist/node/runtimeModule/i18n.js +5 -5
- 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 +1 -1
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
- package/dist/node/serve.d.ts +3 -3
- package/dist/node/serve.js +10 -4
- 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 +5 -5
- package/dist/node/ssg/renderPageWorker.js +2 -2
- package/dist/node/ssg/renderPages.js +6 -6
- 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/remarkSplitMdx.js +1 -1
- package/dist/node/ssg-md/renderPage.js +5 -5
- package/dist/node/ssg-md/renderPages.js +6 -6
- package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
- package/dist/node/utils/checkLanguageParity.js +5 -7
- package/dist/node/utils/createHash.js +1 -1
- package/dist/node/utils/error.js +4 -4
- package/dist/node/utils/flattenMdxContent.js +2 -2
- package/dist/node/utils/fs.js +1 -1
- package/dist/node/utils/getPageKey.js +1 -1
- package/dist/node/utils/index.d.ts +1 -1
- package/dist/node/utils/reactAlias.js +5 -5
- package/dist/node/utils/slash.d.ts +1 -0
- package/dist/node/utils/slash.js +4 -0
- package/dist/{864~0.js → n~0.js} +41 -41
- package/dist/{2711~0.js → o~0.js} +90 -56
- package/dist/rslib-runtime~0.js +27 -35
- package/dist/theme/components/Banner/index.js +53 -9
- package/dist/theme/components/Callout/index.css +6 -1
- package/dist/theme/components/CodeBlock/index.css +2 -0
- package/dist/theme/components/DocContent/doc.css +2 -2
- package/dist/theme/components/Link/getHref.d.ts +8 -0
- package/dist/theme/components/Link/getHref.js +33 -0
- package/dist/theme/components/Link/index.js +7 -6
- package/dist/theme/components/Link/useLinkNavigate.d.ts +0 -7
- package/dist/theme/components/Link/useLinkNavigate.js +8 -32
- package/dist/theme/components/Llms/LlmsHint.js +23 -6
- package/dist/theme/components/Nav/NavMenu.css +18 -6
- package/dist/theme/components/Nav/NavMenu.d.ts +4 -2
- package/dist/theme/components/Nav/NavMenu.js +17 -9
- package/dist/theme/components/Nav/index.css +3 -1
- package/dist/theme/components/Nav/index.d.ts +7 -1
- package/dist/theme/components/Nav/index.js +13 -4
- package/dist/theme/components/NavHamburger/index.d.ts +2 -1
- package/dist/theme/components/NavHamburger/index.js +8 -2
- package/dist/theme/components/NavList/context.d.ts +1 -0
- package/dist/theme/components/NavList/context.js +3 -0
- package/dist/theme/components/NavList/index.d.ts +6 -0
- package/dist/theme/components/NavList/index.js +17 -0
- package/dist/theme/components/NavScreen/NavScreenMenu.d.ts +3 -2
- package/dist/theme/components/NavScreen/NavScreenMenu.js +42 -6
- package/dist/theme/components/NavScreen/index.css +0 -10
- package/dist/theme/components/NavScreen/index.d.ts +2 -1
- package/dist/theme/components/NavScreen/index.js +11 -3
- package/dist/theme/components/PackageManagerTabs/index.js +2 -2
- package/dist/theme/components/Prompt/index.css +2 -1
- package/dist/theme/components/ReadPercent/useReadPercent.js +1 -0
- package/dist/theme/components/Search/SearchButton.css +1 -0
- package/dist/theme/components/Search/SearchPanel.css +47 -9
- package/dist/theme/components/Search/SearchPanel.js +97 -205
- package/dist/theme/components/Search/logic/providers/LocalProvider.d.ts +1 -0
- package/dist/theme/components/Search/logic/providers/LocalProvider.js +23 -13
- package/dist/theme/components/Search/logic/search.js +1 -1
- package/dist/theme/components/Search/useSearchPanel.d.ts +23 -0
- package/dist/theme/components/Search/useSearchPanel.js +155 -0
- package/dist/theme/components/Steps/index.css +3 -3
- package/dist/theme/components/SwitchAppearance/getClipPath.d.ts +8 -0
- package/dist/theme/components/SwitchAppearance/getClipPath.js +13 -0
- package/dist/theme/components/SwitchAppearance/global.css +12 -0
- package/dist/theme/components/SwitchAppearance/index.js +11 -15
- package/dist/theme/components/Tabs/index.js +4 -4
- package/dist/theme/components/Tag/index.js +2 -2
- package/dist/theme/index.d.ts +1 -0
- package/dist/theme/index.js +1 -0
- package/dist/theme/layout/DocLayout/index.js +2 -2
- package/dist/theme/layout/Layout/index.js +12 -4
- package/dist/theme/logic/applyThemeToDOM.d.ts +2 -0
- package/dist/theme/logic/applyThemeToDOM.js +17 -0
- package/dist/theme/logic/useFullTextSearch.js +6 -1
- package/dist/theme/logic/useThemeState.d.ts +1 -2
- package/dist/theme/logic/useThemeState.js +1 -7
- package/dist/theme/styles/vars/shiki-vars.css +1 -1
- package/dist/tinypool~0.js +5 -3
- package/dist/{4538~0.js → t~0.js} +2 -2
- package/dist/{8472~0.js → v~0.js} +1 -1
- package/package.json +11 -12
- package/dist/eject-theme/components/NavScreen/NavScreenMenuOthers.tsx +0 -29
- package/dist/node/utils/normalizePath.d.ts +0 -3
- package/dist/node/utils/normalizePath.js +0 -10
- package/dist/theme/components/NavScreen/NavScreenMenuOthers.d.ts +0 -2
- package/dist/theme/components/NavScreen/NavScreenMenuOthers.js +0 -30
- package/dist/theme/logic/useHandler.d.ts +0 -6
- package/dist/theme/logic/useHandler.js +0 -7
- /package/dist/{9857~0.js → 4~0.js} +0 -0
- /package/dist/{8016~0.js → i~0.js} +0 -0
- /package/dist/{5357~0.js → r~0.js} +0 -0
- /package/dist/{102~0.js → t2~0.js} +0 -0
- /package/dist/{9940~0.js → tx~0.js} +0 -0
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 "../o~0.js";
|
|
2
|
+
import { package_namespaceObject } from "../v~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";
|
|
@@ -19,15 +19,14 @@ function runCLI({ argv = process.argv } = {}) {
|
|
|
19
19
|
let devServer;
|
|
20
20
|
const startDevServer = async ()=>{
|
|
21
21
|
const { port, host } = options || {};
|
|
22
|
-
const
|
|
22
|
+
const configResult = await loadConfigFile(options?.config);
|
|
23
|
+
const { content: config } = configResult;
|
|
23
24
|
config.root = resolveDocRoot(cwd, root, config.root);
|
|
24
25
|
if (options?.base) config.base = options.base;
|
|
25
26
|
const docDirectory = config.root;
|
|
26
27
|
devServer = await dev({
|
|
27
|
-
appDirectory: cwd,
|
|
28
28
|
docDirectory,
|
|
29
|
-
config,
|
|
30
|
-
configFilePath,
|
|
29
|
+
config: configResult,
|
|
31
30
|
extraBuilderConfig: {
|
|
32
31
|
server: {
|
|
33
32
|
port,
|
|
@@ -60,15 +59,15 @@ function runCLI({ argv = process.argv } = {}) {
|
|
|
60
59
|
cli.command('build [root]', 'Build the documentation site for production').option('--base <base>', 'Set the base path and override config.base').action(async (root, options)=>{
|
|
61
60
|
setNodeEnv('production');
|
|
62
61
|
const cwd = process.cwd();
|
|
63
|
-
const
|
|
62
|
+
const configResult = await loadConfigFile(options.config);
|
|
63
|
+
const { content: config } = configResult;
|
|
64
64
|
config.root = resolveDocRoot(cwd, root, config.root);
|
|
65
65
|
if (options.base) config.base = options.base;
|
|
66
66
|
const docDirectory = config.root;
|
|
67
67
|
try {
|
|
68
68
|
await build({
|
|
69
69
|
docDirectory,
|
|
70
|
-
config
|
|
71
|
-
configFilePath
|
|
70
|
+
config: configResult
|
|
72
71
|
});
|
|
73
72
|
} catch (err) {
|
|
74
73
|
logger.error(err);
|
|
@@ -79,14 +78,14 @@ function runCLI({ argv = process.argv } = {}) {
|
|
|
79
78
|
setNodeEnv('production');
|
|
80
79
|
const cwd = process.cwd();
|
|
81
80
|
const { port, host } = options || {};
|
|
82
|
-
const
|
|
81
|
+
const configResult = await loadConfigFile(options?.config);
|
|
82
|
+
const { content: config } = configResult;
|
|
83
83
|
config.root = resolveDocRoot(cwd, root, config.root);
|
|
84
84
|
if (options?.base) config.base = options.base;
|
|
85
85
|
await serve({
|
|
86
|
-
config,
|
|
86
|
+
config: configResult,
|
|
87
87
|
host,
|
|
88
|
-
port
|
|
89
|
-
configFilePath
|
|
88
|
+
port
|
|
90
89
|
});
|
|
91
90
|
});
|
|
92
91
|
cli.command('eject [component]', 'Eject a theme component for customization').action(async (component)=>{
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import type { LoadConfigResult } from '@rsbuild/core';
|
|
1
2
|
import type { UserConfig } from '@rspress/shared';
|
|
2
|
-
export declare function loadConfigFile(customConfigFile?: string): Promise<
|
|
3
|
-
|
|
4
|
-
configFilePath: string;
|
|
5
|
-
}>;
|
|
3
|
+
export declare function loadConfigFile(customConfigFile?: string): Promise<LoadConfigResult<UserConfig>>;
|
|
4
|
+
export declare function normalizeConfigResult(config: UserConfig | LoadConfigResult<UserConfig>, configFilePath?: string): LoadConfigResult<UserConfig>;
|
|
6
5
|
export declare function resolveDocRoot(cwd: string, cliRoot?: string, configRoot?: string): string;
|
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
|
|
1
|
+
import { node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../o~0.js";
|
|
3
2
|
async function loadConfigFile(customConfigFile) {
|
|
4
|
-
const baseDir = process.cwd();
|
|
5
|
-
const configFilePath = customConfigFile ? node_path.isAbsolute(customConfigFile) ? customConfigFile : node_path.join(baseDir, customConfigFile) : findConfig(node_path.join(baseDir, DEFAULT_CONFIG_NAME));
|
|
6
|
-
if (!configFilePath) {
|
|
7
|
-
logger.info(`No config file found in ${baseDir}`);
|
|
8
|
-
return {
|
|
9
|
-
config: {},
|
|
10
|
-
configFilePath: ''
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
3
|
const { loadConfig } = await import("@rsbuild/core");
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
const result = await loadConfig({
|
|
5
|
+
path: customConfigFile,
|
|
6
|
+
configFileNames: DEFAULT_CONFIG_EXTENSIONS.map((ext)=>DEFAULT_CONFIG_NAME + ext)
|
|
17
7
|
});
|
|
8
|
+
if (!result.filePath) logger.info(`No config file found in ${process.cwd()}`);
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
function normalizeConfigResult(config, configFilePath) {
|
|
12
|
+
if ('content' in config && 'filePath' in config && 'dependencies' in config) return config;
|
|
18
13
|
return {
|
|
19
|
-
|
|
20
|
-
configFilePath
|
|
14
|
+
content: config,
|
|
15
|
+
filePath: configFilePath || null,
|
|
16
|
+
dependencies: []
|
|
21
17
|
};
|
|
22
18
|
}
|
|
23
19
|
function resolveDocRoot(cwd, cliRoot, configRoot) {
|
|
@@ -25,4 +21,4 @@ function resolveDocRoot(cwd, cliRoot, configRoot) {
|
|
|
25
21
|
if (configRoot) return node_path.isAbsolute(configRoot) ? configRoot : node_path.join(cwd, configRoot);
|
|
26
22
|
return node_path.join(cwd, 'docs');
|
|
27
23
|
}
|
|
28
|
-
export { loadConfigFile, resolveDocRoot };
|
|
24
|
+
export { loadConfigFile, normalizeConfigResult, resolveDocRoot };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
export { default as github_slugger, slug } from "@rspress/shared/github-slugger";
|
|
2
2
|
export { extractTextAndId } from "@rspress/shared/node-utils";
|
|
3
3
|
export { visitChildren } from "unist-util-visit-children";
|
|
4
|
-
export { default as node_os } from "node:os";
|
|
5
|
-
export { default as node_path } from "node:path";
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { IconClose, Link, mergeRefs, SvgWrapper } from '@rspress/core/theme';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import { forwardRef, type ReactNode, useEffect, useState } from 'react';
|
|
3
|
+
import { forwardRef, type ReactNode, useEffect, useId, useState } from 'react';
|
|
4
4
|
import './index.scss';
|
|
5
5
|
|
|
6
|
+
const inlineStorageScript = `(function () {
|
|
7
|
+
var script = document.currentScript;
|
|
8
|
+
if (!script) return;
|
|
9
|
+
try {
|
|
10
|
+
var storage = window[script.dataset.rpBannerStorage];
|
|
11
|
+
var storageKey = script.dataset.rpBannerStorageKey;
|
|
12
|
+
var hiddenClass = script.dataset.rpBannerHiddenClass;
|
|
13
|
+
if (storage && storageKey && hiddenClass && storage.getItem(storageKey)) {
|
|
14
|
+
document.documentElement.classList.add(hiddenClass);
|
|
15
|
+
}
|
|
16
|
+
} catch (e) {}
|
|
17
|
+
})();`;
|
|
18
|
+
|
|
6
19
|
export type BannerProps = {
|
|
7
20
|
/**
|
|
8
21
|
* @default true
|
|
@@ -71,6 +84,7 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
|
|
|
71
84
|
storage?: 'localStorage' | 'sessionStorage' | false;
|
|
72
85
|
customChildren?: ReactNode;
|
|
73
86
|
};
|
|
87
|
+
const isCustom = 'customChildren' in props;
|
|
74
88
|
|
|
75
89
|
const [height, setHeight] = useState(36);
|
|
76
90
|
const ref = mergeRefs(forwardedRef, element => {
|
|
@@ -79,14 +93,27 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
|
|
|
79
93
|
}
|
|
80
94
|
});
|
|
81
95
|
const [disable, setDisable] = useState(false);
|
|
96
|
+
const bannerId = useId().replace(/[^a-zA-Z0-9_-]/g, '');
|
|
97
|
+
const bannerClass = `rp-banner-${bannerId}`;
|
|
98
|
+
const hiddenClass = `${bannerClass}-hidden`;
|
|
82
99
|
|
|
83
|
-
// TODO: support SSR
|
|
84
100
|
useEffect(() => {
|
|
85
|
-
|
|
86
|
-
|
|
101
|
+
let isDisabled = false;
|
|
102
|
+
if (!isCustom && typeof window !== 'undefined' && storage && storageKey) {
|
|
103
|
+
try {
|
|
104
|
+
isDisabled = Boolean(window[storage].getItem(storageKey));
|
|
105
|
+
} catch {
|
|
106
|
+
isDisabled = false;
|
|
107
|
+
}
|
|
87
108
|
}
|
|
88
|
-
|
|
89
|
-
|
|
109
|
+
|
|
110
|
+
document.documentElement.classList.toggle(hiddenClass, isDisabled);
|
|
111
|
+
setDisable(isDisabled);
|
|
112
|
+
|
|
113
|
+
return () => {
|
|
114
|
+
document.documentElement.classList.remove(hiddenClass);
|
|
115
|
+
};
|
|
116
|
+
}, [hiddenClass, isCustom, storage, storageKey]);
|
|
90
117
|
|
|
91
118
|
if (!display || disable) {
|
|
92
119
|
return null;
|
|
@@ -94,7 +121,17 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
|
|
|
94
121
|
|
|
95
122
|
return (
|
|
96
123
|
<>
|
|
97
|
-
|
|
124
|
+
{!isCustom && storage && storageKey ? (
|
|
125
|
+
<script
|
|
126
|
+
data-rp-banner-hidden-class={hiddenClass}
|
|
127
|
+
data-rp-banner-storage={storage}
|
|
128
|
+
data-rp-banner-storage-key={storageKey}
|
|
129
|
+
suppressHydrationWarning
|
|
130
|
+
dangerouslySetInnerHTML={{ __html: inlineStorageScript }}
|
|
131
|
+
/>
|
|
132
|
+
) : null}
|
|
133
|
+
<style>{`:root {--rp-banner-height: ${height}px;} :root.${hiddenClass} {--rp-banner-height: 0px;} :root.${hiddenClass} .${bannerClass} {display: none;}`}</style>
|
|
134
|
+
<div className={clsx('rp-banner', bannerClass, className)} ref={ref}>
|
|
98
135
|
{customChildren ?? (
|
|
99
136
|
<>
|
|
100
137
|
<Link
|
|
@@ -107,9 +144,14 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
|
|
|
107
144
|
<SvgWrapper
|
|
108
145
|
icon={IconClose}
|
|
109
146
|
onClick={() => {
|
|
147
|
+
document.documentElement.classList.add(hiddenClass);
|
|
110
148
|
setDisable(true);
|
|
111
149
|
if (storage) {
|
|
112
|
-
|
|
150
|
+
try {
|
|
151
|
+
window[storage].setItem(storageKey, 'true');
|
|
152
|
+
} catch {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
113
155
|
}
|
|
114
156
|
}}
|
|
115
157
|
className="rp-banner__close"
|
|
@@ -117,7 +159,6 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
|
|
|
117
159
|
</>
|
|
118
160
|
)}
|
|
119
161
|
</div>
|
|
120
|
-
<style>{`:root {--rp-banner-height: ${height}px;}`}</style>
|
|
121
162
|
</>
|
|
122
163
|
);
|
|
123
164
|
},
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, it, rs } from '@rstest/core';
|
|
2
|
+
import { getHref } from './getHref';
|
|
3
|
+
|
|
4
|
+
rs.mock('virtual-site-data', () => ({
|
|
5
|
+
default: {
|
|
6
|
+
base: '/docs/',
|
|
7
|
+
route: {
|
|
8
|
+
cleanUrls: true,
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
describe('getHref', () => {
|
|
14
|
+
it('preserves search and hash for an internal link with a base', () => {
|
|
15
|
+
expect(getHref('/guide?tab=api#install')).toEqual({
|
|
16
|
+
linkType: 'internal',
|
|
17
|
+
withBaseHref: '/docs/guide?tab=api#install',
|
|
18
|
+
removeBaseHref: '/guide?tab=api#install',
|
|
19
|
+
routePath: '/guide',
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('preserves search and hash when resolving a relative link', () => {
|
|
24
|
+
expect(
|
|
25
|
+
getHref('./guide?tab=api#install', 'https://example.com/docs/source'),
|
|
26
|
+
).toEqual({
|
|
27
|
+
linkType: 'relative',
|
|
28
|
+
withBaseHref: '/docs/guide?tab=api#install',
|
|
29
|
+
removeBaseHref: '/guide?tab=api#install',
|
|
30
|
+
routePath: '/guide',
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { cleanUrl, isExternalUrl } from '@rspress/shared';
|
|
2
|
+
import { cleanUrlByConfig, removeBase, withBase } from '../../../runtime/utils';
|
|
3
|
+
|
|
4
|
+
type LinkType = 'external' | 'hashOnly' | 'relative' | 'internal';
|
|
5
|
+
|
|
6
|
+
function isAbsoluteUrl(url: string): boolean {
|
|
7
|
+
return url.startsWith('/');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function getLinkType(href: string): LinkType {
|
|
11
|
+
if (isExternalUrl(href)) {
|
|
12
|
+
return 'external';
|
|
13
|
+
}
|
|
14
|
+
if (href.startsWith('#')) {
|
|
15
|
+
return 'hashOnly';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (!isAbsoluteUrl(href)) {
|
|
19
|
+
return 'relative';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return 'internal';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function getHref(
|
|
26
|
+
href: string,
|
|
27
|
+
currentUrl = typeof window === 'undefined' ? undefined : window.location.href,
|
|
28
|
+
): {
|
|
29
|
+
withBaseHref: string;
|
|
30
|
+
removeBaseHref: string;
|
|
31
|
+
routePath: string;
|
|
32
|
+
linkType: LinkType;
|
|
33
|
+
} {
|
|
34
|
+
let withBaseHref;
|
|
35
|
+
const linkType = getLinkType(href);
|
|
36
|
+
|
|
37
|
+
if (linkType === 'external' || linkType === 'hashOnly') {
|
|
38
|
+
return {
|
|
39
|
+
linkType,
|
|
40
|
+
withBaseHref: href,
|
|
41
|
+
removeBaseHref: href,
|
|
42
|
+
routePath: cleanUrl(href),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (linkType === 'relative' && currentUrl) {
|
|
47
|
+
const url = new URL(href, currentUrl);
|
|
48
|
+
withBaseHref = `${url.pathname}${url.search}${url.hash}`;
|
|
49
|
+
} else {
|
|
50
|
+
withBaseHref = withBase(cleanUrlByConfig(href));
|
|
51
|
+
}
|
|
52
|
+
const removeBaseHref = removeBase(withBaseHref);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
withBaseHref,
|
|
56
|
+
removeBaseHref,
|
|
57
|
+
routePath: cleanUrl(removeBaseHref),
|
|
58
|
+
linkType,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -5,7 +5,8 @@ import type React from 'react';
|
|
|
5
5
|
import type { ComponentProps, TransitionStartFunction } from 'react';
|
|
6
6
|
import { forwardRef } from 'react';
|
|
7
7
|
import './index.scss';
|
|
8
|
-
import { getHref
|
|
8
|
+
import { getHref } from './getHref';
|
|
9
|
+
import { useLinkNavigate } from './useLinkNavigate';
|
|
9
10
|
|
|
10
11
|
export interface LinkProps extends ComponentProps<'a'> {
|
|
11
12
|
href?: string;
|
|
@@ -55,7 +56,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
|
|
|
55
56
|
...otherProps
|
|
56
57
|
} = props;
|
|
57
58
|
|
|
58
|
-
const { linkType, removeBaseHref, withBaseHref } = getHref(href);
|
|
59
|
+
const { linkType, removeBaseHref, routePath, withBaseHref } = getHref(href);
|
|
59
60
|
const navigate = useLinkNavigate({ startTransition });
|
|
60
61
|
|
|
61
62
|
if (linkType === 'external') {
|
|
@@ -98,10 +99,10 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
|
|
|
98
99
|
className={clsx(className, 'rp-link')}
|
|
99
100
|
onMouseEnter={event => {
|
|
100
101
|
onMouseEnter?.(event);
|
|
101
|
-
preloadLink(
|
|
102
|
+
preloadLink(routePath);
|
|
102
103
|
}}
|
|
103
104
|
onTouchStart={() => {
|
|
104
|
-
preloadLink(
|
|
105
|
+
preloadLink(routePath);
|
|
105
106
|
}}
|
|
106
107
|
onClick={e => {
|
|
107
108
|
onClick?.(e);
|
|
@@ -135,10 +136,10 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
|
|
|
135
136
|
className={clsx(className, 'rp-link')}
|
|
136
137
|
onMouseEnter={event => {
|
|
137
138
|
onMouseEnter?.(event);
|
|
138
|
-
preloadLink(
|
|
139
|
+
preloadLink(routePath);
|
|
139
140
|
}}
|
|
140
141
|
onTouchStart={() => {
|
|
141
|
-
preloadLink(
|
|
142
|
+
preloadLink(routePath);
|
|
142
143
|
}}
|
|
143
144
|
onClick={e => {
|
|
144
145
|
onClick?.(e);
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
cleanUrlByConfig,
|
|
3
2
|
initPageData,
|
|
4
3
|
isActive,
|
|
5
|
-
isExternalUrl,
|
|
6
4
|
pathnameToRouteService,
|
|
7
|
-
removeBase,
|
|
8
5
|
useLocation,
|
|
9
6
|
useNavigate as useNavigateInner,
|
|
10
7
|
useSite,
|
|
11
8
|
warmPageData,
|
|
12
|
-
withBase,
|
|
13
9
|
} from '@rspress/core/runtime';
|
|
14
10
|
import nprogress from 'nprogress';
|
|
15
11
|
import {
|
|
@@ -17,52 +13,10 @@ import {
|
|
|
17
13
|
type TransitionStartFunction,
|
|
18
14
|
useCallback,
|
|
19
15
|
} from 'react';
|
|
16
|
+
import { getHref } from './getHref';
|
|
20
17
|
|
|
21
18
|
nprogress.configure({ showSpinner: false });
|
|
22
19
|
|
|
23
|
-
function isAbsoluteUrl(url: string): boolean {
|
|
24
|
-
return url.startsWith('/');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
type LinkType = 'external' | 'hashOnly' | 'relative' | 'internal';
|
|
28
|
-
|
|
29
|
-
function getLinkType(href: string): LinkType {
|
|
30
|
-
if (isExternalUrl(href)) {
|
|
31
|
-
return 'external';
|
|
32
|
-
}
|
|
33
|
-
if (href.startsWith('#')) {
|
|
34
|
-
return 'hashOnly';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!isAbsoluteUrl(href)) {
|
|
38
|
-
return 'relative';
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return 'internal';
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function getHref(href: string): {
|
|
45
|
-
withBaseHref: string;
|
|
46
|
-
removeBaseHref: string;
|
|
47
|
-
linkType: LinkType;
|
|
48
|
-
} {
|
|
49
|
-
let withBaseHref;
|
|
50
|
-
const linkType = getLinkType(href);
|
|
51
|
-
|
|
52
|
-
if (linkType === 'external' || linkType === 'hashOnly') {
|
|
53
|
-
return { linkType: linkType, withBaseHref: href, removeBaseHref: href };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (linkType === 'relative' && !import.meta.env.SSR) {
|
|
57
|
-
withBaseHref = new URL(href, window.location.href).pathname;
|
|
58
|
-
} else {
|
|
59
|
-
withBaseHref = withBase(cleanUrlByConfig(href));
|
|
60
|
-
}
|
|
61
|
-
const removeBaseHref = removeBase(withBaseHref);
|
|
62
|
-
|
|
63
|
-
return { withBaseHref, removeBaseHref, linkType };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
20
|
/**
|
|
67
21
|
* For import { Link } from '@rspress/core/theme';
|
|
68
22
|
* useNavigate with preload logic
|
|
@@ -81,7 +35,8 @@ export function useLinkNavigate(
|
|
|
81
35
|
|
|
82
36
|
return useCallback(
|
|
83
37
|
async (href: string) => {
|
|
84
|
-
const { linkType, removeBaseHref, withBaseHref } =
|
|
38
|
+
const { linkType, removeBaseHref, routePath, withBaseHref } =
|
|
39
|
+
getHref(href);
|
|
85
40
|
if (linkType === 'external' || linkType === 'hashOnly') {
|
|
86
41
|
window.location.assign(href);
|
|
87
42
|
return;
|
|
@@ -92,13 +47,13 @@ export function useLinkNavigate(
|
|
|
92
47
|
const inCurrPage = isActive(removeBaseHref, currPagePathname);
|
|
93
48
|
|
|
94
49
|
if (!import.meta.env.SSR && !inCurrPage) {
|
|
95
|
-
const matchedRoute = pathnameToRouteService(
|
|
50
|
+
const matchedRoute = pathnameToRouteService(routePath);
|
|
96
51
|
if (matchedRoute) {
|
|
97
52
|
const timer = setTimeout(() => {
|
|
98
53
|
nprogress.start();
|
|
99
54
|
}, 200);
|
|
100
|
-
const data = await initPageData(
|
|
101
|
-
warmPageData(
|
|
55
|
+
const data = await initPageData(routePath);
|
|
56
|
+
warmPageData(routePath, data);
|
|
102
57
|
clearTimeout(timer);
|
|
103
58
|
nprogress.done();
|
|
104
59
|
} else {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type React from 'react';
|
|
1
2
|
import { afterEach, describe, expect, it, rs } from '@rstest/core';
|
|
2
3
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
3
4
|
import { renderToMarkdownString } from 'react-render-to-markdown';
|
|
@@ -21,6 +22,7 @@ let page = defaultPage;
|
|
|
21
22
|
let site = defaultSite;
|
|
22
23
|
|
|
23
24
|
rs.mock('@rspress/core/runtime', () => ({
|
|
25
|
+
Head: ({ children }: { children?: React.ReactNode }) => <>{children}</>,
|
|
24
26
|
routePathToMdPath: (path: string) => `/docs${path}index.md`,
|
|
25
27
|
usePage: () => ({ page }),
|
|
26
28
|
useSite: () => ({ site }),
|
|
@@ -58,6 +60,12 @@ describe('LlmsHint', () => {
|
|
|
58
60
|
expect(html).toContain(
|
|
59
61
|
'For AI agents: the complete documentation index is available at https://example.com/docs/llms.txt, the full documentation bundle is available at https://example.com/docs/llms-full.txt, and this page is available as Markdown at https://example.com/docs/guide/index.md.',
|
|
60
62
|
);
|
|
63
|
+
expect(html).toContain(
|
|
64
|
+
'<link rel="alternate" type="text/markdown" href="https://example.com/docs/guide/index.md"/>',
|
|
65
|
+
);
|
|
66
|
+
expect(html).toContain(
|
|
67
|
+
'<link rel="describedby" href="https://example.com/docs/llms.txt"/>',
|
|
68
|
+
);
|
|
61
69
|
});
|
|
62
70
|
|
|
63
71
|
it('renders a blockquote string when SSG_MD is enabled', async () => {
|
|
@@ -4,7 +4,9 @@ import {
|
|
|
4
4
|
useSite,
|
|
5
5
|
withBase,
|
|
6
6
|
withSiteOrigin,
|
|
7
|
+
Head,
|
|
7
8
|
} from '@rspress/core/runtime';
|
|
9
|
+
|
|
8
10
|
import type React from 'react';
|
|
9
11
|
|
|
10
12
|
const visuallyHiddenStyle: React.CSSProperties = {
|
|
@@ -67,8 +69,14 @@ export function LlmsHint() {
|
|
|
67
69
|
});
|
|
68
70
|
|
|
69
71
|
return (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
<>
|
|
73
|
+
<Head>
|
|
74
|
+
<link rel="alternate" type="text/markdown" href={pageMdUrl} />
|
|
75
|
+
<link rel="describedby" href={llmsTxtUrl} />
|
|
76
|
+
</Head>
|
|
77
|
+
<div className="rp-llms-hint" style={visuallyHiddenStyle}>
|
|
78
|
+
{hintText}
|
|
79
|
+
</div>
|
|
80
|
+
</>
|
|
73
81
|
);
|
|
74
82
|
}
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
.rp-nav-menu {
|
|
2
|
+
--rp-nav-menu-item-gap: 32px;
|
|
3
|
+
|
|
2
4
|
display: inline-flex;
|
|
3
5
|
align-items: center;
|
|
4
6
|
height: 100%;
|
|
5
7
|
list-style: none;
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
&:empty {
|
|
10
|
+
display: none;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
@media (max-width: 1279px) {
|
|
12
|
-
gap: 24px;
|
|
14
|
+
--rp-nav-menu-item-gap: 24px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
&--left {
|
|
18
|
+
margin: 0 0 0 24px;
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
&__item {
|
|
@@ -26,6 +32,8 @@
|
|
|
26
32
|
align-items: center;
|
|
27
33
|
height: 100%;
|
|
28
34
|
gap: 4px;
|
|
35
|
+
padding: 0 calc(var(--rp-nav-menu-item-gap) / 2) 0
|
|
36
|
+
calc(var(--rp-nav-menu-item-gap) / 2);
|
|
29
37
|
|
|
30
38
|
// text
|
|
31
39
|
text-align: center;
|
|
@@ -35,6 +43,14 @@
|
|
|
35
43
|
line-height: 22px;
|
|
36
44
|
}
|
|
37
45
|
|
|
46
|
+
&:first-child > .rp-nav-menu__item__container {
|
|
47
|
+
padding-left: 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
&:last-child > .rp-nav-menu__item__container {
|
|
51
|
+
padding-right: 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
38
54
|
&__icon {
|
|
39
55
|
display: flex;
|
|
40
56
|
justify-content: center;
|
|
@@ -15,9 +15,9 @@ import {
|
|
|
15
15
|
} from '@rspress/core/theme';
|
|
16
16
|
import cls from 'clsx';
|
|
17
17
|
import { type ReactNode, useMemo } from 'react';
|
|
18
|
+
import { NavListContext } from '../NavList/context';
|
|
18
19
|
import { useLangsMenu, useVersionsMenu } from './hooks';
|
|
19
20
|
import './NavMenu.scss';
|
|
20
|
-
import clsx from 'clsx';
|
|
21
21
|
|
|
22
22
|
export const SvgDown = (props: React.SVGProps<SVGSVGElement>) => {
|
|
23
23
|
return <SvgWrapper icon={IconArrowDown} {...props} />;
|
|
@@ -168,25 +168,32 @@ export function NavVersions() {
|
|
|
168
168
|
export function NavMenu({
|
|
169
169
|
menuItems,
|
|
170
170
|
position,
|
|
171
|
+
beforeNavItems,
|
|
172
|
+
afterNavItems,
|
|
171
173
|
}: {
|
|
172
174
|
menuItems: NavItem[];
|
|
173
|
-
position
|
|
175
|
+
position?: 'left' | 'right';
|
|
176
|
+
beforeNavItems?: ReactNode;
|
|
177
|
+
afterNavItems?: ReactNode;
|
|
174
178
|
}) {
|
|
175
|
-
const
|
|
179
|
+
const items = useMemo(() => {
|
|
180
|
+
return position
|
|
181
|
+
? menuItems.filter(item => (item.position ?? 'right') === position)
|
|
182
|
+
: menuItems;
|
|
183
|
+
}, [menuItems, position]);
|
|
176
184
|
|
|
177
|
-
|
|
178
|
-
return menuItems.filter(item => getPosition(item) === position);
|
|
179
|
-
}, [menuItems]);
|
|
180
|
-
|
|
181
|
-
if (leftOrRightMenuItems.length === 0) {
|
|
185
|
+
if (!items.length && beforeNavItems == null && afterNavItems == null)
|
|
182
186
|
return null;
|
|
183
|
-
}
|
|
184
187
|
|
|
185
188
|
return (
|
|
186
|
-
<ul className={
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
189
|
+
<ul className={cls('rp-nav-menu', position && `rp-nav-menu--${position}`)}>
|
|
190
|
+
<NavListContext.Provider value="items">
|
|
191
|
+
{beforeNavItems}
|
|
192
|
+
{items.map((item, index) => (
|
|
193
|
+
<NavMenuItem key={index} menuItem={item} />
|
|
194
|
+
))}
|
|
195
|
+
{afterNavItems}
|
|
196
|
+
</NavListContext.Provider>
|
|
190
197
|
</ul>
|
|
191
198
|
);
|
|
192
199
|
}
|