@rspress/core 1.41.2 → 1.42.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/193.js CHANGED
@@ -6,7 +6,7 @@ export const ids = [
6
6
  export const modules = {
7
7
  "./package.json": function(module) {
8
8
  module.exports = {
9
- version: "1.41.2"
9
+ version: "1.42.0"
10
10
  };
11
11
  }
12
12
  };
package/dist/index.js CHANGED
@@ -8,9 +8,11 @@ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_less_4c557a99__ from "@rsb
8
8
  import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__ from "@rsbuild/plugin-react";
9
9
  import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_sass_b13a7d33__ from "@rsbuild/plugin-sass";
10
10
  import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
11
+ import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__ from "@rspress/shared/constants";
11
12
  import * as __WEBPACK_EXTERNAL_MODULE_tinyglobby__ from "tinyglobby";
12
13
  import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
13
14
  import * as __WEBPACK_EXTERNAL_MODULE_rspack_plugin_virtual_module_609978fd__ from "rspack-plugin-virtual-module";
15
+ import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__ from "@rspress/shared/logger";
14
16
  import * as __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__ from "lodash-es";
15
17
  import * as __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__ from "node:crypto";
16
18
  import * as __WEBPACK_EXTERNAL_MODULE__rspress_mdx_rs_d2f3021f__ from "@rspress/mdx-rs";
@@ -19,15 +21,11 @@ import * as __WEBPACK_EXTERNAL_MODULE_html_to_text_2c51ed38__ from "html-to-text
19
21
  import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
20
22
  import * as __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__ from "@mdx-js/mdx";
21
23
  import * as __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__ from "enhanced-resolve";
24
+ import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
22
25
  import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
23
- import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__ from "@rspress/shared/logger";
24
26
  import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
25
27
  export * from "@rspress/shared";
26
- var __webpack_modules__ = {
27
- "react-syntax-highlighter/dist/cjs/languages/prism/supported-languages": function(module) {
28
- module.exports = require("react-syntax-highlighter/dist/cjs/languages/prism/supported-languages");
29
- }
30
- };
28
+ var __webpack_modules__ = {};
31
29
  var __webpack_module_cache__ = {};
32
30
  function __webpack_require__(moduleId) {
33
31
  var cachedModule = __webpack_module_cache__[moduleId];
@@ -343,6 +341,41 @@ function getPageKey(route) {
343
341
  const cleanRoute = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeLeadingSlash)(route);
344
342
  return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
345
343
  }
344
+ const normalizeRoutePath = (routePath, base, lang, version, langs, versions, extensions = __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS)=>{
345
+ const hasTrailSlash = routePath.endsWith('/');
346
+ let versionPart = '';
347
+ let langPart = '';
348
+ let purePathPart = '';
349
+ const parts = routePath.split('/').filter(Boolean);
350
+ if (version) {
351
+ const versionToMatch = parts[0];
352
+ if (versions.includes(versionToMatch)) {
353
+ if (versionToMatch !== version) versionPart = versionToMatch;
354
+ parts.shift();
355
+ }
356
+ }
357
+ if (lang) {
358
+ const langToMatch = parts[0];
359
+ if (langs.includes(langToMatch)) {
360
+ if (langToMatch !== lang) langPart = langToMatch;
361
+ parts.shift();
362
+ }
363
+ }
364
+ purePathPart = parts.join('/');
365
+ const extensionsWithoutDot = extensions.map((i)=>i.slice(1));
366
+ const cleanExtensionPattern = new RegExp(`\\.(${extensionsWithoutDot.join('|')})$`, 'i');
367
+ let normalizedRoutePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)([
368
+ versionPart,
369
+ langPart,
370
+ purePathPart
371
+ ].filter(Boolean).join('/')).replace(cleanExtensionPattern, '').replace(/\.html$/, '').replace(/\/index$/, '/');
372
+ if (hasTrailSlash) normalizedRoutePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addTrailingSlash)(normalizedRoutePath);
373
+ return {
374
+ routePath: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(normalizedRoutePath, base),
375
+ lang: langPart || lang,
376
+ version: versionPart || version
377
+ };
378
+ };
346
379
  function RouteService_check_private_redeclaration(obj, privateCollection) {
347
380
  if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
348
381
  }
