@rspress/core 2.0.22 → 2.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/rspress.js +3 -1
- package/dist/{o~0.js → a~0.js} +0 -14
- package/dist/{v~0.js → b~0.js} +19 -14
- package/dist/cli/index.js +2 -2
- package/dist/config/loadConfigFile.js +1 -1
- package/dist/eject-theme/components/Search/SearchPanel.tsx +9 -5
- package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +1 -1
- package/dist/eject-theme/components/Search/useSearchPanel.ts +6 -5
- package/dist/eject-theme/components/SocialLinks/SocialLink.tsx +2 -2
- package/dist/eject-theme/components/SourceCode/index.tsx +1 -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 +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 +2 -2
- package/dist/node/route/RoutePage.js +1 -1
- package/dist/node/route/RouteService.js +1 -1
- package/dist/node/route/extractPageData.js +1 -1
- package/dist/node/route/normalizeRoutePath.js +1 -1
- package/dist/node/runtimeModule/i18n.js +1 -1
- package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
- package/dist/node/runtimeModule/searchHooks.js +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.js +1 -1
- package/dist/node/ssg/alternateLinks.js +1 -1
- package/dist/node/ssg/htmlFile.js +1 -1
- package/dist/node/ssg/renderHtmlTemplate.js +4 -3
- package/dist/node/ssg/renderPage.js +1 -1
- package/dist/node/ssg/renderPageWorker.js +1 -1
- package/dist/node/ssg/renderPages.js +2 -2
- package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
- package/dist/node/ssg/ssgEnv.js +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
- package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
- package/dist/node/ssg-md/renderPage.js +1 -1
- 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 +1 -1
- package/dist/n~0.js +11 -10
- package/dist/runtime/App.js +3 -2
- package/dist/runtime/hooks/createExternalStore.d.ts +4 -0
- package/dist/runtime/hooks/createExternalStore.js +20 -0
- package/dist/runtime/hooks/useGlobalComponents.d.ts +1 -0
- package/dist/runtime/hooks/useGlobalComponents.js +10 -0
- package/dist/runtime/hooks/useI18n.js +5 -3
- package/dist/runtime/hooks/useI18nText.d.ts +1 -0
- package/dist/runtime/hooks/useI18nText.js +10 -0
- package/dist/runtime/hooks/usePages.d.ts +2 -0
- package/dist/runtime/hooks/usePages.js +12 -3
- package/dist/runtime/hooks/useSearchHooks.d.ts +8 -0
- package/dist/runtime/hooks/useSearchHooks.js +14 -0
- package/dist/runtime/hooks/useSite.d.ts +1 -0
- package/dist/runtime/hooks/useSite.js +9 -2
- package/dist/runtime/index.d.ts +3 -1
- package/dist/runtime/index.js +5 -1
- package/dist/runtime/initPageData.js +10 -10
- package/dist/runtime/route.js +5 -5
- package/dist/runtime/utils.js +6 -6
- package/dist/theme/components/Search/SearchPanel.js +8 -6
- package/dist/theme/components/Search/logic/providers/LocalProvider.js +1 -1
- package/dist/theme/components/Search/useSearchPanel.js +7 -7
- package/dist/theme/components/SocialLinks/SocialLink.js +2 -2
- package/dist/theme/components/SourceCode/index.js +1 -1
- package/dist/theme/logic/utils.d.ts +0 -2
- package/dist/theme/logic/utils.js +56 -6
- package/package.json +11 -11
package/dist/n~0.js
CHANGED
|
@@ -8,10 +8,11 @@ import node_os, { constants } from "node:os";
|
|
|
8
8
|
import { createReadStream, createWriteStream, readFileSync } from "node:fs";
|
|
9
9
|
import { setTimeout as promises_setTimeout } from "node:timers/promises";
|
|
10
10
|
import { debuglog } from "node:util";
|
|
11
|
-
import "
|
|
11
|
+
import { createRequire as __rspack_createRequire } from "node:module";
|
|
12
|
+
const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
|
|
12
13
|
moduleFactories.add({
|
|
13
14
|
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js" (module) {
|
|
14
|
-
const cp =
|
|
15
|
+
const cp = __rspack_createRequire_require("child_process");
|
|
15
16
|
const parse = rspackRequire("../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js");
|
|
16
17
|
const enoent = rspackRequire("../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js");
|
|
17
18
|
function spawn(command, args, options) {
|
|
@@ -70,7 +71,7 @@ moduleFactories.add({
|
|
|
70
71
|
};
|
|
71
72
|
},
|
|
72
73
|
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js" (module) {
|
|
73
|
-
const path =
|
|
74
|
+
const path = __rspack_createRequire_require("path");
|
|
74
75
|
const resolveCommand = rspackRequire("../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js");
|
|
75
76
|
const escape = rspackRequire("../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js");
|
|
76
77
|
const readShebang = rspackRequire("../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js");
|
|
@@ -150,7 +151,7 @@ moduleFactories.add({
|
|
|
150
151
|
module.exports.argument = escapeArgument;
|
|
151
152
|
},
|
|
152
153
|
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js" (module) {
|
|
153
|
-
const fs =
|
|
154
|
+
const fs = __rspack_createRequire_require("fs");
|
|
154
155
|
const shebangCommand = rspackRequire("../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js");
|
|
155
156
|
function readShebang(command) {
|
|
156
157
|
const size = 150;
|
|
@@ -166,7 +167,7 @@ moduleFactories.add({
|
|
|
166
167
|
module.exports = readShebang;
|
|
167
168
|
},
|
|
168
169
|
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js" (module) {
|
|
169
|
-
const path =
|
|
170
|
+
const path = __rspack_createRequire_require("path");
|
|
170
171
|
const which = rspackRequire("../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js");
|
|
171
172
|
const getPathKey = rspackRequire("../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js");
|
|
172
173
|
function resolveCommandAttempt(parsed, withoutPathExt) {
|
|
@@ -197,7 +198,7 @@ moduleFactories.add({
|
|
|
197
198
|
module.exports = resolveCommand;
|
|
198
199
|
},
|
|
199
200
|
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js" (module) {
|
|
200
|
-
|
|
201
|
+
__rspack_createRequire_require("fs");
|
|
201
202
|
var core;
|
|
202
203
|
core = 'win32' === process.platform || global.TESTING_WINDOWS ? rspackRequire("../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js") : rspackRequire("../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js");
|
|
203
204
|
module.exports = isexe;
|
|
@@ -238,7 +239,7 @@ moduleFactories.add({
|
|
|
238
239
|
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js" (module) {
|
|
239
240
|
module.exports = isexe;
|
|
240
241
|
isexe.sync = sync;
|
|
241
|
-
var fs =
|
|
242
|
+
var fs = __rspack_createRequire_require("fs");
|
|
242
243
|
function isexe(path, options, cb) {
|
|
243
244
|
fs.stat(path, function(er, stat) {
|
|
244
245
|
cb(er, er ? false : checkStat(stat, options));
|
|
@@ -267,7 +268,7 @@ moduleFactories.add({
|
|
|
267
268
|
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js" (module) {
|
|
268
269
|
module.exports = isexe;
|
|
269
270
|
isexe.sync = sync;
|
|
270
|
-
var fs =
|
|
271
|
+
var fs = __rspack_createRequire_require("fs");
|
|
271
272
|
function checkPathExt(path, options) {
|
|
272
273
|
var pathext = void 0 !== options.pathExt ? options.pathExt : process.env.PATHEXT;
|
|
273
274
|
if (!pathext) return true;
|
|
@@ -293,7 +294,7 @@ moduleFactories.add({
|
|
|
293
294
|
}
|
|
294
295
|
},
|
|
295
296
|
"../../node_modules/.pnpm/merge-stream@2.0.0/node_modules/merge-stream/index.js" (module) {
|
|
296
|
-
const { PassThrough } =
|
|
297
|
+
const { PassThrough } = __rspack_createRequire_require("stream");
|
|
297
298
|
module.exports = function() {
|
|
298
299
|
var sources = [];
|
|
299
300
|
var output = new PassThrough({
|
|
@@ -355,7 +356,7 @@ moduleFactories.add({
|
|
|
355
356
|
},
|
|
356
357
|
"../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js" (module) {
|
|
357
358
|
const isWindows = 'win32' === process.platform || 'cygwin' === process.env.OSTYPE || 'msys' === process.env.OSTYPE;
|
|
358
|
-
const path =
|
|
359
|
+
const path = __rspack_createRequire_require("path");
|
|
359
360
|
const COLON = isWindows ? ';' : ':';
|
|
360
361
|
const isexe = rspackRequire("../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js");
|
|
361
362
|
const getNotFoundError = (cmd)=>Object.assign(new Error(`not found: ${cmd}`), {
|
package/dist/runtime/App.js
CHANGED
|
@@ -3,9 +3,10 @@ import { PageContext, useLocation } from "@rspress/core/runtime";
|
|
|
3
3
|
import { Layout, Root } from "@rspress/core/theme";
|
|
4
4
|
import { LlmsHint } from "@rspress/core/theme-original";
|
|
5
5
|
import react, { useContext, useLayoutEffect } from "react";
|
|
6
|
-
import
|
|
6
|
+
import { useGlobalComponents } from "./hooks/useGlobalComponents.js";
|
|
7
7
|
import { consumeCachedPageData, initPageData, setCurrentPageData } from "./initPageData.js";
|
|
8
8
|
function App() {
|
|
9
|
+
const globalComponents = useGlobalComponents();
|
|
9
10
|
const { setData: setPageData, data } = useContext(PageContext);
|
|
10
11
|
const { pathname, search } = useLocation();
|
|
11
12
|
useLayoutEffect(()=>{
|
|
@@ -40,7 +41,7 @@ function App() {
|
|
|
40
41
|
children: [
|
|
41
42
|
import.meta.env.ENABLE_LLMS_HINT && /*#__PURE__*/ jsx(LlmsHint, {}),
|
|
42
43
|
/*#__PURE__*/ jsx(Layout, {}),
|
|
43
|
-
!hideGlobalUIComponents &&
|
|
44
|
+
!hideGlobalUIComponents && globalComponents.map((componentInfo, index)=>{
|
|
44
45
|
if (Array.isArray(componentInfo)) {
|
|
45
46
|
const [component, props] = componentInfo;
|
|
46
47
|
return /*#__PURE__*/ react.createElement(component, {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
function createExternalStore(initialValue) {
|
|
3
|
+
let value = initialValue;
|
|
4
|
+
const listeners = new Set();
|
|
5
|
+
const getSnapshot = ()=>value;
|
|
6
|
+
const subscribe = (listener)=>{
|
|
7
|
+
listeners.add(listener);
|
|
8
|
+
return ()=>listeners.delete(listener);
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
update (nextValue) {
|
|
12
|
+
value = nextValue;
|
|
13
|
+
for (const listener of listeners)listener();
|
|
14
|
+
},
|
|
15
|
+
useValue () {
|
|
16
|
+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export { createExternalStore };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useGlobalComponents(): ([import("react").ComponentType, object] | import("react").ComponentType)[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import virtual_global_components from "virtual-global-components";
|
|
2
|
+
import { createExternalStore } from "./createExternalStore.js";
|
|
3
|
+
const store = createExternalStore(virtual_global_components);
|
|
4
|
+
function useGlobalComponents() {
|
|
5
|
+
return store.useValue();
|
|
6
|
+
}
|
|
7
|
+
if (import.meta.webpackHot) import.meta.webpackHot.accept('virtual-global-components', ()=>{
|
|
8
|
+
store.update(virtual_global_components);
|
|
9
|
+
});
|
|
10
|
+
export { useGlobalComponents };
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
|
-
import
|
|
2
|
+
import { useI18nText } from "./useI18nText.js";
|
|
3
3
|
import { useLang } from "./useLang.js";
|
|
4
4
|
function useI18n() {
|
|
5
5
|
const lang = useLang();
|
|
6
|
+
const i18nTextData = useI18nText();
|
|
6
7
|
return useCallback((key, params)=>{
|
|
7
|
-
const text =
|
|
8
|
+
const text = i18nTextData[key]?.[lang];
|
|
8
9
|
if ('string' != typeof text) throw new Error(`i18n key "${key}" not found for language "${lang}"`);
|
|
9
10
|
return text.replace(/\{\{(\w+)\}\}/g, (_, p1)=>params?.[p1] ?? `${p1}`);
|
|
10
11
|
}, [
|
|
11
|
-
lang
|
|
12
|
+
lang,
|
|
13
|
+
i18nTextData
|
|
12
14
|
]);
|
|
13
15
|
}
|
|
14
16
|
export { useI18n };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useI18nText(): Record<string, Record<string, string>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import virtual_i18n_text from "virtual-i18n-text";
|
|
2
|
+
import { createExternalStore } from "./createExternalStore.js";
|
|
3
|
+
const store = createExternalStore(virtual_i18n_text);
|
|
4
|
+
function useI18nText() {
|
|
5
|
+
return store.useValue();
|
|
6
|
+
}
|
|
7
|
+
if (import.meta.webpackHot) import.meta.webpackHot.accept('virtual-i18n-text', ()=>{
|
|
8
|
+
store.update(virtual_i18n_text);
|
|
9
|
+
});
|
|
10
|
+
export { useI18nText };
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import { pageData } from "virtual-page-data";
|
|
1
|
+
import { pageData, searchIndexHash } from "virtual-page-data";
|
|
2
|
+
import { createExternalStore } from "./createExternalStore.js";
|
|
3
|
+
let usePages_pageData = pageData;
|
|
4
|
+
let usePages_searchIndexHash = searchIndexHash;
|
|
5
|
+
const store = createExternalStore(usePages_pageData);
|
|
2
6
|
function usePages() {
|
|
3
7
|
return {
|
|
4
|
-
pages:
|
|
8
|
+
pages: store.useValue().pages
|
|
5
9
|
};
|
|
6
10
|
}
|
|
7
|
-
|
|
11
|
+
if (import.meta.webpackHot) import.meta.webpackHot.accept('virtual-page-data', ()=>{
|
|
12
|
+
usePages_pageData = pageData;
|
|
13
|
+
usePages_searchIndexHash = searchIndexHash;
|
|
14
|
+
store.update(usePages_pageData);
|
|
15
|
+
});
|
|
16
|
+
export { usePages, usePages_pageData as pageData, usePages_searchIndexHash as searchIndexHash };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BeforeSearch, OnSearch, AfterSearch, RenderSearchFunction } from '@rspress/core/theme';
|
|
2
|
+
export interface SearchHooks {
|
|
3
|
+
beforeSearch?: BeforeSearch;
|
|
4
|
+
onSearch?: OnSearch;
|
|
5
|
+
afterSearch?: AfterSearch;
|
|
6
|
+
render?: RenderSearchFunction;
|
|
7
|
+
}
|
|
8
|
+
export declare function useSearchHooks(): SearchHooks;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as __rspack_external_virtual_search_hooks_705b6e40 from "virtual-search-hooks";
|
|
2
|
+
import { createExternalStore } from "./createExternalStore.js";
|
|
3
|
+
const store = createExternalStore({
|
|
4
|
+
...__rspack_external_virtual_search_hooks_705b6e40
|
|
5
|
+
});
|
|
6
|
+
function useSearchHooks() {
|
|
7
|
+
return store.useValue();
|
|
8
|
+
}
|
|
9
|
+
if (import.meta.webpackHot) import.meta.webpackHot.accept('virtual-search-hooks', ()=>{
|
|
10
|
+
store.update({
|
|
11
|
+
...__rspack_external_virtual_search_hooks_705b6e40
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
export { useSearchHooks };
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import virtual_site_data from "virtual-site-data";
|
|
2
|
+
import { createExternalStore } from "./createExternalStore.js";
|
|
3
|
+
let siteData = virtual_site_data;
|
|
4
|
+
const store = createExternalStore(siteData);
|
|
2
5
|
function useSite() {
|
|
3
6
|
return {
|
|
4
|
-
site:
|
|
7
|
+
site: store.useValue()
|
|
5
8
|
};
|
|
6
9
|
}
|
|
7
|
-
|
|
10
|
+
if (import.meta.webpackHot) import.meta.webpackHot.accept('virtual-site-data', ()=>{
|
|
11
|
+
siteData = virtual_site_data;
|
|
12
|
+
store.update(siteData);
|
|
13
|
+
});
|
|
14
|
+
export { siteData, useSite };
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { useLocaleSiteData } from './hooks/useLocaleSiteData.js';
|
|
|
12
12
|
export { useNav } from './hooks/useNav.js';
|
|
13
13
|
export { PageContext, usePage } from './hooks/usePage.js';
|
|
14
14
|
export { usePageData } from './hooks/usePageData.js';
|
|
15
|
-
export { usePages } from './hooks/usePages.js';
|
|
15
|
+
export { usePages, searchIndexHash } from './hooks/usePages.js';
|
|
16
16
|
export { getSidebarDataGroup, useSidebar, useSidebarDynamic, } from './hooks/useSidebar.js';
|
|
17
17
|
export { useSite } from './hooks/useSite.js';
|
|
18
18
|
export { useVersion } from './hooks/useVersion.js';
|
|
@@ -22,3 +22,5 @@ export { NoSSR } from './NoSSR.js';
|
|
|
22
22
|
export { safePreconnect, safePreload } from './reactDom.js';
|
|
23
23
|
export { isActive, pathnameToRouteService, preloadLink } from './route.js';
|
|
24
24
|
export { addLeadingSlash, addTrailingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase, withSiteOrigin, } from './utils.js';
|
|
25
|
+
export declare const socialLinks: Record<string, string>;
|
|
26
|
+
export { useSearchHooks, type SearchHooks } from './hooks/useSearchHooks.js';
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import virtual_social_links from "virtual-social-links";
|
|
1
2
|
export * from "react-router-dom";
|
|
3
|
+
const socialLinks = virtual_social_links;
|
|
2
4
|
export { isDataUrl, isExternalUrl, matchNavbar, matchSidebar, normalizeHref } from "@rspress/shared";
|
|
3
5
|
export { Head, useHead } from "@unhead/react";
|
|
4
6
|
export { BrowserOnly } from "./BrowserOnly.js";
|
|
@@ -12,7 +14,7 @@ export { useLocaleSiteData } from "./hooks/useLocaleSiteData.js";
|
|
|
12
14
|
export { useNav } from "./hooks/useNav.js";
|
|
13
15
|
export { PageContext, usePage } from "./hooks/usePage.js";
|
|
14
16
|
export { usePageData } from "./hooks/usePageData.js";
|
|
15
|
-
export { usePages } from "./hooks/usePages.js";
|
|
17
|
+
export { searchIndexHash, usePages } from "./hooks/usePages.js";
|
|
16
18
|
export { getSidebarDataGroup, useSidebar, useSidebarDynamic } from "./hooks/useSidebar.js";
|
|
17
19
|
export { useSite } from "./hooks/useSite.js";
|
|
18
20
|
export { useVersion } from "./hooks/useVersion.js";
|
|
@@ -22,3 +24,5 @@ export { NoSSR } from "./NoSSR.js";
|
|
|
22
24
|
export { safePreconnect, safePreload } from "./reactDom.js";
|
|
23
25
|
export { isActive, pathnameToRouteService, preloadLink } from "./route.js";
|
|
24
26
|
export { addLeadingSlash, addTrailingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase, withSiteOrigin } from "./utils.js";
|
|
27
|
+
export { useSearchHooks } from "./hooks/useSearchHooks.js";
|
|
28
|
+
export { socialLinks };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MDX_OR_MD_REGEXP, cleanUrl } from "@rspress/shared";
|
|
2
|
-
import { pageData } from "
|
|
3
|
-
import virtual_site_data from "virtual-site-data";
|
|
2
|
+
import { pageData } from "./hooks/usePages.js";
|
|
4
3
|
import { pathnameToRouteService } from "./route.js";
|
|
4
|
+
import { siteData } from "./hooks/useSite.js";
|
|
5
5
|
import { isEqualPath } from "./utils.js";
|
|
6
6
|
const slots = [
|
|
7
7
|
void 0,
|
|
@@ -57,16 +57,16 @@ async function initPageData(routePath) {
|
|
|
57
57
|
toc
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
let lang =
|
|
61
|
-
let version =
|
|
62
|
-
if (
|
|
63
|
-
const path = window.location.pathname.replace(
|
|
64
|
-
if (
|
|
65
|
-
const result =
|
|
60
|
+
let lang = siteData.lang || '';
|
|
61
|
+
let version = siteData.multiVersion?.default || '';
|
|
62
|
+
if (siteData.lang && "u" > typeof window) {
|
|
63
|
+
const path = window.location.pathname.replace(siteData.base, '').split('/').slice(0, 2);
|
|
64
|
+
if (siteData.locales.length) {
|
|
65
|
+
const result = siteData.locales.find(({ lang })=>path.includes(lang));
|
|
66
66
|
if (result) lang = result.lang;
|
|
67
67
|
}
|
|
68
|
-
if (
|
|
69
|
-
const result =
|
|
68
|
+
if (siteData.multiVersion.versions) {
|
|
69
|
+
const result = siteData.multiVersion.versions.find((version)=>path.includes(version));
|
|
70
70
|
if (result) version = result;
|
|
71
71
|
}
|
|
72
72
|
}
|
package/dist/runtime/route.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cleanUrl, normalizeHref } from "@rspress/shared";
|
|
2
2
|
import { routes } from "virtual-routes";
|
|
3
|
-
import
|
|
3
|
+
import { siteData } from "./hooks/useSite.js";
|
|
4
4
|
import { removeBase, removeTrailingSlash } from "./utils.js";
|
|
5
5
|
function normalizeRoutePath(routePath) {
|
|
6
6
|
return cleanUrl(decodeURIComponent(routePath)).replace(/\.html$/, '').replace(/\/index$/, '/').toLowerCase();
|
|
@@ -45,11 +45,11 @@ function pathnameToRouteService(pathname) {
|
|
|
45
45
|
return route;
|
|
46
46
|
}
|
|
47
47
|
function redirectToCleanUrl(location, history) {
|
|
48
|
-
if (
|
|
48
|
+
if (siteData.route?.cleanUrlsRedirect === false) return false;
|
|
49
49
|
const matchedRoute = pathnameToRouteService(removeBase(location.pathname));
|
|
50
50
|
if (!matchedRoute) return false;
|
|
51
|
-
const canonicalRoutePath = normalizeHref(matchedRoute.path, Boolean(
|
|
52
|
-
const canonicalPathname = `${removeTrailingSlash(
|
|
51
|
+
const canonicalRoutePath = normalizeHref(matchedRoute.path, Boolean(siteData.route?.cleanUrls));
|
|
52
|
+
const canonicalPathname = `${removeTrailingSlash(siteData.base)}${canonicalRoutePath}`;
|
|
53
53
|
if (location.pathname === canonicalPathname) return false;
|
|
54
54
|
history.replaceState(history.state, '', `${canonicalPathname}${location.search}${location.hash}`);
|
|
55
55
|
return true;
|
|
@@ -59,7 +59,7 @@ function isActive(itemLink, currentPathname) {
|
|
|
59
59
|
return null !== linkMatched;
|
|
60
60
|
}
|
|
61
61
|
const preloadLink = (link)=>{
|
|
62
|
-
if (
|
|
62
|
+
if (siteData?.route?.prefetchLink === false) return;
|
|
63
63
|
const route = pathnameToRouteService(link);
|
|
64
64
|
if (route) route.preload();
|
|
65
65
|
};
|
package/dist/runtime/utils.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { addLeadingSlash, addTrailingSlash, isDataUrl, isExternalUrl, isProduction, normalizeHref, removeBase, removeHash, removeTrailingSlash, withBase, withSiteOrigin } from "@rspress/shared";
|
|
2
|
-
import
|
|
2
|
+
import { siteData } from "./hooks/useSite.js";
|
|
3
3
|
function utils_withBase(url = '/') {
|
|
4
|
-
return withBase(url,
|
|
4
|
+
return withBase(url, siteData.base);
|
|
5
5
|
}
|
|
6
6
|
function utils_withSiteOrigin(url) {
|
|
7
|
-
return withSiteOrigin(url,
|
|
7
|
+
return withSiteOrigin(url, siteData.siteOrigin);
|
|
8
8
|
}
|
|
9
9
|
function utils_removeBase(url) {
|
|
10
|
-
return removeBase(url,
|
|
10
|
+
return removeBase(url, siteData.base);
|
|
11
11
|
}
|
|
12
12
|
function isEqualPath(a, b) {
|
|
13
13
|
return utils_removeBase(normalizeHref(removeHash(a), true)) === utils_removeBase(normalizeHref(removeHash(b), true));
|
|
14
14
|
}
|
|
15
15
|
function normalizeHrefInRuntime(link) {
|
|
16
|
-
const cleanUrls = Boolean(
|
|
16
|
+
const cleanUrls = Boolean(siteData?.route?.cleanUrls);
|
|
17
17
|
return normalizeHref(link, cleanUrls);
|
|
18
18
|
}
|
|
19
19
|
function cleanUrlByConfig(link) {
|
|
20
|
-
if (
|
|
20
|
+
if (siteData?.route?.cleanUrls) return normalizeHref(link, true);
|
|
21
21
|
return link;
|
|
22
22
|
}
|
|
23
23
|
function normalizeImagePath(imagePath) {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Head, useI18n } from "@rspress/core/runtime";
|
|
2
|
+
import { Head, useI18n, useSearchHooks } from "@rspress/core/runtime";
|
|
3
3
|
import { IconClose, IconSearch, SvgWrapper, Tab, Tabs, useLinkNavigate } from "@rspress/core/theme";
|
|
4
4
|
import { useEffect, useRef, useState } from "react";
|
|
5
5
|
import { createPortal } from "react-dom";
|
|
6
|
-
import * as __rspack_external_virtual_search_hooks_705b6e40 from "virtual-search-hooks";
|
|
7
6
|
import { RenderType } from "./logic/types.js";
|
|
8
7
|
import { NoSearchResult } from "./NoSearchResult.js";
|
|
9
8
|
import "./SearchPanel.css";
|
|
@@ -46,6 +45,7 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
46
45
|
}
|
|
47
46
|
};
|
|
48
47
|
const t = useI18n();
|
|
48
|
+
const userSearchHooks = useSearchHooks();
|
|
49
49
|
const navigate = useLinkNavigate();
|
|
50
50
|
const { currentRenderType, currentSuggestions, currentSuggestionIndex, clearQuery, handleQueryInput, initStatus, isSearching, query, resultTabIndex, searchError, searchIndexURL, searchResult, searchEnabled, setCurrentSuggestionIndex, setResultTabIndex } = useSearchPanel({
|
|
51
51
|
focused,
|
|
@@ -89,11 +89,13 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
89
89
|
break;
|
|
90
90
|
case KEY_CODE.ENTER:
|
|
91
91
|
if (e.isComposing) return;
|
|
92
|
-
if (currentSuggestionIndex >= 0 && currentRenderType === RenderType.Default) {
|
|
92
|
+
if (focused && currentSuggestionIndex >= 0 && currentRenderType === RenderType.Default) {
|
|
93
93
|
const flatSuggestions = Array.from(normalizeSuggestions(currentSuggestions).values()).flat();
|
|
94
94
|
const suggestion = flatSuggestions[currentSuggestionIndex];
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
if (suggestion) {
|
|
96
|
+
navigate(suggestion.link);
|
|
97
|
+
clearSearchState();
|
|
98
|
+
}
|
|
97
99
|
}
|
|
98
100
|
break;
|
|
99
101
|
case KEY_CODE.ESC:
|
|
@@ -136,7 +138,7 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
136
138
|
label: item.group,
|
|
137
139
|
children: [
|
|
138
140
|
item.renderType === RenderType.Default && renderSearchResultItem(item.result),
|
|
139
|
-
item.renderType === RenderType.Custom &&
|
|
141
|
+
item.renderType === RenderType.Custom && userSearchHooks[renderKey]?.(item.result)
|
|
140
142
|
]
|
|
141
143
|
}, item.group))
|
|
142
144
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SEARCH_INDEX_NAME, removeTrailingSlash } from "@rspress/shared";
|
|
2
2
|
import { Document } from "flexsearch";
|
|
3
|
-
import { searchIndexHash } from "
|
|
3
|
+
import { searchIndexHash } from "@rspress/core/runtime";
|
|
4
4
|
import { LOCAL_INDEX } from "../Provider.js";
|
|
5
5
|
import { normalizeTextCase } from "../util.js";
|
|
6
6
|
function getSearchIndexURL(lang, version) {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { usePageData } from "@rspress/core/runtime";
|
|
1
|
+
import { usePageData, useSearchHooks } from "@rspress/core/runtime";
|
|
2
2
|
import { debounce } from "@rspress/shared/lodash-es";
|
|
3
3
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
4
|
import { getSearchIndexURL } from "./logic/providers/LocalProvider.js";
|
|
5
5
|
import { PageSearcher } from "./logic/search.js";
|
|
6
6
|
import { RenderType } from "./logic/types.js";
|
|
7
|
-
import * as __rspack_external_virtual_search_hooks_705b6e40 from "virtual-search-hooks";
|
|
8
7
|
const useDebounce = (cb)=>{
|
|
9
8
|
const cbRef = useRef(cb);
|
|
10
9
|
cbRef.current = cb;
|
|
@@ -12,6 +11,7 @@ const useDebounce = (cb)=>{
|
|
|
12
11
|
};
|
|
13
12
|
function useSearchPanel({ focused, searchInputRef }) {
|
|
14
13
|
const { siteData, page: { lang, version } } = usePageData();
|
|
14
|
+
const userSearchHooks = useSearchHooks();
|
|
15
15
|
const { search, title: siteTitle } = siteData;
|
|
16
16
|
const [query, setQuery] = useState('');
|
|
17
17
|
const [searchResult, setSearchResult] = useState([]);
|
|
@@ -105,20 +105,20 @@ function useSearchPanel({ focused, searchInputRef }) {
|
|
|
105
105
|
setQuery(newQuery);
|
|
106
106
|
if (!newQuery) return void setIsSearching(false);
|
|
107
107
|
const result = [];
|
|
108
|
-
if (
|
|
109
|
-
const transformedQuery = await
|
|
108
|
+
if (userSearchHooks.beforeSearch) {
|
|
109
|
+
const transformedQuery = await userSearchHooks.beforeSearch(newQuery);
|
|
110
110
|
if (transformedQuery) newQuery = transformedQuery;
|
|
111
111
|
}
|
|
112
112
|
const defaultSearchResult = await pageSearcherRef.current?.match(newQuery);
|
|
113
113
|
if (defaultSearchResult) result.push(...defaultSearchResult);
|
|
114
|
-
if (
|
|
115
|
-
const customSearchResult = await
|
|
114
|
+
if (userSearchHooks.onSearch) {
|
|
115
|
+
const customSearchResult = await userSearchHooks.onSearch(newQuery, result);
|
|
116
116
|
if (customSearchResult) result.push(...customSearchResult.map((item)=>({
|
|
117
117
|
renderType: RenderType.Custom,
|
|
118
118
|
...item
|
|
119
119
|
})));
|
|
120
120
|
}
|
|
121
|
-
if (
|
|
121
|
+
if (userSearchHooks.afterSearch) await userSearchHooks.afterSearch(newQuery, result);
|
|
122
122
|
if (searchInputRef.current?.value === newQuery) {
|
|
123
123
|
setCurrentSuggestionIndex(0);
|
|
124
124
|
setSearchResult(result || DEFAULT_RESULT);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import { socialLinks } from "@rspress/core/runtime";
|
|
3
3
|
import "./index.css";
|
|
4
4
|
import { GithubStars } from "./GithubStars.js";
|
|
5
5
|
import { useHoverGroup } from "../HoverGroup/useHoverGroup.js";
|
|
@@ -8,7 +8,7 @@ const SocialLink = (props)=>{
|
|
|
8
8
|
const { icon, mode = 'link', content } = link;
|
|
9
9
|
let IconComp = /*#__PURE__*/ jsx(Fragment, {});
|
|
10
10
|
if (icon) {
|
|
11
|
-
const html = 'string' == typeof icon ?
|
|
11
|
+
const html = 'string' == typeof icon ? socialLinks[icon] : icon.svg;
|
|
12
12
|
IconComp = /*#__PURE__*/ jsx("div", {
|
|
13
13
|
className: "rp-social-links__icon",
|
|
14
14
|
dangerouslySetInnerHTML: {
|
|
@@ -6,7 +6,7 @@ function SourceCode(props) {
|
|
|
6
6
|
const { href, platform = 'github' } = props;
|
|
7
7
|
const t = useI18n();
|
|
8
8
|
return /*#__PURE__*/ jsx("div", {
|
|
9
|
-
className: "rp-not-doc rp-source-code",
|
|
9
|
+
className: "rp-not-doc rp-source-code rp-toc-exclude",
|
|
10
10
|
children: /*#__PURE__*/ jsxs("a", {
|
|
11
11
|
href: href,
|
|
12
12
|
target: "_blank",
|
|
@@ -16,12 +16,11 @@ function renderHtmlOrText(str) {
|
|
|
16
16
|
children: str.replace(/\\</g, '<').replace(/\\>/g, '>').replace(/</g, '<').replace(/>/g, '>')
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
const CODE_TEXT_PATTERN = /`(.*?)`/g;
|
|
20
19
|
const STRONG_TEXT_PATTERN = /\*{2}(?!\*)(.*?)\*{2}(?!\*)/g;
|
|
21
20
|
const EMPHASIS_TEXT_PATTERN = /\*(?!\*)(.*?)\*(?!\*)/g;
|
|
22
21
|
const DELETE_TEXT_PATTERN = /~{2}(.*?)~{2}/g;
|
|
23
|
-
const INLINE_CODE_PATTERN = /`[^`]+`/g;
|
|
24
22
|
const HTML_TAG_PATTERN = /<\/?[a-z][^>]*>/gi;
|
|
23
|
+
const HTML_VOID_ELEMENT_PATTERN = /<(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)(?=[\s/>])[^>]*>/gi;
|
|
25
24
|
const HTML_ENTITY_PATTERN = /&(#\d+|#x[0-9a-f]+|[a-z][0-9a-z]*);/gi;
|
|
26
25
|
const NAMED_HTML_ENTITIES = {
|
|
27
26
|
amp: '&',
|
|
@@ -40,12 +39,63 @@ function decodeHtmlEntities(text) {
|
|
|
40
39
|
return isScalarValue ? String.fromCodePoint(codePoint) : match;
|
|
41
40
|
});
|
|
42
41
|
}
|
|
42
|
+
function escapeHtml(text) {
|
|
43
|
+
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
44
|
+
}
|
|
45
|
+
function protectInlineMarkdown(text) {
|
|
46
|
+
let marker = '\u0000';
|
|
47
|
+
while(text.includes(marker))marker += '\u0000';
|
|
48
|
+
const fragments = [];
|
|
49
|
+
const protect = (value, html = escapeHtml(value))=>{
|
|
50
|
+
const index = fragments.push({
|
|
51
|
+
text: value,
|
|
52
|
+
html
|
|
53
|
+
}) - 1;
|
|
54
|
+
return `${marker}${index}${marker}`;
|
|
55
|
+
};
|
|
56
|
+
const pattern = /\\([!-/:-@[-`{-~])|`+|<code\b[^>]*>[\s\S]*?<\/code>|&(#\d+|#x[0-9a-f]+|[a-z][0-9a-z]*);/gi;
|
|
57
|
+
const backticks = /`+/g;
|
|
58
|
+
let result = '';
|
|
59
|
+
let offset = 0;
|
|
60
|
+
let match;
|
|
61
|
+
while(match = pattern.exec(text)){
|
|
62
|
+
result += text.slice(offset, match.index);
|
|
63
|
+
if (match[1]) result += protect(match[1]);
|
|
64
|
+
else if (match[0].startsWith('&')) result += protect(decodeHtmlEntities(match[0]), match[0]);
|
|
65
|
+
else if (match[0].startsWith('<')) result += protect(decodeHtmlEntities(match[0].replace(HTML_TAG_PATTERN, '')), match[0]);
|
|
66
|
+
else {
|
|
67
|
+
backticks.lastIndex = pattern.lastIndex;
|
|
68
|
+
let closing;
|
|
69
|
+
while(closing = backticks.exec(text))if (closing[0].length === match[0].length) break;
|
|
70
|
+
if (closing) {
|
|
71
|
+
let value = text.slice(pattern.lastIndex, closing.index).replace(/\r\n?|\n/g, ' ');
|
|
72
|
+
if (value.startsWith(' ') && value.endsWith(' ') && /[^ ]/.test(value)) value = value.slice(1, -1);
|
|
73
|
+
result += protect(value, `<code>${escapeHtml(value)}</code>`);
|
|
74
|
+
pattern.lastIndex = closing.index + closing[0].length;
|
|
75
|
+
} else result += protect(match[0]);
|
|
76
|
+
}
|
|
77
|
+
offset = pattern.lastIndex;
|
|
78
|
+
}
|
|
79
|
+
result += text.slice(offset);
|
|
80
|
+
return {
|
|
81
|
+
text: result,
|
|
82
|
+
restore: (value, format)=>value.replace(new RegExp(`${marker}(\\d+)${marker}`, 'g'), (_, index)=>fragments[Number(index)][format])
|
|
83
|
+
};
|
|
84
|
+
}
|
|
43
85
|
function renderInlineMarkdown(text) {
|
|
44
|
-
const
|
|
45
|
-
|
|
86
|
+
const protectedText = protectInlineMarkdown(text);
|
|
87
|
+
const source = renderHtmlOrText(protectedText.text);
|
|
88
|
+
const htmlText = ('children' in source ? escapeHtml(source.children ?? '') : source.dangerouslySetInnerHTML.__html).replace(STRONG_TEXT_PATTERN, '<strong>$1</strong>').replace(EMPHASIS_TEXT_PATTERN, '<em>$1</em>').replace(DELETE_TEXT_PATTERN, '<del>$1</del>');
|
|
89
|
+
return {
|
|
90
|
+
dangerouslySetInnerHTML: {
|
|
91
|
+
__html: protectedText.restore(htmlText, 'html')
|
|
92
|
+
}
|
|
93
|
+
};
|
|
46
94
|
}
|
|
47
95
|
function parseInlineMarkdownText(mdx) {
|
|
48
|
-
const
|
|
49
|
-
|
|
96
|
+
const protectedText = protectInlineMarkdown(mdx);
|
|
97
|
+
const source = renderHtmlOrText(protectedText.text.replace(HTML_VOID_ELEMENT_PATTERN, ''));
|
|
98
|
+
const plainText = ('children' in source ? source.children ?? '' : source.dangerouslySetInnerHTML.__html.replace(HTML_TAG_PATTERN, '')).replace(STRONG_TEXT_PATTERN, '$1').replace(EMPHASIS_TEXT_PATTERN, '$1').replace(DELETE_TEXT_PATTERN, '$1');
|
|
99
|
+
return protectedText.restore(decodeHtmlEntities(plainText), 'text').trim();
|
|
50
100
|
}
|
|
51
101
|
export { parseInlineMarkdownText, renderHtmlOrText, renderInlineMarkdown };
|