@rspress/core 2.0.16 → 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/Link/index.tsx +1 -1
- package/dist/eject-theme/components/Link/useLinkNavigate.ts +17 -4
- 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/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/ClientApp.js +3 -2
- package/dist/runtime/route.js +2 -0
- 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/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 +9 -9
- 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
package/dist/cli/index.d.ts
CHANGED
package/dist/cli/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __webpack_require__ } from "../0~rslib-runtime.js";
|
|
2
|
-
import { node_path, logger, join, cac } from "../
|
|
3
|
-
import "../
|
|
4
|
-
import { package_namespaceObject } from "../
|
|
2
|
+
import { node_path, logger, join, cac } from "../8629.js";
|
|
3
|
+
import "../4538.js";
|
|
4
|
+
import { package_namespaceObject } from "../7448.js";
|
|
5
5
|
import { loadConfigFile, resolveDocRoot } from "../config/loadConfigFile.js";
|
|
6
6
|
import { dev } from "../node/dev.js";
|
|
7
7
|
import { build } from "../node/build.js";
|
|
@@ -14,115 +14,118 @@ const META_FILES = [
|
|
|
14
14
|
'_meta.json',
|
|
15
15
|
'_nav.json'
|
|
16
16
|
];
|
|
17
|
-
const cli = cac('rspress').version(package_namespaceObject.rE).help();
|
|
18
|
-
const landingMessage = `🔥 Rspress v${package_namespaceObject.rE}\n`;
|
|
19
|
-
logger.greet(landingMessage);
|
|
20
17
|
const setNodeEnv = (env)=>{
|
|
21
18
|
process.env.NODE_ENV = env;
|
|
22
19
|
};
|
|
23
|
-
|
|
24
|
-
cli
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
config
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
20
|
+
function runCLI({ argv = process.argv } = {}) {
|
|
21
|
+
const cli = cac('rspress').version(package_namespaceObject.rE).help();
|
|
22
|
+
const landingMessage = `🔥 Rspress v${package_namespaceObject.rE}\n`;
|
|
23
|
+
logger.greet(landingMessage);
|
|
24
|
+
cli.option('-c, --config <config>', 'Set the configuration file (relative or absolute path)');
|
|
25
|
+
cli.command('[root]', 'Start the dev server').alias('dev').option('--port <port>', 'Set the port number for the server').option('--host [host]', 'Set the host that the server listens to').option('--base <base>', 'Set the base path and override config.base').action(async (root, options)=>{
|
|
26
|
+
setNodeEnv('development');
|
|
27
|
+
let isRestarting = false;
|
|
28
|
+
const cwd = process.cwd();
|
|
29
|
+
let cliWatcher;
|
|
30
|
+
let devServer;
|
|
31
|
+
const startDevServer = async ()=>{
|
|
32
|
+
const { port, host } = options || {};
|
|
33
|
+
const { config, configFilePath } = await loadConfigFile(options?.config);
|
|
34
|
+
config.root = resolveDocRoot(cwd, root, config.root);
|
|
35
|
+
if (options?.base) config.base = options.base;
|
|
36
|
+
const docDirectory = config.root;
|
|
37
|
+
devServer = await dev({
|
|
38
|
+
appDirectory: cwd,
|
|
39
|
+
docDirectory,
|
|
40
|
+
config,
|
|
41
|
+
configFilePath,
|
|
42
|
+
extraBuilderConfig: {
|
|
43
|
+
server: {
|
|
44
|
+
port,
|
|
45
|
+
host
|
|
46
|
+
}
|
|
45
47
|
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
48
|
+
});
|
|
49
|
+
cliWatcher = chokidar.w([
|
|
50
|
+
configFilePath,
|
|
51
|
+
docDirectory
|
|
52
|
+
], {
|
|
53
|
+
ignoreInitial: true,
|
|
54
|
+
ignored: [
|
|
55
|
+
'**/node_modules/**',
|
|
56
|
+
'**/.git/**',
|
|
57
|
+
'**/.DS_Store/**',
|
|
58
|
+
join(docDirectory, "public")
|
|
59
|
+
]
|
|
60
|
+
});
|
|
61
|
+
cliWatcher.on('all', async (eventName, filepath)=>{
|
|
62
|
+
const basename = node_path.basename(filepath);
|
|
63
|
+
if ('change' === eventName && META_FILES.includes(basename)) return;
|
|
64
|
+
if ('add' === eventName || 'unlink' === eventName || 'change' === eventName && filepath === configFilePath) {
|
|
65
|
+
if (isRestarting) return;
|
|
66
|
+
isRestarting = true;
|
|
67
|
+
console.log(`\n✨ ${eventName} ${picocolors_default().green(node_path.relative(cwd, filepath))}, dev server will restart...\n`);
|
|
68
|
+
await devServer.close();
|
|
69
|
+
await cliWatcher.close();
|
|
70
|
+
await startDevServer();
|
|
71
|
+
isRestarting = false;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
await startDevServer();
|
|
76
|
+
const exitProcess = async ()=>{
|
|
77
|
+
try {
|
|
67
78
|
await devServer.close();
|
|
68
79
|
await cliWatcher.close();
|
|
69
|
-
|
|
70
|
-
|
|
80
|
+
} finally{
|
|
81
|
+
process.exit(0);
|
|
71
82
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
};
|
|
84
|
+
process.on('SIGINT', exitProcess);
|
|
85
|
+
process.on('SIGTERM', exitProcess);
|
|
86
|
+
});
|
|
87
|
+
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)=>{
|
|
88
|
+
setNodeEnv('production');
|
|
89
|
+
const cwd = process.cwd();
|
|
90
|
+
const { config, configFilePath } = await loadConfigFile(options.config);
|
|
91
|
+
config.root = resolveDocRoot(cwd, root, config.root);
|
|
92
|
+
if (options.base) config.base = options.base;
|
|
93
|
+
const docDirectory = config.root;
|
|
76
94
|
try {
|
|
77
|
-
await
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
95
|
+
await build({
|
|
96
|
+
docDirectory,
|
|
97
|
+
config,
|
|
98
|
+
configFilePath
|
|
99
|
+
});
|
|
100
|
+
} catch (err) {
|
|
101
|
+
logger.error(err);
|
|
102
|
+
process.exit(1);
|
|
81
103
|
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (options.base) config.base = options.base;
|
|
92
|
-
const docDirectory = config.root;
|
|
93
|
-
try {
|
|
94
|
-
await build({
|
|
95
|
-
docDirectory,
|
|
104
|
+
});
|
|
105
|
+
cli.command('preview [root]', 'Preview the production build locally').alias('serve').option('--port <port>', 'Set the port number for the server').option('--host [host]', 'Set the host that the server listens to').option('--base <base>', 'Set the base path and override config.base').action(async (root, options)=>{
|
|
106
|
+
setNodeEnv('production');
|
|
107
|
+
const cwd = process.cwd();
|
|
108
|
+
const { port, host } = options || {};
|
|
109
|
+
const { config, configFilePath } = await loadConfigFile(options?.config);
|
|
110
|
+
config.root = resolveDocRoot(cwd, root, config.root);
|
|
111
|
+
if (options?.base) config.base = options.base;
|
|
112
|
+
await serve({
|
|
96
113
|
config,
|
|
114
|
+
host,
|
|
115
|
+
port,
|
|
97
116
|
configFilePath
|
|
98
117
|
});
|
|
99
|
-
} catch (err) {
|
|
100
|
-
logger.error(err);
|
|
101
|
-
process.exit(1);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
cli.command('preview [root]', 'Preview the production build locally').alias('serve').option('--port <port>', 'Set the port number for the server').option('--host [host]', 'Set the host that the server listens to').option('--base <base>', 'Set the base path and override config.base').action(async (root, options)=>{
|
|
105
|
-
setNodeEnv('production');
|
|
106
|
-
const cwd = process.cwd();
|
|
107
|
-
const { port, host } = options || {};
|
|
108
|
-
const { config, configFilePath } = await loadConfigFile(options?.config);
|
|
109
|
-
config.root = resolveDocRoot(cwd, root, config.root);
|
|
110
|
-
if (options?.base) config.base = options.base;
|
|
111
|
-
await serve({
|
|
112
|
-
config,
|
|
113
|
-
host,
|
|
114
|
-
port,
|
|
115
|
-
configFilePath
|
|
116
118
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
119
|
+
cli.command('eject [component]', 'Eject a theme component for customization').action(async (component)=>{
|
|
120
|
+
if (!component) return void await listComponents();
|
|
121
|
+
const cwd = process.cwd();
|
|
122
|
+
try {
|
|
123
|
+
await ejectComponent(component, cwd);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
logger.error(`Failed to eject component: ${error}`);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
cli.parse(argv);
|
|
130
|
+
}
|
|
131
|
+
export { runCLI };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { node_fs, node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../
|
|
1
|
+
import { node_fs, node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../8629.js";
|
|
2
2
|
const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
|
|
3
3
|
async function loadConfigFile(customConfigFile) {
|
|
4
4
|
const baseDir = process.cwd();
|
|
@@ -41,7 +41,7 @@ nprogress.configure({ showSpinner: false });
|
|
|
41
41
|
* Link can tell whether it's in current site or external site.
|
|
42
42
|
* 1. If external, open a new page and navigate to it.
|
|
43
43
|
* 2. If inCurrentPage, scroll to anchor.
|
|
44
|
-
* 3. If inCurrentSite, it will navigate and scroll to anchor,
|
|
44
|
+
* 3. If inCurrentSite, it will navigate and scroll to anchor, prefetch route resources when hovering over the link.
|
|
45
45
|
* 4. Link is styled.
|
|
46
46
|
*/
|
|
47
47
|
export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
removeBase,
|
|
8
8
|
useLocation,
|
|
9
9
|
useNavigate as useNavigateInner,
|
|
10
|
+
useSite,
|
|
10
11
|
warmPageData,
|
|
11
12
|
withBase,
|
|
12
13
|
} from '@rspress/core/runtime';
|
|
@@ -67,12 +68,16 @@ export function getHref(href: string): {
|
|
|
67
68
|
* useNavigate with preload logic
|
|
68
69
|
*/
|
|
69
70
|
export function useLinkNavigate(
|
|
70
|
-
{
|
|
71
|
+
{
|
|
72
|
+
startTransition = reactStartTransition,
|
|
73
|
+
}: { startTransition?: TransitionStartFunction } = {
|
|
71
74
|
startTransition: reactStartTransition,
|
|
72
75
|
},
|
|
73
76
|
): (href: string) => Promise<void> {
|
|
74
77
|
const { pathname: currPagePathname } = useLocation();
|
|
75
78
|
const navigate = useNavigateInner();
|
|
79
|
+
const { site } = useSite();
|
|
80
|
+
const useTransitions = site?.route?.useTransitions;
|
|
76
81
|
|
|
77
82
|
return useCallback(
|
|
78
83
|
async (href: string) => {
|
|
@@ -82,8 +87,10 @@ export function useLinkNavigate(
|
|
|
82
87
|
return;
|
|
83
88
|
}
|
|
84
89
|
|
|
90
|
+
const isTransitionable = !!(useTransitions && startTransition);
|
|
85
91
|
const preloadChunkThenNavigate = async () => {
|
|
86
92
|
const inCurrPage = isActive(removeBaseHref, currPagePathname);
|
|
93
|
+
|
|
87
94
|
if (!import.meta.env.SSR && !inCurrPage) {
|
|
88
95
|
const matchedRoute = pathnameToRouteService(removeBaseHref);
|
|
89
96
|
if (matchedRoute) {
|
|
@@ -99,15 +106,21 @@ export function useLinkNavigate(
|
|
|
99
106
|
return;
|
|
100
107
|
}
|
|
101
108
|
}
|
|
102
|
-
|
|
109
|
+
if (isTransitionable) {
|
|
110
|
+
startTransition(() => {
|
|
111
|
+
return navigate(removeBaseHref, { replace: false });
|
|
112
|
+
});
|
|
113
|
+
} else {
|
|
114
|
+
navigate(removeBaseHref, { replace: false });
|
|
115
|
+
}
|
|
103
116
|
};
|
|
104
117
|
|
|
105
|
-
if (
|
|
118
|
+
if (isTransitionable) {
|
|
106
119
|
startTransition(preloadChunkThenNavigate);
|
|
107
120
|
} else {
|
|
108
121
|
preloadChunkThenNavigate();
|
|
109
122
|
}
|
|
110
123
|
},
|
|
111
|
-
[currPagePathname, navigate],
|
|
124
|
+
[useTransitions, currPagePathname, navigate, startTransition],
|
|
112
125
|
);
|
|
113
126
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from '@rstest/core';
|
|
2
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
3
|
+
import { GithubStars } from './GithubStars';
|
|
4
|
+
|
|
5
|
+
const originalLocalStorage = Object.getOwnPropertyDescriptor(
|
|
6
|
+
globalThis,
|
|
7
|
+
'localStorage',
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
if (originalLocalStorage) {
|
|
12
|
+
Object.defineProperty(globalThis, 'localStorage', originalLocalStorage);
|
|
13
|
+
} else {
|
|
14
|
+
Reflect.deleteProperty(globalThis, 'localStorage');
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
function mockLocalStorage(cache: Record<string, string>) {
|
|
19
|
+
Object.defineProperty(globalThis, 'localStorage', {
|
|
20
|
+
configurable: true,
|
|
21
|
+
value: {
|
|
22
|
+
getItem: (key: string) => cache[key] ?? null,
|
|
23
|
+
setItem: () => {},
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('GithubStars', () => {
|
|
29
|
+
it('does not render cached stars during the first render', () => {
|
|
30
|
+
mockLocalStorage({
|
|
31
|
+
'rp-github-stars:web-infra-dev/rspress': JSON.stringify({
|
|
32
|
+
count: 12345,
|
|
33
|
+
fetchedAt: Date.now(),
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const markup = renderToStaticMarkup(
|
|
38
|
+
<GithubStars
|
|
39
|
+
content="https://github.com/web-infra-dev/rspress"
|
|
40
|
+
icon={<span data-icon="github" />}
|
|
41
|
+
/>,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(markup).not.toContain('rp-social-links__github-stars-count');
|
|
45
|
+
expect(markup).not.toContain('12.3K');
|
|
46
|
+
expect(markup).toContain('aria-label="GitHub repository"');
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ReactNode, useEffect, useState } from 'react';
|
|
2
|
+
import { useStorageValue } from '../../logic/useStorageValue';
|
|
2
3
|
|
|
3
4
|
const TTL_MS = 60 * 60 * 1000;
|
|
4
5
|
|
|
@@ -21,10 +22,8 @@ function parseRepo(content: string): string | null {
|
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
function
|
|
25
|
-
if (typeof localStorage === 'undefined') return null;
|
|
25
|
+
function parseCache(raw: string | null): Cached | null {
|
|
26
26
|
try {
|
|
27
|
-
const raw = localStorage.getItem(storageKey(repo));
|
|
28
27
|
if (!raw) return null;
|
|
29
28
|
const parsed = JSON.parse(raw) as Cached;
|
|
30
29
|
if (
|
|
@@ -39,16 +38,8 @@ function readCache(repo: string): Cached | null {
|
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
localStorage.setItem(
|
|
46
|
-
storageKey(repo),
|
|
47
|
-
JSON.stringify({ count, fetchedAt: Date.now() }),
|
|
48
|
-
);
|
|
49
|
-
} catch {
|
|
50
|
-
// Storage may be full or disabled (private mode); ignore.
|
|
51
|
-
}
|
|
41
|
+
function createCacheValue(count: number): string {
|
|
42
|
+
return JSON.stringify({ count, fetchedAt: Date.now() });
|
|
52
43
|
}
|
|
53
44
|
|
|
54
45
|
function formatCount(count: number): string {
|
|
@@ -70,14 +61,34 @@ export const GithubStars = (props: GithubStarsProps) => {
|
|
|
70
61
|
const { content, icon } = props;
|
|
71
62
|
const repo = parseRepo(content);
|
|
72
63
|
|
|
73
|
-
const [
|
|
74
|
-
repo ? (
|
|
64
|
+
const [rawCache, setRawCache] = useStorageValue<string | null>(
|
|
65
|
+
repo ? storageKey(repo) : '',
|
|
66
|
+
null,
|
|
75
67
|
);
|
|
68
|
+
const [isMounted, setIsMounted] = useState(false);
|
|
69
|
+
const [count, setCount] = useState<number | null>(null);
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
setIsMounted(true);
|
|
73
|
+
}, []);
|
|
76
74
|
|
|
77
75
|
useEffect(() => {
|
|
78
|
-
if (!repo)
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
if (!repo) {
|
|
77
|
+
setCount(null);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!isMounted) return;
|
|
82
|
+
|
|
83
|
+
const cached = parseCache(rawCache);
|
|
84
|
+
if (cached) {
|
|
85
|
+
setCount(cached.count);
|
|
86
|
+
if (Date.now() - cached.fetchedAt < TTL_MS) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
setCount(null);
|
|
91
|
+
}
|
|
81
92
|
|
|
82
93
|
let cancelled = false;
|
|
83
94
|
fetch(`https://api.github.com/repos/${repo}`)
|
|
@@ -86,7 +97,11 @@ export const GithubStars = (props: GithubStarsProps) => {
|
|
|
86
97
|
if (cancelled) return;
|
|
87
98
|
if (typeof data?.stargazers_count === 'number') {
|
|
88
99
|
setCount(data.stargazers_count);
|
|
89
|
-
|
|
100
|
+
try {
|
|
101
|
+
setRawCache(createCacheValue(data.stargazers_count));
|
|
102
|
+
} catch {
|
|
103
|
+
// Storage may be full or disabled (private mode); ignore.
|
|
104
|
+
}
|
|
90
105
|
}
|
|
91
106
|
})
|
|
92
107
|
.catch(() => {
|
|
@@ -95,7 +110,7 @@ export const GithubStars = (props: GithubStarsProps) => {
|
|
|
95
110
|
return () => {
|
|
96
111
|
cancelled = true;
|
|
97
112
|
};
|
|
98
|
-
}, [repo]);
|
|
113
|
+
}, [isMounted, rawCache, repo, setRawCache]);
|
|
99
114
|
|
|
100
115
|
return (
|
|
101
116
|
<a
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export type { DarkMode, EditLink, Feature, FrontMatterMeta, Header, Hero, I18nText, LocalSearchOptions, Nav, NavItem, NavItemWithChildren, NavItemWithLink, NavItemWithLinkAndChildren, NormalizedSidebarGroup, PageIndexInfo, RemotePageInfo, RouteMeta, RspressPlugin, Sidebar, SidebarData, SidebarDivider, SidebarGroup, SidebarItem, SidebarSectionHeader, SocialLink, UserConfig, } from '@rspress/shared';
|
|
2
|
-
export { getSidebarDataGroup, normalizeHref, normalizePosixPath, RSPRESS_TEMP_DIR, removeTrailingSlash, withBase, } from '@rspress/shared';
|
|
2
|
+
export { getSidebarDataGroup, normalizeHref, normalizePosixPath, RSPRESS_TEMP_DIR, removeTrailingSlash, withBase, withSiteOrigin, } from '@rspress/shared';
|
|
3
3
|
export { logger } from '@rspress/shared/logger';
|
|
4
4
|
export { getIconUrlPath, getNodeAttribute, mergeDocConfig, } from '@rspress/shared/node-utils';
|
|
5
5
|
export { matchPath } from 'react-router-dom';
|
|
6
6
|
export type { UserConfigAsyncFn } from './config/defineConfig.js';
|
|
7
7
|
export { defineConfig } from './config/defineConfig.js';
|
|
8
|
+
export { type RunCLIOptions, runCLI } from './cli/index.js';
|
|
8
9
|
export { build, dev, remarkFileCodeBlock, remarkImage, remarkLink, serve, } from './node/index.js';
|
|
9
10
|
export type { CustomLinkMeta, DirSectionHeaderSideMeta, DirSideMeta, DividerSideMeta, FileSideMeta, MetaJson, NavJson, SectionHeaderMeta, SideMeta, SideMetaItem, } from './node/auto-nav-sidebar/type.js';
|
|
10
11
|
export { PluginDriver } from './node/PluginDriver.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { PluginDriver } from "./node/PluginDriver.js";
|
|
2
|
-
export { RSPRESS_TEMP_DIR, getIconUrlPath, getNodeAttribute, getSidebarDataGroup, logger, matchPath, mergeDocConfig, normalizeHref, normalizePosixPath, removeTrailingSlash, withBase } from "./
|
|
2
|
+
export { RSPRESS_TEMP_DIR, getIconUrlPath, getNodeAttribute, getSidebarDataGroup, logger, matchPath, mergeDocConfig, normalizeHref, normalizePosixPath, removeTrailingSlash, withBase, withSiteOrigin } from "./102.js";
|
|
3
3
|
export { RouteService } from "./node/route/RouteService.js";
|
|
4
4
|
export { build } from "./node/build.js";
|
|
5
5
|
export { defineConfig } from "./config/defineConfig.js";
|
|
@@ -7,4 +7,5 @@ export { dev } from "./node/dev.js";
|
|
|
7
7
|
export { remarkFileCodeBlock } from "./node/mdx/remarkPlugins/fileCodeBlock.js";
|
|
8
8
|
export { remarkImage } from "./node/mdx/remarkPlugins/image.js";
|
|
9
9
|
export { remarkLink } from "./node/mdx/remarkPlugins/link.js";
|
|
10
|
+
export { runCLI } from "./cli/index.js";
|
|
10
11
|
export { serve } from "./node/serve.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addTrailingSlash, node_path, addLeadingSlash } from "../
|
|
1
|
+
import { addTrailingSlash, node_path, addLeadingSlash } from "../8629.js";
|
|
2
2
|
import { createError } from "./utils/error.js";
|
|
3
3
|
import { haveNavSidebarConfig as auto_nav_sidebar_haveNavSidebarConfig } from "./auto-nav-sidebar/index.js";
|
|
4
4
|
class PluginDriver {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../
|
|
1
|
+
import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../8629.js";
|
|
2
2
|
import { processLocales, combineWalkResult } from "./locales.js";
|
|
3
3
|
import { walk } from "./walk.js";
|
|
4
4
|
async function runAutoNavSide(config, metaFileSet, mdFileSet) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __webpack_require__ } from "../../0~rslib-runtime.js";
|
|
2
|
-
import "../../
|
|
3
|
-
import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../
|
|
2
|
+
import "../../4538.js";
|
|
3
|
+
import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../8629.js";
|
|
4
4
|
import { createError } from "../utils/error.js";
|
|
5
5
|
import { pathExists, extractInfoFromFrontmatterWithAbsolutePath, readJson } from "./utils.js";
|
|
6
6
|
import { absolutePathToRoutePath, addRoutePrefix } from "../route/RoutePage.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../
|
|
1
|
+
import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../8629.js";
|
|
2
2
|
import { createError } from "../utils/error.js";
|
|
3
3
|
async function pathExists(path) {
|
|
4
4
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isExternalUrl, node_path, promises } from "../../
|
|
1
|
+
import { isExternalUrl, node_path, promises } from "../../8629.js";
|
|
2
2
|
import { pathExists } from "../utils/fs.js";
|
|
3
3
|
import { readJson } from "./utils.js";
|
|
4
4
|
import { addRoutePrefix } from "../route/RoutePage.js";
|
package/dist/node/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isDarkModeSwitchEnabled, node_path, package_namespaceObject, getDefaultDarkModeValue, createRequire } from "../
|
|
1
|
+
import { isDarkModeSwitchEnabled, node_path, package_namespaceObject, getDefaultDarkModeValue, createRequire } from "../7448.js";
|
|
2
2
|
const constants_require = createRequire(import.meta.url);
|
|
3
3
|
const RSPRESS_VERSION = package_namespaceObject.rE;
|
|
4
4
|
const APPEARANCE_KEY = 'rspress-theme-appearance';
|
package/dist/node/eject.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __webpack_require__ } from "../0~rslib-runtime.js";
|
|
2
|
-
import "../
|
|
3
|
-
import { node_path, logger, promises } from "../
|
|
2
|
+
import "../4538.js";
|
|
3
|
+
import { node_path, logger, promises } from "../8629.js";
|
|
4
4
|
import { EJECTED_THEME } from "./constants.js";
|
|
5
5
|
const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
6
6
|
var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
|
package/dist/node/initRsbuild.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { external_node_process_cwd, node_path,
|
|
1
|
+
import { external_node_process_cwd, node_path, fileURLToPath, addTrailingSlash, PLUGIN_REACT_NAME, removeTrailingSlash, normalizeDarkMode, pluginVirtualModule, pluginReact, createRequire, MDX_OR_MD_REGEXP } from "../8629.js";
|
|
2
2
|
import { createError } from "./utils/error.js";
|
|
3
3
|
import { CSR_CLIENT_ENTRY, SSR_CLIENT_ENTRY, OUTPUT_DIR, SSG_MD_SERVER_ENTRY, NODE_SSG_BUNDLE_FOLDER, isProduction, PACKAGE_ROOT, SSR_SERVER_ENTRY, TEMPLATE_PATH, NODE_SSG_MD_BUNDLE_FOLDER, DEFAULT_THEME, NODE_SSG_MD_BUNDLE_NAME, getInlineThemeScript, DEFAULT_TITLE, NODE_SSG_BUNDLE_NAME } from "./constants.js";
|
|
4
4
|
import { hintBuilderPluginsBreakingChange, hintThemeBreakingChange } from "./logger/hint.js";
|
|
@@ -14,11 +14,11 @@ import { siteDataVMPlugin } from "./runtimeModule/siteData/rsbuildPlugin.js";
|
|
|
14
14
|
import { rsbuildPluginSSG } from "./ssg/rsbuildPluginSSG.js";
|
|
15
15
|
import { rsbuildPluginCSR } from "./ssg/rsbuildPluginCSR.js";
|
|
16
16
|
import { rsbuildPluginSSGMD } from "./ssg-md/rsbuildPluginSSGMD.js";
|
|
17
|
-
import { package_namespaceObject } from "../
|
|
17
|
+
import { package_namespaceObject } from "../7448.js";
|
|
18
18
|
function isPluginIncluded(config, pluginName) {
|
|
19
19
|
return Boolean(config.builderConfig?.plugins?.some((plugin)=>plugin && plugin.name === pluginName));
|
|
20
20
|
}
|
|
21
|
-
const initRsbuild_require =
|
|
21
|
+
const initRsbuild_require = createRequire(import.meta.url);
|
|
22
22
|
const RAW_QUERY_REGEXP = /[?&]raw(?:&|=|$)/;
|
|
23
23
|
const NODE_RSPACK_OPTIMIZATION = {
|
|
24
24
|
concatenateModules: false,
|
|
@@ -43,7 +43,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
43
43
|
const normalizeIcon = (icon)=>{
|
|
44
44
|
if (!icon) return;
|
|
45
45
|
icon = icon.toString();
|
|
46
|
-
if (icon.startsWith('file://')) icon =
|
|
46
|
+
if (icon.startsWith('file://')) icon = fileURLToPath(icon);
|
|
47
47
|
else if (node_path.isAbsolute(icon)) return node_path.join(userDocRoot, "public", icon);
|
|
48
48
|
return icon;
|
|
49
49
|
};
|
|
@@ -212,7 +212,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
212
212
|
chain.module.rule('mdx').test(MDX_OR_MD_REGEXP).resolve.merge({
|
|
213
213
|
conditionNames: jsModuleRule.resolve.conditionNames.values(),
|
|
214
214
|
mainFields: jsModuleRule.resolve.mainFields.values()
|
|
215
|
-
}).end().oneOf('mdx-raw').type('asset/source').resourceQuery(RAW_QUERY_REGEXP).end().oneOf('mdx').type("javascript/auto").use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(
|
|
215
|
+
}).end().oneOf('mdx-raw').type('asset/source').resourceQuery(RAW_QUERY_REGEXP).end().oneOf('mdx').type("javascript/auto").use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(fileURLToPath(new URL('./mdx/loader.js', import.meta.url))).options({
|
|
216
216
|
config,
|
|
217
217
|
docDirectory: userDocRoot,
|
|
218
218
|
routeService,
|
package/dist/node/logger/hint.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __webpack_require__ } from "../../0~rslib-runtime.js";
|
|
2
|
-
import { relative, logger, join, readFile } from "../../
|
|
2
|
+
import { relative, logger, join, readFile } from "../../4538.js";
|
|
3
3
|
import { pathExists } from "../utils/fs.js";
|
|
4
4
|
const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
5
5
|
var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
|
package/dist/node/mdx/options.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { node_path, rehype_external_links, rehype_raw, remark_cjk_friendly, nodeTypes, remark_gfm, rehype, remark_cjk_friendly_gfm_strikethrough } from "../../
|
|
1
|
+
import { node_path, rehype_external_links, rehype_raw, remark_cjk_friendly, nodeTypes, remark_gfm, rehype, remark_cjk_friendly_gfm_strikethrough } from "../../9940.js";
|
|
2
2
|
import { remarkToc } from "./remarkPlugins/toc.js";
|
|
3
3
|
import { remarkContainerSyntax } from "./remarkPlugins/containerSyntax.js";
|
|
4
4
|
import { remarkFileCodeBlock } from "./remarkPlugins/fileCodeBlock.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { node_path, extractTextAndId, createProcessor, loadFrontMatter } from "../../
|
|
1
|
+
import { node_path, extractTextAndId, createProcessor, loadFrontMatter } from "../../9940.js";
|
|
2
2
|
import { createMDXOptions } from "./options.js";
|
|
3
3
|
import { applyReplaceRules } from "../utils/applyReplaceRules.js";
|
|
4
4
|
import { escapeMarkdownHeadingIds } from "../utils/escapeHeadingIds.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { visit, extractTextAndId, github_slugger, headingRank } from "../../../
|
|
1
|
+
import { visit, extractTextAndId, github_slugger, headingRank } from "../../../9940.js";
|
|
2
2
|
const rehypeHeaderAnchor = ()=>{
|
|
3
3
|
const slugger = new github_slugger();
|
|
4
4
|
return (tree)=>{
|