@rspress/core 0.1.1 → 0.2.0
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/index.js +57 -24
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +1 -0
- package/dist/loader.js +5 -24
- package/dist/loader.js.map +1 -1
- package/dist/runtime/App.js +1 -0
- package/dist/runtime/Content.js +7 -2
- package/dist/runtime/hooks.d.ts +7 -0
- package/dist/runtime/hooks.js +23 -1
- package/dist/theme/bundle.css +39 -1
- package/dist/theme/bundle.d.ts +6 -1
- package/dist/theme/bundle.js +119 -69
- package/dist/theme/bundle.js.map +1 -1
- package/package.json +7 -7
- package/src/runtime/App.tsx +1 -0
- package/src/runtime/Content.tsx +11 -2
- package/src/runtime/hooks.ts +47 -1
- package/src/theme-default/components/Nav/index.tsx +19 -5
- package/src/theme-default/index.ts +2 -0
- package/src/theme-default/layout/DocLayout/docComponents/link.tsx +8 -23
- package/src/theme-default/layout/DocLayout/index.module.scss +46 -0
- package/src/theme-default/logic/index.ts +1 -0
- package/src/theme-default/logic/usePathUtils.ts +72 -0
package/dist/index.js
CHANGED
|
@@ -519,6 +519,7 @@ ${item.text}#
|
|
|
519
519
|
...frontmatter,
|
|
520
520
|
__content: void 0
|
|
521
521
|
},
|
|
522
|
+
version: route.version,
|
|
522
523
|
_filepath: route.absolutePath,
|
|
523
524
|
_relativePath: path5.relative(root, route.absolutePath)
|
|
524
525
|
};
|
|
@@ -557,7 +558,12 @@ async function siteDataVMPlugin(context) {
|
|
|
557
558
|
themeConfig: normalizeThemeConfig(userConfig, pages),
|
|
558
559
|
base: userConfig?.base || "/",
|
|
559
560
|
lang: userConfig?.lang || "",
|
|
561
|
+
locales: userConfig?.locales || userConfig.themeConfig?.locales || [],
|
|
560
562
|
logo: userConfig?.logo || "",
|
|
563
|
+
multiVersion: {
|
|
564
|
+
default: userConfig?.multiVersion?.default || "",
|
|
565
|
+
versions: userConfig?.multiVersion?.versions || []
|
|
566
|
+
},
|
|
561
567
|
search: userConfig?.search ?? {
|
|
562
568
|
mode: "local"
|
|
563
569
|
},
|
|
@@ -849,14 +855,38 @@ var DEFAULT_PAGE_EXTENSIONS = [
|
|
|
849
855
|
var addLeadingSlash3 = (str) => {
|
|
850
856
|
return str.startsWith("/") ? str : `/${str}`;
|
|
851
857
|
};
|
|
852
|
-
var normalizeRoutePath = (routePath, lang, base) => {
|
|
853
|
-
let
|
|
854
|
-
|
|
855
|
-
|
|
858
|
+
var normalizeRoutePath = (routePath, lang, base, version) => {
|
|
859
|
+
let versionPart = "";
|
|
860
|
+
let langPart = "";
|
|
861
|
+
let purePathPart = "";
|
|
862
|
+
const parts = routePath.split("/").filter(Boolean);
|
|
863
|
+
if (version) {
|
|
864
|
+
const versionToMatch = parts.shift();
|
|
865
|
+
if (versionToMatch !== version) {
|
|
866
|
+
versionPart = versionToMatch;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
if (lang) {
|
|
870
|
+
const langToMatch = parts.shift();
|
|
871
|
+
if (langToMatch !== lang) {
|
|
872
|
+
langPart = langToMatch;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
purePathPart = parts.join("/");
|
|
876
|
+
const normalizedRoutePath = addLeadingSlash3([
|
|
877
|
+
versionPart,
|
|
878
|
+
langPart,
|
|
879
|
+
purePathPart
|
|
880
|
+
].filter(Boolean).join("/")).replace(/\.[^.]+$/, "").replace(/\/index$/, "/");
|
|
881
|
+
return {
|
|
882
|
+
routePath: withBase2(normalizedRoutePath, base),
|
|
883
|
+
lang: langPart || lang,
|
|
884
|
+
version: versionPart || version
|
|
885
|
+
};
|
|
856
886
|
};
|
|
857
887
|
var _scanDir = /* @__PURE__ */ new WeakMap();
|
|
858
888
|
var _defaultLang = /* @__PURE__ */ new WeakMap();
|
|
859
|
-
var
|
|
889
|
+
var _defaultVersion = /* @__PURE__ */ new WeakMap();
|
|
860
890
|
var _extensions = /* @__PURE__ */ new WeakMap();
|
|
861
891
|
var _include = /* @__PURE__ */ new WeakMap();
|
|
862
892
|
var _exclude = /* @__PURE__ */ new WeakMap();
|
|
@@ -864,7 +894,6 @@ var _base = /* @__PURE__ */ new WeakMap();
|
|
|
864
894
|
var _tempDir = /* @__PURE__ */ new WeakMap();
|
|
865
895
|
var _pluginDriver = /* @__PURE__ */ new WeakMap();
|
|
866
896
|
var _writeTempFile = /* @__PURE__ */ new WeakSet();
|
|
867
|
-
var _getLang = /* @__PURE__ */ new WeakSet();
|
|
868
897
|
var _generateRouteInfo = /* @__PURE__ */ new WeakSet();
|
|
869
898
|
var RouteService = class {
|
|
870
899
|
async init() {
|
|
@@ -884,15 +913,15 @@ var RouteService = class {
|
|
|
884
913
|
}).sort();
|
|
885
914
|
files.forEach((filePath) => {
|
|
886
915
|
const fileRelativePath = normalizePath(path7.relative(_class_private_field_get(this, _scanDir), filePath));
|
|
887
|
-
const lang =
|
|
888
|
-
const routePath = normalizeRoutePath(fileRelativePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base));
|
|
916
|
+
const { routePath, lang, version } = normalizeRoutePath(fileRelativePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base), _class_private_field_get(this, _defaultVersion));
|
|
889
917
|
const absolutePath = path7.join(_class_private_field_get(this, _scanDir), fileRelativePath);
|
|
890
918
|
const routeInfo = {
|
|
891
919
|
routePath,
|
|
892
920
|
absolutePath: normalizePath(absolutePath),
|
|
893
921
|
relativePath: fileRelativePath,
|
|
894
922
|
pageName: getPageKey(fileRelativePath),
|
|
895
|
-
lang
|
|
923
|
+
lang,
|
|
924
|
+
version
|
|
896
925
|
};
|
|
897
926
|
this.addRoute(routeInfo);
|
|
898
927
|
});
|
|
@@ -926,41 +955,43 @@ var RouteService = class {
|
|
|
926
955
|
}
|
|
927
956
|
removeRoute(filePath) {
|
|
928
957
|
const fileRelativePath = path7.relative(_class_private_field_get(this, _scanDir), filePath);
|
|
929
|
-
const routePath = normalizeRoutePath(fileRelativePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base));
|
|
958
|
+
const { routePath } = normalizeRoutePath(fileRelativePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base), _class_private_field_get(this, _defaultVersion));
|
|
930
959
|
this.routeData.delete(routePath);
|
|
931
960
|
}
|
|
932
961
|
getRoutes() {
|
|
933
962
|
return Array.from(this.routeData.values());
|
|
934
963
|
}
|
|
935
964
|
isExistRoute(routePath) {
|
|
936
|
-
const normalizedRoute = normalizeRoutePath(routePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base));
|
|
965
|
+
const { routePath: normalizedRoute } = normalizeRoutePath(routePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base), _class_private_field_get(this, _defaultVersion));
|
|
937
966
|
return this.routeData.get(normalizedRoute);
|
|
938
967
|
}
|
|
939
968
|
isEmpty() {
|
|
940
969
|
return this.routeData.size === 0;
|
|
941
970
|
}
|
|
942
|
-
generateRoutesCode(isStaticImport) {
|
|
971
|
+
generateRoutesCode(isStaticImport = false) {
|
|
972
|
+
return this.generateRoutesCodeByRouteMeta(this.getRoutes(), isStaticImport);
|
|
973
|
+
}
|
|
974
|
+
generateRoutesCodeByRouteMeta(routeMeta, isStaticImport) {
|
|
943
975
|
return `
|
|
944
976
|
import React from 'react';
|
|
945
977
|
import { lazyWithPreload } from "react-lazy-with-preload";
|
|
946
|
-
${
|
|
978
|
+
${routeMeta.map((route, index) => {
|
|
947
979
|
return isStaticImport ? `import * as Route${index} from '${route.absolutePath}';` : `const Route${index} = lazyWithPreload(() => import(/* webpackChunkName: "${route.pageName}" */'${route.absolutePath}'))`;
|
|
948
980
|
}).join("\n")}
|
|
949
981
|
export const routes = [
|
|
950
|
-
${
|
|
982
|
+
${routeMeta.map((route, index) => {
|
|
951
983
|
const preload = isStaticImport ? `() => Route${index}` : `async () => {
|
|
952
984
|
await Route${index}.preload();
|
|
953
985
|
return import("${route.absolutePath}");
|
|
954
986
|
}`;
|
|
955
987
|
const component = isStaticImport ? `Route${index}.default` : `Route${index}`;
|
|
956
|
-
return `{ path: '${route.routePath}', element: React.createElement(${component}), filePath: '${route.relativePath}', preload: ${preload}, lang: '${route.lang}' }`;
|
|
988
|
+
return `{ path: '${route.routePath}', element: React.createElement(${component}), filePath: '${route.relativePath}', preload: ${preload}, lang: '${route.lang}', version: '${route.version}' }`;
|
|
957
989
|
}).join(",\n")}
|
|
958
990
|
];
|
|
959
991
|
`;
|
|
960
992
|
}
|
|
961
993
|
constructor(scanDir, userConfig, tempDir, pluginDriver) {
|
|
962
994
|
_class_private_method_init(this, _writeTempFile);
|
|
963
|
-
_class_private_method_init(this, _getLang);
|
|
964
995
|
_class_private_method_init(this, _generateRouteInfo);
|
|
965
996
|
_define_property(this, "routeData", /* @__PURE__ */ new Map());
|
|
966
997
|
_class_private_field_init(this, _scanDir, {
|
|
@@ -971,9 +1002,9 @@ ${this.getRoutes().map((route, index) => {
|
|
|
971
1002
|
writable: true,
|
|
972
1003
|
value: void 0
|
|
973
1004
|
});
|
|
974
|
-
_class_private_field_init(this,
|
|
1005
|
+
_class_private_field_init(this, _defaultVersion, {
|
|
975
1006
|
writable: true,
|
|
976
|
-
value:
|
|
1007
|
+
value: ""
|
|
977
1008
|
});
|
|
978
1009
|
_class_private_field_init(this, _extensions, {
|
|
979
1010
|
writable: true,
|
|
@@ -1005,10 +1036,12 @@ ${this.getRoutes().map((route, index) => {
|
|
|
1005
1036
|
_class_private_field_set(this, _include, routeOptions.include || []);
|
|
1006
1037
|
_class_private_field_set(this, _exclude, routeOptions.exclude || []);
|
|
1007
1038
|
_class_private_field_set(this, _defaultLang, userConfig?.lang || "");
|
|
1008
|
-
_class_private_field_set(this, _langs, userConfig?.themeConfig?.locales?.map((locale) => locale.lang) || []);
|
|
1009
1039
|
_class_private_field_set(this, _base, userConfig?.base || "");
|
|
1010
1040
|
_class_private_field_set(this, _tempDir, tempDir);
|
|
1011
1041
|
_class_private_field_set(this, _pluginDriver, pluginDriver);
|
|
1042
|
+
if (userConfig.multiVersion) {
|
|
1043
|
+
_class_private_field_set(this, _defaultVersion, userConfig.multiVersion.default || "");
|
|
1044
|
+
}
|
|
1012
1045
|
}
|
|
1013
1046
|
};
|
|
1014
1047
|
async function writeTempFile(index, content) {
|
|
@@ -1016,16 +1049,15 @@ async function writeTempFile(index, content) {
|
|
|
1016
1049
|
await fs7.writeFile(tempFilePath, content);
|
|
1017
1050
|
return tempFilePath;
|
|
1018
1051
|
}
|
|
1019
|
-
function getLang(filepath) {
|
|
1020
|
-
return _class_private_field_get(this, _langs).find((lang) => filepath.startsWith(lang)) || _class_private_field_get(this, _defaultLang);
|
|
1021
|
-
}
|
|
1022
1052
|
function generateRouteInfo(routePath, filepath) {
|
|
1053
|
+
const { routePath: normalizedPath, lang, version } = normalizeRoutePath(routePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base), _class_private_field_get(this, _defaultVersion));
|
|
1023
1054
|
return {
|
|
1024
|
-
routePath:
|
|
1055
|
+
routePath: normalizedPath,
|
|
1025
1056
|
absolutePath: normalizePath(filepath),
|
|
1026
1057
|
relativePath: normalizePath(path7.relative(_class_private_field_get(this, _scanDir), filepath)),
|
|
1027
1058
|
pageName: getPageKey(routePath),
|
|
1028
|
-
lang
|
|
1059
|
+
lang,
|
|
1060
|
+
version
|
|
1029
1061
|
};
|
|
1030
1062
|
}
|
|
1031
1063
|
|
|
@@ -1370,6 +1402,7 @@ var PluginDriver = class {
|
|
|
1370
1402
|
});
|
|
1371
1403
|
_class_private_field_set2(this, _config, config);
|
|
1372
1404
|
_class_private_field_set2(this, _isProd, isProd);
|
|
1405
|
+
_class_private_field_set2(this, _plugins, []);
|
|
1373
1406
|
}
|
|
1374
1407
|
};
|
|
1375
1408
|
|