@rspress/core 0.1.1 → 1.0.0-beta.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.
Files changed (42) hide show
  1. package/dist/index.js +62 -24
  2. package/dist/index.js.map +1 -1
  3. package/dist/loader.d.ts +1 -1
  4. package/dist/loader.js +17 -33
  5. package/dist/loader.js.map +1 -1
  6. package/dist/runtime/App.js +4 -4
  7. package/dist/runtime/Content.js +14 -2
  8. package/dist/runtime/hooks.d.ts +17 -0
  9. package/dist/runtime/hooks.js +27 -1
  10. package/dist/runtime/index.d.ts +1 -1
  11. package/dist/runtime/index.js +1 -1
  12. package/dist/runtime/utils.d.ts +3 -2
  13. package/dist/runtime/utils.js +6 -2
  14. package/dist/theme/bundle.css +44 -4
  15. package/dist/theme/bundle.d.ts +6 -1
  16. package/dist/theme/bundle.js +150 -77
  17. package/dist/theme/bundle.js.map +1 -1
  18. package/package.json +7 -7
  19. package/src/runtime/App.tsx +5 -6
  20. package/src/runtime/Content.tsx +24 -2
  21. package/src/runtime/global.d.ts +4 -5
  22. package/src/runtime/hooks.ts +67 -1
  23. package/src/runtime/index.ts +1 -1
  24. package/src/runtime/utils.ts +9 -8
  25. package/src/theme-default/components/DocFooter/index.tsx +1 -1
  26. package/src/theme-default/components/HomeHero/index.tsx +1 -1
  27. package/src/theme-default/components/Link/index.module.scss +0 -1
  28. package/src/theme-default/components/Link/index.tsx +21 -2
  29. package/src/theme-default/components/Nav/NavMenuSingleItem.tsx +1 -1
  30. package/src/theme-default/components/Nav/index.tsx +19 -5
  31. package/src/theme-default/components/Overview/index.tsx +1 -1
  32. package/src/theme-default/components/Search/logic/search.ts +1 -1
  33. package/src/theme-default/components/Sidebar/SidebarGroup.tsx +1 -1
  34. package/src/theme-default/components/Sidebar/SidebarItem.tsx +1 -1
  35. package/src/theme-default/index.ts +2 -0
  36. package/src/theme-default/layout/DocLayout/docComponents/index.module.scss +4 -0
  37. package/src/theme-default/layout/DocLayout/docComponents/link.tsx +14 -23
  38. package/src/theme-default/layout/DocLayout/index.module.scss +46 -0
  39. package/src/theme-default/layout/HomeLayout/index.tsx +1 -0
  40. package/src/theme-default/logic/index.ts +1 -0
  41. package/src/theme-default/logic/sideEffects.ts +7 -0
  42. package/src/theme-default/logic/usePathUtils.ts +73 -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
  };