@@ -382,56 +415,17 @@ function _class_private_method_init(obj, privateSet) {
382
415
  RouteService_check_private_redeclaration(obj, privateSet);
383
416
  privateSet.add(obj);
384
417
  }
385
- const DEFAULT_PAGE_EXTENSIONS = [
386
- 'js',
387
- 'jsx',
388
- 'ts',
389
- 'tsx',
390
- 'md',
391
- 'mdx'
392
- ];
393
- const normalizeRoutePath = (routePath, base, lang, version, langs, versions, extensions = DEFAULT_PAGE_EXTENSIONS)=>{
394
- const hasTrailSlash = routePath.endsWith('/');
395
- let versionPart = '';
396
- let langPart = '';
397
- let purePathPart = '';
398
- const parts = routePath.split('/').filter(Boolean);
399
- if (version) {
400
- const versionToMatch = parts[0];
401
- if (versions.includes(versionToMatch)) {
402
- if (versionToMatch !== version) versionPart = versionToMatch;
403
- parts.shift();
404
- }
405
- }
406
- if (lang) {
407
- const langToMatch = parts[0];
408
- if (langs.includes(langToMatch)) {
409
- if (langToMatch !== lang) langPart = langToMatch;
410
- parts.shift();
411
- }
412
- }
413
- purePathPart = parts.join('/');
414
- let normalizedRoutePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)([
415
- versionPart,
416
- langPart,
417
- purePathPart
418
- ].filter(Boolean).join('/')).replace(new RegExp(`\\.(${extensions.join('|')})$`), '').replace(/\.html$/, '').replace(/\/index$/, '/');
419
- if (hasTrailSlash) normalizedRoutePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addTrailingSlash)(normalizedRoutePath);
420
- return {
421
- routePath: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(normalizedRoutePath, base),
422
- lang: langPart || lang,
423
- version: versionPart || version
424
- };
425
- };
426
418
  var _scanDir = /*#__PURE__*/ new WeakMap(), _defaultLang = /*#__PURE__*/ new WeakMap(), _defaultVersion = /*#__PURE__*/ new WeakMap(), _extensions = /*#__PURE__*/ new WeakMap(), _langs = /*#__PURE__*/ new WeakMap(), _versions = /*#__PURE__*/ new WeakMap(), _include = /*#__PURE__*/ new WeakMap(), _exclude = /*#__PURE__*/ new WeakMap(), _base = /*#__PURE__*/ new WeakMap(), _tempDir = /*#__PURE__*/ new WeakMap(), _pluginDriver = /*#__PURE__*/ new WeakMap(), _writeTempFile = /*#__PURE__*/ new WeakSet(), _generateRouteInfo = /*#__PURE__*/ new WeakSet();
