@rspress/core 1.7.0 → 1.7.2

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 CHANGED
@@ -4583,22 +4583,28 @@ var DEFAULT_PAGE_EXTENSIONS = ["js", "jsx", "ts", "tsx", "md", "mdx"];
4583
4583
  var addLeadingSlash3 = (str2) => {
4584
4584
  return str2.startsWith("/") ? str2 : `/${str2}`;
4585
4585
  };
4586
- var normalizeRoutePath = (routePath, lang, base, version) => {
4586
+ var normalizeRoutePath = (routePath, base, lang, version, langs, versions) => {
4587
4587
  const hasTrailSlash = routePath.endsWith("/");
4588
4588
  let versionPart = "";
4589
4589
  let langPart = "";
4590
4590
  let purePathPart = "";
4591
4591
  const parts = routePath.split("/").filter(Boolean);
4592
4592
  if (version) {
4593
- const versionToMatch = parts.shift();
4594
- if (versionToMatch !== version) {
4595
- versionPart = versionToMatch;
4593
+ const versionToMatch = parts[0];
4594
+ if (versions.includes(versionToMatch)) {
4595
+ if (versionToMatch !== version) {
4596
+ versionPart = versionToMatch;
4597
+ }
4598
+ parts.shift();
4596
4599
  }
4597
4600
  }
4598
4601
  if (lang) {
4599
- const langToMatch = parts.shift();
4600
- if (langToMatch !== lang) {
4601
- langPart = langToMatch;
4602
+ const langToMatch = parts[0];
4603
+ if (langs.includes(langToMatch)) {
4604
+ if (langToMatch !== lang) {
4605
+ langPart = langToMatch;
4606
+ }
4607
+ parts.shift();
4602
4608
  }
4603
4609
  }
4604
4610
  purePathPart = parts.join("/");
@@ -4614,16 +4620,19 @@ var normalizeRoutePath = (routePath, lang, base, version) => {
4614
4620
  version: versionPart || version
4615
4621
  };
4616
4622
  };
4617
- var _scanDir, _defaultLang, _defaultVersion, _extensions, _include, _exclude, _base, _tempDir, _pluginDriver, _writeTempFile, writeTempFile_fn, _generateRouteInfo, generateRouteInfo_fn;
4623
+ var _scanDir, _defaultLang, _defaultVersion, _extensions, _langs, _versions, _include, _exclude, _base, _tempDir, _pluginDriver, _writeTempFile, writeTempFile_fn, _generateRouteInfo, generateRouteInfo_fn, _normalizeRoutePath, normalizeRoutePath_fn;
4618
4624
  var RouteService = class {
4619
4625
  constructor(scanDir, userConfig, tempDir, pluginDriver) {
4620
4626
  __privateAdd(this, _writeTempFile);
4621
4627
  __privateAdd(this, _generateRouteInfo);
4628
+ __privateAdd(this, _normalizeRoutePath);
4622
4629
  __publicField(this, "routeData", /* @__PURE__ */ new Map());
4623
4630
  __privateAdd(this, _scanDir, void 0);
4624
4631
  __privateAdd(this, _defaultLang, void 0);
4625
4632
  __privateAdd(this, _defaultVersion, "");
4626
4633
  __privateAdd(this, _extensions, []);
4634
+ __privateAdd(this, _langs, []);
4635
+ __privateAdd(this, _versions, []);
4627
4636
  __privateAdd(this, _include, []);
4628
4637
  __privateAdd(this, _exclude, []);
4629
4638
  __privateAdd(this, _base, "");
@@ -4635,11 +4644,13 @@ var RouteService = class {
4635
4644
  __privateSet(this, _include, routeOptions.include || []);
4636
4645
  __privateSet(this, _exclude, routeOptions.exclude || []);
4637
4646
  __privateSet(this, _defaultLang, userConfig?.lang || "");
4647
+ __privateSet(this, _langs, (userConfig?.locales ?? userConfig?.themeConfig?.locales ?? []).map((item) => item.lang));
4638
4648
  __privateSet(this, _base, userConfig?.base || "");
4639
4649
  __privateSet(this, _tempDir, tempDir);
4640
4650
  __privateSet(this, _pluginDriver, pluginDriver);
4641
4651
  if (userConfig.multiVersion) {
4642
4652
  __privateSet(this, _defaultVersion, userConfig.multiVersion.default || "");
4653
+ __privateSet(this, _versions, userConfig.multiVersion.versions || []);
4643
4654
  }
4644
4655
  }
4645
4656
  async init() {
@@ -4660,9 +4671,11 @@ var RouteService = class {
4660
4671
  );
4661
4672
  const { routePath, lang, version } = normalizeRoutePath(
4662
4673
  fileRelativePath,
4663
- __privateGet(this, _defaultLang),
4664
4674
  __privateGet(this, _base),
4665
- __privateGet(this, _defaultVersion)
4675
+ __privateGet(this, _defaultLang),
4676
+ __privateGet(this, _defaultVersion),
4677
+ __privateGet(this, _langs),
4678
+ __privateGet(this, _versions)
4666
4679
  );
4667
4680
  const absolutePath = path9.join(__privateGet(this, _scanDir), fileRelativePath);
4668
4681
  const routeInfo = {
@@ -4711,24 +4724,14 @@ var RouteService = class {
4711
4724
  }
4712
4725
  removeRoute(filePath) {
4713
4726
  const fileRelativePath = path9.relative(__privateGet(this, _scanDir), filePath);
4714
- const { routePath } = normalizeRoutePath(
4715
- fileRelativePath,
4716
- __privateGet(this, _defaultLang),
4717
- __privateGet(this, _base),
4718
- __privateGet(this, _defaultVersion)
4719
- );
4727
+ const { routePath } = __privateMethod(this, _normalizeRoutePath, normalizeRoutePath_fn).call(this, fileRelativePath);
4720
4728
  this.routeData.delete(routePath);
4721
4729
  }
4722
4730
  getRoutes() {
4723
4731
  return Array.from(this.routeData.values());
4724
4732
  }
4725
4733
  isExistRoute(routePath) {
4726
- const { routePath: normalizedRoute } = normalizeRoutePath(
4727
- routePath,
4728
- __privateGet(this, _defaultLang),
4729
- __privateGet(this, _base),
4730
- __privateGet(this, _defaultVersion)
4731
- );
4734
+ const { routePath: normalizedRoute } = __privateMethod(this, _normalizeRoutePath, normalizeRoutePath_fn).call(this, routePath);
4732
4735
  return this.routeData.get(normalizedRoute);
4733
4736
  }
4734
4737
  isEmpty() {
@@ -4761,6 +4764,8 @@ _scanDir = new WeakMap();
4761
4764
  _defaultLang = new WeakMap();
4762
4765
  _defaultVersion = new WeakMap();
4763
4766
  _extensions = new WeakMap();
4767
+ _langs = new WeakMap();
4768
+ _versions = new WeakMap();
4764
4769
  _include = new WeakMap();
4765
4770
  _exclude = new WeakMap();
4766
4771
  _base = new WeakMap();
@@ -4778,12 +4783,7 @@ generateRouteInfo_fn = function(routePath, filepath) {
4778
4783
  routePath: normalizedPath,
4779
4784
  lang,
4780
4785
  version
4781
- } = normalizeRoutePath(
4782
- routePath,
4783
- __privateGet(this, _defaultLang),
4784
- __privateGet(this, _base),
4785
- __privateGet(this, _defaultVersion)
4786
- );
4786
+ } = __privateMethod(this, _normalizeRoutePath, normalizeRoutePath_fn).call(this, routePath);
4787
4787
  return {
4788
4788
  routePath: normalizedPath,
4789
4789
  absolutePath: normalizePath(filepath),
@@ -4793,6 +4793,17 @@ generateRouteInfo_fn = function(routePath, filepath) {
4793
4793
  version
4794
4794
  };
4795
4795
  };
4796
+ _normalizeRoutePath = new WeakSet();
4797
+ normalizeRoutePath_fn = function(routePath) {
4798
+ return normalizeRoutePath(
4799
+ routePath,
4800
+ __privateGet(this, _base),
4801
+ __privateGet(this, _defaultLang),
4802
+ __privateGet(this, _defaultVersion),
4803
+ __privateGet(this, _langs),
4804
+ __privateGet(this, _versions)
4805
+ );
4806
+ };
4796
4807
 
4797
4808
  // src/node/route/init.ts
4798
4809
  var routeService = null;