@@ -554,10 +555,16 @@ async function siteDataVMPlugin(context) {
554
555
  title: userConfig?.title || "",
555
556
  description: userConfig?.description || "",
556
557
  icon: userConfig?.icon || "",
558
+ route: userConfig?.route,
557
559
  themeConfig: normalizeThemeConfig(userConfig, pages),
558
560
  base: userConfig?.base || "/",
559
561
  lang: userConfig?.lang || "",
562
+ locales: userConfig?.locales || userConfig.themeConfig?.locales || [],
560
563
  logo: userConfig?.logo || "",
564
+ multiVersion: {
565
+ default: userConfig?.multiVersion?.default || "",
566
+ versions: userConfig?.multiVersion?.versions || []
567
+ },
561
568
  search: userConfig?.search ?? {
562
569
  mode: "local"
563
570
  },
@@ -849,14 +856,42 @@ var DEFAULT_PAGE_EXTENSIONS = [
849
856
  var addLeadingSlash3 = (str) => {
850
857
  return str.startsWith("/") ? str : `/${str}`;
851
858
  };
852
- var normalizeRoutePath = (routePath, lang, base) => {
853
- let normalizedRoutePath = routePath.replace(/^\//, "").replace(new RegExp(`^${lang}`), "").replace(/\.[^.]+$/, "");
854
- normalizedRoutePath = addLeadingSlash3(normalizedRoutePath).replace(/\/index$/, "/");
855
- return withBase2(normalizedRoutePath, base);
859
+ var normalizeRoutePath = (routePath, lang, base, version) => {
860
+ const hasTrailSlash = routePath.endsWith("/");
861
+ let versionPart = "";
862
+ let langPart = "";
863
+ let purePathPart = "";
864
+ const parts = routePath.split("/").filter(Boolean);
865
+ if (version) {
866
+ const versionToMatch = parts.shift();
867
+ if (versionToMatch !== version) {
868
+ versionPart = versionToMatch;
869
+ }
870
+ }
871
+ if (lang) {
872
+ const langToMatch = parts.shift();
873
+ if (langToMatch !== lang) {
874
+ langPart = langToMatch;
875
+ }
876
+ }
877
+ purePathPart = parts.join("/");
878
+ let normalizedRoutePath = addLeadingSlash3([
879
+ versionPart,
880
+ langPart,
881
+ purePathPart
882
+ ].filter(Boolean).join("/")).replace(/\.[^.]+$/, "").replace(/\/index$/, "/");
883
+ if (hasTrailSlash && !normalizedRoutePath.endsWith("/")) {
884
+ normalizedRoutePath = `${normalizedRoutePath}/`;
885
+ }
886
+ return {
887
+ routePath: withBase2(normalizedRoutePath, base),
888
+ lang: langPart || lang,
889
+ version: versionPart || version
890
+ };
856
891
  };
857
892
  var _scanDir = /* @__PURE__ */ new WeakMap();
858
893
  var _defaultLang = /* @__PURE__ */ new WeakMap();
859
- var _langs = /* @__PURE__ */ new WeakMap();
894
+ var _defaultVersion = /* @__PURE__ */ new WeakMap();
860
895
  var _extensions = /* @__PURE__ */ new WeakMap();
861
896
  var _include = /* @__PURE__ */ new WeakMap();
862
897
  var _exclude = /* @__PURE__ */ new WeakMap();
@@ -864,7 +899,6 @@ var _base = /* @__PURE__ */ new WeakMap();
864
899
  var _tempDir = /* @__PURE__ */ new WeakMap();
865
900
  var _pluginDriver = /* @__PURE__ */ new WeakMap();
866
901
  var _writeTempFile = /* @__PURE__ */ new WeakSet();
867
- var _getLang = /* @__PURE__ */ new WeakSet();
868
902
  var _generateRouteInfo = /* @__PURE__ */ new WeakSet();
869
903
  var RouteService = class {
870
904
  async init() {
@@ -884,15 +918,15 @@ var RouteService = class {
884
918
  }).sort();
885
919
  files.forEach((filePath) => {
886
920
  const fileRelativePath = normalizePath(path7.relative(_class_private_field_get(this, _scanDir), filePath));
887
- const lang = _class_private_method_get(this, _getLang, getLang).call(this, fileRelativePath);
888
- const routePath = normalizeRoutePath(fileRelativePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base));
921
+ 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
922
  const absolutePath = path7.join(_class_private_field_get(this, _scanDir), fileRelativePath);
890
923
  const routeInfo = {
891
924
  routePath,
892
925
  absolutePath: normalizePath(absolutePath),
893
926
  relativePath: fileRelativePath,
894
927
  pageName: getPageKey(fileRelativePath),
895
- lang
928
+ lang,
929
+ version
896
930
  };
897
931
  this.addRoute(routeInfo);
898
932
  });
@@ -926,41 +960,43 @@ var RouteService = class {
926
960
  }
927
961
  removeRoute(filePath) {
928
962
  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));
963
+ const { routePath } = normalizeRoutePath(fileRelativePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base), _class_private_field_get(this, _defaultVersion));
930
964
  this.routeData.delete(routePath);
931
965
  }
932
966
  getRoutes() {
933
967
  return Array.from(this.routeData.values());
934
968
  }
935
969
  isExistRoute(routePath) {
936
- const normalizedRoute = normalizeRoutePath(routePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base));
970
+ const { routePath: normalizedRoute } = normalizeRoutePath(routePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base), _class_private_field_get(this, _defaultVersion));
937
971
  return this.routeData.get(normalizedRoute);
938
972
  }
939
973
  isEmpty() {
940
974
  return this.routeData.size === 0;
941
975
  }