427
419
  class RouteService {
428
420
  async init() {
421
+ const extensions = RouteService_class_private_field_get(this, _extensions).map((i)=>i.slice(1));
429
422
  const files = (await (0, __WEBPACK_EXTERNAL_MODULE_tinyglobby__.glob)([
430
- `**/*.{${RouteService_class_private_field_get(this, _extensions).join(',')}}`,
423
+ `**/*.{${extensions.join(',')}}`,
431
424
  ...RouteService_class_private_field_get(this, _include)
432
425
  ], {
433
426
  cwd: RouteService_class_private_field_get(this, _scanDir),
434
427
  absolute: true,
428
+ onlyFiles: true,
435
429
  ignore: [
436
430
  ...RouteService_class_private_field_get(this, _exclude),
437
431
  '**/node_modules/**',
@@ -473,8 +467,8 @@ class RouteService {
473
467
  addRoute(routeInfo) {
474
468
  const { routePath, absolutePath } = routeInfo;
475
469
  if (this.routeData.has(routePath)) {
476
- const preRouteExtIndex = RouteService_class_private_field_get(this, _extensions).indexOf(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(this.routeData.get(routePath).absolutePath).slice(1));
477
- const currRouteExtIndex = RouteService_class_private_field_get(this, _extensions).indexOf(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(absolutePath).slice(1));
470
+ const preRouteExtIndex = RouteService_class_private_field_get(this, _extensions).indexOf(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(this.routeData.get(routePath).absolutePath));
471
+ const currRouteExtIndex = RouteService_class_private_field_get(this, _extensions).indexOf(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(absolutePath));
478
472
  if (-1 !== currRouteExtIndex && (currRouteExtIndex < preRouteExtIndex || -1 === preRouteExtIndex)) this.routeData.set(routePath, routeInfo);
479
473
  } else this.routeData.set(routePath, routeInfo);
480
474
  }
@@ -488,7 +482,7 @@ class RouteService {
488
482
  }
489
483
  isExistRoute(routePath) {
490
484
  const { routePath: normalizedRoute } = this.normalizeRoutePath(routePath);
491
- return this.routeData.get(normalizedRoute);
485
+ return Boolean(this.routeData.get(normalizedRoute));
492
486
  }
493
487
  isEmpty() {
494
488
  return 0 === this.routeData.size;
@@ -575,7 +569,7 @@ ${routeMeta.map((route, index)=>{
575
569
  RouteService_class_private_field_set(this, _tempDir, '');
576
570
  const routeOptions = (null == userConfig ? void 0 : userConfig.route) || {};
577
571
  RouteService_class_private_field_set(this, _scanDir, scanDir);
578
- RouteService_class_private_field_set(this, _extensions, routeOptions.extensions || DEFAULT_PAGE_EXTENSIONS);
572
+ RouteService_class_private_field_set(this, _extensions, routeOptions.extensions || __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS);
579
573
  RouteService_class_private_field_set(this, _include, routeOptions.include || []);
580
574
  RouteService_class_private_field_set(this, _exclude, routeOptions.exclude || []);
581
575
  RouteService_class_private_field_set(this, _defaultLang, (null == userConfig ? void 0 : userConfig.lang) || '');
@@ -661,6 +655,7 @@ function getI18nData(docConfig) {
661
655
  const i18nSource = require(i18nSourcePath);
662
656
  return i18nSource;
663
657
  } catch (e) {
658
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug('getI18nData Failed: \n', e);
664
659
  return {};
665
660
  }
666
661
  }
@@ -745,6 +740,7 @@ async function flattenMdxContent(content, basePath, alias) {
745
740
  try {
746
741
  ast = processor.parse(content);
747
742
  } catch (e) {
743
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug('flattenMdxContent parse failed: \n', e);
748
744
  return {
749
745
  flattenContent: content,
750
746
  deps
@@ -800,7 +796,7 @@ async function extractPageData(replaceRules, alias, domain, root, routeService,
800
796
  frontmatter: {},
801
797
  version: route.version,
802
798
  _filepath: route.absolutePath,
803
- _relativePath: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, route.absolutePath)
799
+ _relativePath: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, route.absolutePath).split(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].sep).join('/')
804
800
  };
805
801
  if (!__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_REGEXP.test(route.absolutePath)) return defaultIndexInfo;
806
802
  let content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, 'utf8');
@@ -879,12 +875,13 @@ async function extractPageData(replaceRules, alias, domain, root, routeService,
879
875
  }));
880
876
  return pageData.filter(Boolean);
881
877
  }
878
+ const highlightLanguages_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url);
882
879
  let highlightLanguages_supportedLanguages;
883
880
  function handleHighlightLanguages(highlightLanguages, defaultLanguages) {
884
881
  const aliases = {};
885
882
  if (highlightLanguages.size) {
886
883
  if (!highlightLanguages_supportedLanguages) {
887
- const langs = __webpack_require__("react-syntax-highlighter/dist/cjs/languages/prism/supported-languages")["default"];
884
+ const langs = highlightLanguages_require('react-syntax-highlighter/dist/cjs/languages/prism/supported-languages').default;
888
885
  highlightLanguages_supportedLanguages = new Set(langs);
889
886
  }
890
887
  let useDeprecatedTypeWarning = true;
@@ -959,7 +956,7 @@ function normalizeThemeConfig(docConfig, pages = []) {
959
956
  return {
960
957
  text: applyReplaceRules((null == page ? void 0 : page.title) || '', replaceRules),
961
958
  link: normalizedItem,
962
- _fileKey: page._relativePath.replace(/\.mdx?$/, '')
959
+ _fileKey: page._relativePath.replace(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(page._relativePath), '')
963
960
  };
964
961
  }
965
962
  return {
@@ -1206,8 +1203,9 @@ function serveSearchIndexMiddleware(config) {
1206
1203
  if (null === (_req_url = req.url) || void 0 === _req_url ? void 0 : _req_url.includes(searchIndexRequestMatch)) {
1207
1204
  var _req_url1;
1208
1205
  res.setHeader('Content-Type', 'application/json');
1206
+ const outDir = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), OUTPUT_DIR);
1209
1207
  const searchIndexFile = null === (_req_url1 = req.url) || void 0 === _req_url1 ? void 0 : _req_url1.split('/').pop();
1210
- (0, __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.createReadStream)(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), (null == config ? void 0 : config.outDir) || OUTPUT_DIR, 'static', searchIndexFile), 'utf-8').pipe(res, {
1208
+ (0, __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.createReadStream)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outDir, 'static', searchIndexFile), 'utf-8').pipe(res, {
1211
1209
  end: true
1212
1210
  });
1213
1211
  } else null == next || next();
@@ -1273,8 +1271,7 @@ async function resolveReactAlias(reactVersion, isSSR) {
1273
1271
  });
1274
1272
  });
1275
1273
  } catch (e) {
1276
- console.log(e);
1277
- __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`${lib} not found`);
1274
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`${lib} not found: \n`, e);
1278
1275
  }
