@rspress/core 1.18.1 → 1.18.3

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
@@ -66,7 +66,7 @@ var require_package = __commonJS({
66
66
  "package.json"(exports, module) {
67
67
  module.exports = {
68
68
  name: "@rspress/core",
69
- version: "1.18.1",
69
+ version: "1.18.3",
70
70
  description: "The Rspress Documentation Framework",
71
71
  bugs: "https://github.com/web-infra-dev/rspress/issues",
72
72
  repository: {
@@ -105,11 +105,11 @@ var require_package = __commonJS({
105
105
  node: ">=14.17.6"
106
106
  },
107
107
  dependencies: {
108
- "@loadable/component": "5.15.2",
108
+ "@loadable/component": "5.16.4",
109
109
  "@mdx-js/loader": "2.3.0",
110
110
  "@mdx-js/mdx": "2.3.0",
111
111
  "@mdx-js/react": "2.3.0",
112
- "@modern-js/utils": "2.48.5",
112
+ "@modern-js/utils": "2.49.0",
113
113
  "@rsbuild/core": "0.6.1",
114
114
  "@rsbuild/plugin-react": "0.6.1",
115
115
  "@rspress/theme-default": "workspace:*",
@@ -124,13 +124,12 @@ var require_package = __commonJS({
124
124
  "copy-to-clipboard": "^3.3.3",
125
125
  "enhanced-resolve": "5.16.0",
126
126
  flexsearch: "0.6.32",
127
- "fs-extra": "10.1.0",
128
127
  "github-slugger": "^2.0.0",
129
128
  "hast-util-from-html": "^1.0.0",
130
129
  "hast-util-heading-rank": "^3.0.0",
131
130
  "html-to-text": "^9.0.3",
132
131
  htmr: "^1.0.2",
133
- "is-html": "^3.0.0",
132
+ "is-html": "^3.1.0",
134
133
  "lodash-es": "^4.17.21",
135
134
  "mdast-util-mdxjs-esm": "^1.3.0",
136
135
  "node-fetch": "3.3.0",
@@ -157,10 +156,9 @@ var require_package = __commonJS({
157
156
  },
158
157
  devDependencies: {
159
158
  tailwindcss: "^3.2.7",
160
- "@modern-js/plugin-tailwindcss": "2.48.5",
161
- "@modern-js/tsconfig": "2.48.5",
159
+ "@modern-js/plugin-tailwindcss": "2.49.0",
160
+ "@modern-js/tsconfig": "2.49.0",
162
161
  "@types/body-scroll-lock": "^3.1.0",
163
- "@types/fs-extra": "^9.0.13",
164
162
  "@types/hast": "^2.3.4",
165
163
  "@types/html-to-text": "^8.1.1",
166
164
  "@types/jest": "^26.0.9",
@@ -260,7 +258,6 @@ var TEMP_DIR = path.join(
260
258
  import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
261
259
 
262
260
  // src/node/runtimeModule/routeData.ts
263
- import { addLeadingSlash } from "@rspress/shared";
264
261
  async function routeVMPlugin(context) {
265
262
  const { routeService: routeService2 } = context;
266
263
  return {
@@ -271,13 +268,14 @@ async function routeVMPlugin(context) {
271
268
 
272
269
  // src/node/runtimeModule/siteData/index.ts
273
270
  import path6 from "path";
271
+ import { groupBy } from "lodash-es";
274
272
  import { SEARCH_INDEX_NAME } from "@rspress/shared";
275
273
  import fs4 from "@rspress/shared/fs-extra";
276
274
 
277
275
  // src/node/runtimeModule/siteData/normalizeThemeConfig.ts
278
276
  import {
279
277
  withBase,
280
- addLeadingSlash as addLeadingSlash2,
278
+ addLeadingSlash,
281
279
  isExternalUrl,
282
280
  withoutBase,
283
281
  slash
@@ -333,7 +331,7 @@ function normalizeThemeConfig(docConfig, pages = []) {
333
331
  hasMultiVersion) {
334
332
  return normalizedLink;
335
333
  }
336
- return lang === currentLang ? normalizedLink : `/${currentLang}${addLeadingSlash2(normalizedLink)}`;
334
+ return lang === currentLang ? normalizedLink : `/${currentLang}${addLeadingSlash(normalizedLink)}`;
337
335
  };
338
336
  const getI18nText = (key = "", currentLang = "") => {
339
337
  const text = i18nTextData[key]?.[currentLang];
@@ -804,34 +802,34 @@ async function siteDataVMPlugin(context) {
804
802
  routeService2
805
803
  )).filter(Boolean);
806
804
  await pluginDriver.modifySearchIndexData(pages);
807
- const pagesByLang = pages.reduce(
808
- (acc, page) => {
809
- if (!acc[page.lang]) {
810
- acc[page.lang] = [];
811
- }
812
- if (page.frontmatter?.pageType === "home") {
813
- return acc;
814
- }
815
- acc[page.lang].push(page);
816
- return acc;
817
- },
818
- {}
819
- );
820
- const indexHashByLang = {};
805
+ const versioned = userConfig.search && userConfig.search.mode !== "remote" && userConfig.search.versioned;
806
+ const groupedPages = groupBy(pages, (page) => {
807
+ if (page.frontmatter?.pageType === "home") {
808
+ return "noindex";
809
+ }
810
+ const version = versioned ? page.version : "";
811
+ const lang = page.lang || "";
812
+ return `${version}###${lang}`;
813
+ });
814
+ delete groupedPages.noindex;
815
+ const indexHashByGroup = {};
821
816
  await Promise.all(
822
- Object.keys(pagesByLang).map(async (lang) => {
823
- const stringfiedIndex = JSON.stringify(
824
- pagesByLang[lang].map(deletePriviteKey)
817
+ Object.keys(groupedPages).map(async (group) => {
818
+ const stringifiedIndex = JSON.stringify(
819
+ groupedPages[group].map(deletePriviteKey)
825
820
  );
826
- const indexHash = createHash(stringfiedIndex);
827
- indexHashByLang[lang] = indexHash;
821
+ const indexHash = createHash(stringifiedIndex);
822
+ indexHashByGroup[group] = indexHash;
823
+ const [version, lang] = group.split("###");
824
+ const indexVersion = version ? `.${version.replace(".", "_")}` : "";
825
+ const indexLang = lang ? `.${lang}` : "";
828
826
  await fs4.ensureDir(TEMP_DIR);
829
827
  await fs4.writeFile(
830
828
  path6.join(
831
829
  TEMP_DIR,
832
- `${SEARCH_INDEX_NAME}${lang ? `.${lang}` : ""}.${indexHash}.json`
830
+ `${SEARCH_INDEX_NAME}${indexVersion}${indexLang}.${indexHash}.json`
833
831
  ),
834
- stringfiedIndex
832
+ stringifiedIndex
835
833
  );
836
834
  })
837
835
  );
@@ -870,7 +868,7 @@ async function siteDataVMPlugin(context) {
870
868
  siteData
871
869
  )}`,
872
870
  ["virtual-search-index-hash" /* SearchIndexHash */]: `export default ${JSON.stringify(
873
- indexHashByLang
871
+ indexHashByGroup
874
872
  )}`
875
873
  };
876
874
  }
@@ -1116,12 +1114,13 @@ function serveSearchIndexMiddleware(config) {
1116
1114
  // src/node/route/RouteService.ts
1117
1115
  import path9 from "path";
1118
1116
  import fs7 from "@rspress/shared/fs-extra";
1119
- import { withBase as withBase2 } from "@rspress/shared";
1117
+ import {
1118
+ addLeadingSlash as addLeadingSlash2,
1119
+ addTrailingSlash,
1120
+ withBase as withBase2
1121
+ } from "@rspress/shared";
1120
1122
  var DEFAULT_PAGE_EXTENSIONS = ["js", "jsx", "ts", "tsx", "md", "mdx"];
1121
- var addLeadingSlash3 = (str) => {
1122
- return str.startsWith("/") ? str : `/${str}`;
1123
- };
1124
- var normalizeRoutePath = (routePath, base, lang, version, langs, versions) => {
1123
+ var normalizeRoutePath = (routePath, base, lang, version, langs, versions, extensions = DEFAULT_PAGE_EXTENSIONS) => {
1125
1124
  const hasTrailSlash = routePath.endsWith("/");
1126
1125
  let versionPart = "";
1127
1126
  let langPart = "";
@@ -1146,11 +1145,11 @@ var normalizeRoutePath = (routePath, base, lang, version, langs, versions) => {
1146
1145
  }
1147
1146
  }
1148
1147
  purePathPart = parts.join("/");
1149
- let normalizedRoutePath = addLeadingSlash3(
1148
+ let normalizedRoutePath = addLeadingSlash2(
1150
1149
  [versionPart, langPart, purePathPart].filter(Boolean).join("/")
1151
- ).replace(/\.[^.]+$/, "").replace(/\/index$/, "/");
1152
- if (hasTrailSlash && !normalizedRoutePath.endsWith("/")) {
1153
- normalizedRoutePath = `${normalizedRoutePath}/`;
1150
+ ).replace(new RegExp(`\\.(${extensions.join("|")})$`), "").replace(/\.html$/, "").replace(/\/index$/, "/");
1151
+ if (hasTrailSlash) {
1152
+ normalizedRoutePath = addTrailingSlash(normalizedRoutePath);
1154
1153
  }
1155
1154
  return {
1156
1155
  routePath: withBase2(normalizedRoutePath, base),
@@ -1158,12 +1157,11 @@ var normalizeRoutePath = (routePath, base, lang, version, langs, versions) => {
1158
1157
  version: versionPart || version
1159
1158
  };
1160
1159
  };
1161
- var _scanDir, _defaultLang, _defaultVersion, _extensions, _langs, _versions, _include, _exclude, _base, _tempDir, _pluginDriver, _writeTempFile, writeTempFile_fn, _generateRouteInfo, generateRouteInfo_fn, _normalizeRoutePath, normalizeRoutePath_fn;
1160
+ var _scanDir, _defaultLang, _defaultVersion, _extensions, _langs, _versions, _include, _exclude, _base, _tempDir, _pluginDriver, _writeTempFile, writeTempFile_fn, _generateRouteInfo, generateRouteInfo_fn;
1162
1161
  var RouteService = class {
1163
1162
  constructor(scanDir, userConfig, tempDir, pluginDriver) {
1164
1163
  __privateAdd(this, _writeTempFile);
1165
1164
  __privateAdd(this, _generateRouteInfo);
1166
- __privateAdd(this, _normalizeRoutePath);
1167
1165
  __publicField(this, "routeData", /* @__PURE__ */ new Map());
1168
1166
  __privateAdd(this, _scanDir, void 0);
1169
1167
  __privateAdd(this, _defaultLang, void 0);
@@ -1211,14 +1209,7 @@ var RouteService = class {
1211
1209
  const fileRelativePath = normalizePath(
1212
1210
  path9.relative(__privateGet(this, _scanDir), filePath)
1213
1211
  );
1214
- const { routePath, lang, version } = normalizeRoutePath(
1215
- fileRelativePath,
1216
- __privateGet(this, _base),
1217
- __privateGet(this, _defaultLang),
1218
- __privateGet(this, _defaultVersion),
1219
- __privateGet(this, _langs),
1220
- __privateGet(this, _versions)
1221
- );
1212
+ const { routePath, lang, version } = this.normalizeRoutePath(fileRelativePath);
1222
1213
  const absolutePath = path9.join(__privateGet(this, _scanDir), fileRelativePath);
1223
1214
  const routeInfo = {
1224
1215
  routePath,
@@ -1266,14 +1257,14 @@ var RouteService = class {
1266
1257
  }
1267
1258
  removeRoute(filePath) {
1268
1259
  const fileRelativePath = path9.relative(__privateGet(this, _scanDir), filePath);
1269
- const { routePath } = __privateMethod(this, _normalizeRoutePath, normalizeRoutePath_fn).call(this, fileRelativePath);
1260
+ const { routePath } = this.normalizeRoutePath(fileRelativePath);
1270
1261
  this.routeData.delete(routePath);
1271
1262
  }
1272
1263
  getRoutes() {
1273
1264
  return Array.from(this.routeData.values());
1274
1265
  }
1275
1266
  isExistRoute(routePath) {
1276
- const { routePath: normalizedRoute } = __privateMethod(this, _normalizeRoutePath, normalizeRoutePath_fn).call(this, routePath);
1267
+ const { routePath: normalizedRoute } = this.normalizeRoutePath(routePath);
1277
1268
  return this.routeData.get(normalizedRoute);
1278
1269
  }
1279
1270
  isEmpty() {
@@ -1301,6 +1292,17 @@ ${routeMeta.map((route, index) => {
1301
1292
  ];
1302
1293
  `;
1303
1294
  }
1295
+ normalizeRoutePath(routePath) {
1296
+ return normalizeRoutePath(
1297
+ routePath,
1298
+ __privateGet(this, _base),
1299
+ __privateGet(this, _defaultLang),
1300
+ __privateGet(this, _defaultVersion),
1301
+ __privateGet(this, _langs),
1302
+ __privateGet(this, _versions),
1303
+ __privateGet(this, _extensions)
1304
+ );
1305
+ }
1304
1306
  };
1305
1307
  _scanDir = new WeakMap();
1306
1308
  _defaultLang = new WeakMap();
@@ -1325,7 +1327,7 @@ generateRouteInfo_fn = function(routePath, filepath) {
1325
1327
  routePath: normalizedPath,
1326
1328
  lang,
1327
1329
  version
1328
- } = __privateMethod(this, _normalizeRoutePath, normalizeRoutePath_fn).call(this, routePath);
1330
+ } = this.normalizeRoutePath(routePath);
1329
1331
  return {
1330
1332
  routePath: normalizedPath,
1331
1333
  absolutePath: normalizePath(filepath),
@@ -1335,17 +1337,6 @@ generateRouteInfo_fn = function(routePath, filepath) {
1335
1337
  version
1336
1338
  };
1337
1339
  };
1338
- _normalizeRoutePath = new WeakSet();
1339
- normalizeRoutePath_fn = function(routePath) {
1340
- return normalizeRoutePath(
1341
- routePath,
1342
- __privateGet(this, _base),
1343
- __privateGet(this, _defaultLang),
1344
- __privateGet(this, _defaultVersion),
1345
- __privateGet(this, _langs),
1346
- __privateGet(this, _versions)
1347
- );
1348
- };
1349
1340
 
1350
1341
  // src/node/route/init.ts
1351
1342
  var routeService = null;