942
- generateRoutesCode(isStaticImport) {
976
+ generateRoutesCode(isStaticImport = false) {
977
+ return this.generateRoutesCodeByRouteMeta(this.getRoutes(), isStaticImport);
978
+ }
979
+ generateRoutesCodeByRouteMeta(routeMeta, isStaticImport) {
943
980
  return `
944
981
  import React from 'react';
945
982
  import { lazyWithPreload } from "react-lazy-with-preload";
946
- ${this.getRoutes().map((route, index) => {
983
+ ${routeMeta.map((route, index) => {
947
984
  return isStaticImport ? `import * as Route${index} from '${route.absolutePath}';` : `const Route${index} = lazyWithPreload(() => import(/* webpackChunkName: "${route.pageName}" */'${route.absolutePath}'))`;
948
985
  }).join("\n")}
949
986
  export const routes = [
950
- ${this.getRoutes().map((route, index) => {
987
+ ${routeMeta.map((route, index) => {
951
988
  const preload = isStaticImport ? `() => Route${index}` : `async () => {
952
989
  await Route${index}.preload();
953
990
  return import("${route.absolutePath}");
954
991
  }`;
955
992
  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}' }`;
993
+ return `{ path: '${route.routePath}', element: React.createElement(${component}), filePath: '${route.relativePath}', preload: ${preload}, lang: '${route.lang}', version: '${route.version}' }`;
957
994
  }).join(",\n")}
958
995
  ];
959
996
  `;
960
997
  }
961
998
  constructor(scanDir, userConfig, tempDir, pluginDriver) {
962
999
  _class_private_method_init(this, _writeTempFile);
963
- _class_private_method_init(this, _getLang);
964
1000
  _class_private_method_init(this, _generateRouteInfo);
965
1001
  _define_property(this, "routeData", /* @__PURE__ */ new Map());
966
1002
  _class_private_field_init(this, _scanDir, {
@@ -971,9 +1007,9 @@ ${this.getRoutes().map((route, index) => {
971
1007
  writable: true,
972
1008
  value: void 0
973
1009
  });
974
- _class_private_field_init(this, _langs, {
1010
+ _class_private_field_init(this, _defaultVersion, {
975
1011
  writable: true,
976
- value: void 0
1012
+ value: ""
977
1013
  });
978
1014
  _class_private_field_init(this, _extensions, {
979
1015
  writable: true,
@@ -1005,10 +1041,12 @@ ${this.getRoutes().map((route, index) => {
1005
1041
  _class_private_field_set(this, _include, routeOptions.include || []);
1006
1042
  _class_private_field_set(this, _exclude, routeOptions.exclude || []);
1007
1043
  _class_private_field_set(this, _defaultLang, userConfig?.lang || "");
1008
- _class_private_field_set(this, _langs, userConfig?.themeConfig?.locales?.map((locale) => locale.lang) || []);
1009
1044
  _class_private_field_set(this, _base, userConfig?.base || "");
1010
1045
  _class_private_field_set(this, _tempDir, tempDir);
1011
1046
  _class_private_field_set(this, _pluginDriver, pluginDriver);
1047
+ if (userConfig.multiVersion) {
1048
+ _class_private_field_set(this, _defaultVersion, userConfig.multiVersion.default || "");
1049
+ }
1012
1050
  }
1013
1051
  };
1014
1052
  async function writeTempFile(index, content) {
@@ -1016,16 +1054,15 @@ async function writeTempFile(index, content) {
1016
1054
  await fs7.writeFile(tempFilePath, content);
1017
1055
  return tempFilePath;
1018
1056
  }
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
1057
  function generateRouteInfo(routePath, filepath) {
1058
+ 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
1059
  return {
1024
- routePath: normalizeRoutePath(routePath, _class_private_field_get(this, _defaultLang), _class_private_field_get(this, _base)),
1060
+ routePath: normalizedPath,
1025
1061
  absolutePath: normalizePath(filepath),
1026
1062
  relativePath: normalizePath(path7.relative(_class_private_field_get(this, _scanDir), filepath)),
1027
1063
  pageName: getPageKey(routePath),
1028
- lang: _class_private_method_get(this, _getLang, getLang).call(this, filepath)
1064
+ lang,
1065
+ version
1029
1066
  };
1030
1067
  }
1031
1068
 
@@ -1370,6 +1407,7 @@ var PluginDriver = class {
1370
1407
  });
1371
1408
  _class_private_field_set2(this, _config, config);
1372
1409
  _class_private_field_set2(this, _isProd, isProd);
1410
+ _class_private_field_set2(this, _plugins, []);
1373
1411
  }
1374
1412
  };
1375
1413