1279
1276
  }));
1280
1277
  return alias;
@@ -1409,11 +1406,10 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1409
1406
  CUSTOM_THEME_DIR,
1410
1407
  DEFAULT_THEME
1411
1408
  ],
1412
- '@/theme-default': DEFAULT_THEME,
1409
+ '@theme-assets': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(DEFAULT_THEME, '../assets'),
1413
1410
  '@rspress/core': PACKAGE_ROOT,
1414
1411
  'react-lazy-with-preload': require.resolve('react-lazy-with-preload'),
1415
- 'react-syntax-highlighter': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(require.resolve('react-syntax-highlighter/package.json')),
1416
- '@theme-assets': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(DEFAULT_THEME, '../assets')
1412
+ 'react-syntax-highlighter': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(require.resolve('react-syntax-highlighter/package.json'))
1417
1413
  }
1418
1414
  },
1419
1415
  source: {
@@ -1597,6 +1593,7 @@ async function collectModuleFiles(contentPath, lang, includedDir, excludedDirs,
1597
1593
  fileLangMap[baseName].add(lang);
1598
1594
  }
1599
1595
  } catch (e) {
1596
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(e);
1600
1597
  throw new Error(`Failed to access directory: ${checkLanguageParity_normalizePath(langModuleDir)}`);
1601
1598
  }
1602
1599
  return fileLangMap;
@@ -1632,7 +1629,7 @@ async function checkLanguageParity(config) {
1632
1629
  if (missingLanguagesFile.length > 0) throw new Error(`Check language parity failed! Missing content:\n${missingLanguagesFile.map((file)=>` - ${checkLanguageParity_normalizePath(file)}`).join('\n')}`);
1633
1630
  __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.success('Language parity checked successfully.');
1634
1631
  } catch (err) {
1635
- __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Error during language parity check: ${err.message}`);
1632
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error('Error during language parity check: \n', err);
1636
1633
  throw err;
1637
1634
  }
1638
1635
  }
@@ -1753,7 +1750,7 @@ async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
1753
1750
  __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering failed.`);
1754
1751
  throw e;
1755
1752
  }
1756
- __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering error: ${e.message}, fallback to CSR.`);
1753
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering error, fallback to CSR.`, e);
1757
1754
  }
1758
1755
  const { helmet } = helmetContext.context;
1759
1756
  let html = htmlTemplate.replace(/<title>(.*?)<\/title>/gi, '').replace(APP_HTML_MARKER, ()=>appHtml).replace(META_GENERATOR, ()=>`<meta name="generator" content="Rspress v${version}">`).replace(HEAD_MARKER, [
package/dist/loader.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { DefaultThemeConfig } from '@rspress/shared';
2
2
  import type { PageIndexInfo } from '@rspress/shared';
3
- import { RouteMeta } from '@rspress/shared';
3
+ import type { RouteMeta } from '@rspress/shared';
4
4
  import type { Rspack as Rspack_2 } from '@rsbuild/core';
5
5
  import type { RspressPlugin } from '@rspress/shared';
6
- import { UserConfig } from '@rspress/shared';
6
+ import type { UserConfig } from '@rspress/shared';
7
7
 
8
8
  export declare function createCheckPageMetaUpdateFn(): (modulePath: string, pageMeta: PageMeta) => void;
9
9
 
@@ -56,7 +56,7 @@ declare class RouteService {
56
56
  addRoute(routeInfo: RouteMeta): void;
57
57
  removeRoute(filePath: string): void;
58
58
  getRoutes(): RouteMeta[];
59
- isExistRoute(routePath: string): RouteMeta;
59
+ isExistRoute(routePath: string): boolean;
60
60
  isEmpty(): boolean;
61
61
  generateRoutesCode(isStaticImport?: boolean): string;
62
62
  generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[], isStaticImport: boolean): string;
package/dist/loader.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import __rslib_shim_module__ from 'module';
2
- const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
2
+ /*#__PURE__*/ import.meta.url;
3
3
  import * as __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__ from "node:fs/promises";
4
4
  import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
@@ -17,21 +17,6 @@ import * as __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__ from "unist-ut
17
17
  import * as __WEBPACK_EXTERNAL_MODULE_github_slugger_8e9a17cb__ from "github-slugger";
18
18
  import * as __WEBPACK_EXTERNAL_MODULE_hast_util_heading_rank_cff646ba__ from "hast-util-heading-rank";
19
19
  import * as __WEBPACK_EXTERNAL_MODULE_unist_util_visit_children_71921007__ from "unist-util-visit-children";
20
- var __webpack_modules__ = {
21
- "@rspress/mdx-rs": function(module) {
22
- module.exports = require("@rspress/mdx-rs");
23
- }
24
- };
25
- var __webpack_module_cache__ = {};
26
- function __webpack_require__(moduleId) {
27
- var cachedModule = __webpack_module_cache__[moduleId];
28
- if (void 0 !== cachedModule) return cachedModule.exports;
29
- var module = __webpack_module_cache__[moduleId] = {
30
- exports: {}
31
- };
32
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
33
- return module.exports;
34
- }
35
20
  const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
36
21
  `{
37
22
  const saved = localStorage.getItem('${__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.APPEARANCE_KEY}')
@@ -105,6 +90,7 @@ async function flattenMdxContent(content, basePath, alias) {
105
90
  try {
106
91
  ast = processor.parse(content);
107
92
  } catch (e) {
93
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug('flattenMdxContent parse failed: \n', e);
108
94
  return {
109
95
  flattenContent: content,
110
96
  deps
@@ -391,6 +377,14 @@ const parseToc = (tree)=>{
391
377
  var _child_children1;
392
378
  return `**${null === (_child_children1 = child.children) || void 0 === _child_children1 ? void 0 : _child_children1.map((item)=>item.value).join('')}**`;
393
379
  }
380
+ if ('emphasis' === child.type) {
381
+ var _child_children2;
382
+ return `*${null === (_child_children2 = child.children) || void 0 === _child_children2 ? void 0 : _child_children2.map((item)=>item.value).join('')}*`;
383
+ }
384
+ if ('delete' === child.type) {
385
+ var _child_children3;
386
+ return `~~${null === (_child_children3 = child.children) || void 0 === _child_children3 ? void 0 : _child_children3.map((item)=>item.value).join('')}~~`;
387
+ }
394
388
  if ('text' === child.type) {
395
389
  const [textPart, idPart] = extractTextAndId(child.value);
396
390
  customId = idPart;
@@ -542,7 +536,7 @@ async function mdxLoader(source) {
542
536
  toc: []
543
537
  };
544
538
  if (enableMdxRs) {
545
- const { compile } = __webpack_require__("@rspress/mdx-rs");
539
+ const { compile } = await import("@rspress/mdx-rs");
546
540
  const { toc, links, title, code } = await compile({
547
541
  value: preprocessedContent,
548
542
  filepath,
@@ -587,6 +581,7 @@ MDXContent.__RSPRESS_PAGE_META["${encodeURIComponent(normalizePath(__WEBPACK_EXT
587
581
  callback(null, result);
588
582
  } catch (e) {
589
583
  __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`MDX compile error: ${e.message} in ${filepath}`);
584
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug(e);
590
585
  callback({
591
586
  message: e.message,
592
587
  name: `${filepath} compile error`
@@ -14,16 +14,14 @@ var App_rslib_entry_QueryStatus = /*#__PURE__*/ function(QueryStatus) {
14
14
  }({});
15
15
  async function initPageData(routePath) {
16
16
  var _siteData_multiVersion;
17
- const { routes } = process.env.__SSR__ ? await import("virtual-routes-ssr") : await import("virtual-routes");
18
- const matched = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.matchRoutes)(routes, routePath);
19
- if (matched) {
17
+ const matchedRoute = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.pathnameToRouteService)(routePath);
18
+ if (matchedRoute) {
20
19
  var _mod_default___RSPRESS_PAGE_META;
21
- const matchedRoute = matched[0].route;
22
20
  const mod = await matchedRoute.preload();
23
- const pagePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.cleanUrl)(matched[0].route.filePath);
21
+ const pagePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.cleanUrl)(matchedRoute.filePath);
24
22
  const extractPageInfo = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].pages.find((page)=>{
25
23
  const normalize = (p)=>p.replace(/\/$/, '').toLowerCase();
26
- return (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.isEqualPath)(normalize(page.routePath), normalize(routePath));
24
+ return (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.isEqualPath)(normalize(page.routePath), normalize(matchedRoute.path));
27
25
  });
28
26
  const encodedPagePath = encodeURIComponent(pagePath);
29
27
  const meta = (null === (_mod_default___RSPRESS_PAGE_META = mod.default.__RSPRESS_PAGE_META) || void 0 === _mod_default___RSPRESS_PAGE_META ? void 0 : _mod_default___RSPRESS_PAGE_META[encodedPagePath]) || {};
@@ -80,7 +78,7 @@ function App({ helmetContext }) {
80
78
  (0, __WEBPACK_EXTERNAL_MODULE_react__.useLayoutEffect)(()=>{
81
79
  async function refetchData() {
82
80
  try {
83
- const pageData = await initPageData((0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.normalizeRoutePath)(pathname));
81
+ const pageData = await initPageData(pathname);
84
82
  setPageData(pageData);
85
83
  } catch (e) {
86
84
  console.log(e);
@@ -33,7 +33,7 @@ const { default: Theme, useThemeState } = __webpack_require__("@theme");
33
33
  async function renderInBrowser() {
34
34
  const container = document.getElementById('root');
35
35
  const enhancedApp = async ()=>{
36
- const initialPageData = await (0, __WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__.initPageData)((0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.normalizeRoutePath)(window.location.pathname));
36
+ const initialPageData = await (0, __WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__.initPageData)(window.location.pathname);
37
37
  return function() {
38
38
  const [data, setData] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(initialPageData);
39
39
  const [theme, setTheme] = useThemeState();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "1.41.2",
3
+ "version": "1.42.0",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -78,13 +78,13 @@
78
78
  "unified": "^10.1.2",
79
79
  "unist-util-visit": "^4.1.2",
80
80
  "unist-util-visit-children": "^3.0.0",
81
- "@rspress/plugin-auto-nav-sidebar": "1.41.2",
82
- "@rspress/plugin-container-syntax": "1.41.2",
83
- "@rspress/plugin-last-updated": "1.41.2",
84
- "@rspress/runtime": "1.41.2",
85
- "@rspress/plugin-medium-zoom": "1.41.2",
86
- "@rspress/theme-default": "1.41.2",
87
- "@rspress/shared": "1.41.2"
81
+ "@rspress/plugin-auto-nav-sidebar": "1.42.0",
82
+ "@rspress/plugin-container-syntax": "1.42.0",
83
+ "@rspress/plugin-last-updated": "1.42.0",
84
+ "@rspress/plugin-medium-zoom": "1.42.0",
85
+ "@rspress/runtime": "1.42.0",
86
+ "@rspress/shared": "1.42.0",
87
+ "@rspress/theme-default": "1.42.0"
88
88
  },
89
89
  "devDependencies": {
90
90
  "@microsoft/api-extractor": "^7.49.2",
@@ -1,8 +1,7 @@
1
1
  import {
2
2
  DataContext,
3
3
  isEqualPath,
4
- matchRoutes,
5
- normalizeRoutePath,
4
+ pathnameToRouteService,
6
5
  useLocation,
7
6
  } from '@rspress/runtime';
8
7
  import {
@@ -31,32 +30,32 @@ type PageMeta = {
31
30
  };
32
31
 
33
32
  export async function initPageData(routePath: string): Promise<PageData> {
34
- const { routes } = process.env.__SSR__
35
- ? // biome-ignore format: Biome format will add an extra comma.
36
- ((await import('virtual-routes-ssr')) as typeof import(
37
- 'virtual-routes-ssr'
38
- ))
39
- : ((await import('virtual-routes')) as typeof import('virtual-routes'));
40
- const matched = matchRoutes(routes, routePath)!;
41
- if (matched) {
33
+ const matchedRoute = pathnameToRouteService(routePath)!;
34
+ if (matchedRoute) {
42
35
  // Preload route component
43
- const matchedRoute = matched[0].route;
44
36
  const mod = await matchedRoute.preload();
45
- const pagePath = cleanUrl(matched[0].route.filePath);
37
+ const pagePath = cleanUrl(matchedRoute.filePath);
46
38
  const extractPageInfo = siteData.pages.find(page => {
47
39
  const normalize = (p: string) =>
48
40
  // compat the path that has no / suffix and ignore case
49
41
  p
50
42
  .replace(/\/$/, '')
51
43
  .toLowerCase();
52
- return isEqualPath(normalize(page.routePath), normalize(routePath));
44
+ return isEqualPath(
45
+ normalize(page.routePath),
46
+ normalize(matchedRoute.path),
47
+ );
53
48
  });
54
49
 
55
50
  // FIXME: when sidebar item is configured as link string, the sidebar text won't updated when page title changed
56
51
  // Reason: The sidebar item text depends on pageData, which is not updated when page title changed, because the pageData is computed once when build
57
52
  const encodedPagePath = encodeURIComponent(pagePath);
58
53
  const meta: PageMeta =
59
- mod.default.__RSPRESS_PAGE_META?.[encodedPagePath] || {};
54
+ (
55
+ mod.default as unknown as {
56
+ __RSPRESS_PAGE_META: Record<string, PageMeta>;
57
+ }
58
+ ).__RSPRESS_PAGE_META?.[encodedPagePath] || ({} as PageMeta);
60
59
  // mdx loader will generate __RSPRESS_PAGE_META,
61
60
  // if the filePath don't match it, we can get meta from j(t)sx if we customize it
62
61
  const {
@@ -64,7 +63,9 @@ export async function initPageData(routePath: string): Promise<PageData> {
64
63
  title = '',
65
64
  frontmatter = {},
66
65
  ...rest
67
- } = MDX_REGEXP.test(matchedRoute.filePath) ? meta : mod;
66
+ } = MDX_REGEXP.test(matchedRoute.filePath)
67
+ ? meta
68
+ : (mod as unknown as PageMeta);
68
69
  return {
69
70
  siteData,
70
71
  page: {
@@ -138,7 +139,7 @@ export function App({ helmetContext }: { helmetContext?: object }) {
138
139
  useLayoutEffect(() => {
139
140
  async function refetchData() {
140
141
  try {
141
- const pageData = await initPageData(normalizeRoutePath(pathname));
142
+ const pageData = await initPageData(pathname);
142
143
  setPageData(pageData);
143
144
  } catch (e) {
144
145
  console.log(e);
@@ -1,9 +1,4 @@
1
- import {
2
- BrowserRouter,
3
- DataContext,
4
- ThemeContext,
5
- normalizeRoutePath,
6
- } from '@rspress/runtime';
1
+ import { BrowserRouter, DataContext, ThemeContext } from '@rspress/runtime';
7
2
  import { isProduction } from '@rspress/shared';
8
3
  import { useMemo, useState } from 'react';
9
4
  import siteData from 'virtual-site-data';
@@ -18,9 +13,8 @@ export async function renderInBrowser() {
18
13
  const container = document.getElementById('root')!;
19
14
 
20
15
  const enhancedApp = async () => {
21
- const initialPageData = await initPageData(
22
- normalizeRoutePath(window.location.pathname),
23
- );
16
+ const initialPageData = await initPageData(window.location.pathname);
17
+
24
18
  return function RootApp() {
25
19
  const [data, setData] = useState(initialPageData);
26
20
  const [theme, setTheme] = useThemeState();