@rspress/core 1.0.0-beta.5 → 1.0.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/loader.js CHANGED
@@ -12,7 +12,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
12
12
  }) : x)(function(x) {
13
13
  if (typeof require !== "undefined")
14
14
  return require.apply(this, arguments);
15
- throw new Error('Dynamic require of "' + x + '" is not supported');
15
+ throw Error('Dynamic require of "' + x + '" is not supported');
16
16
  });
17
17
  var __commonJS = (cb, mod) => function __require2() {
18
18
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
@@ -214,15 +214,10 @@ var require_section_matter = __commonJS({
214
214
  var extend = require_extend_shallow();
215
215
  module2.exports = function(input, options2) {
216
216
  if (typeof options2 === "function") {
217
- options2 = {
218
- parse: options2
219
- };
217
+ options2 = { parse: options2 };
220
218
  }
221
219
  var file = toObject(input);
222
- var defaults = {
223
- section_delimiter: "---",
224
- parse: identity
225
- };
220
+ var defaults = { section_delimiter: "---", parse: identity };
226
221
  var opts = extend({}, defaults, options2);
227
222
  var delim = opts.section_delimiter;
228
223
  var lines = file.content.split(/\r?\n/);
@@ -291,9 +286,7 @@ var require_section_matter = __commonJS({
291
286
  }
292
287
  function toObject(input) {
293
288
  if (typeOf(input) !== "object") {
294
- input = {
295
- content: input
296
- };
289
+ input = { content: input };
297
290
  }
298
291
  if (typeof input.content !== "string" && !isBuffer(input.content)) {
299
292
  throw new TypeError("expected a buffer or string");
@@ -306,11 +299,7 @@ var require_section_matter = __commonJS({
306
299
  return val ? val.slice(delim.length).trim() : "";
307
300
  }
308
301
  function createSection() {
309
- return {
310
- key: "",
311
- data: "",
312
- content: ""
313
- };
302
+ return { key: "", data: "", content: "" };
314
303
  }
315
304
  function identity(val) {
316
305
  return val;
@@ -339,9 +328,7 @@ var require_common = __commonJS({
339
328
  return sequence;
340
329
  else if (isNothing(sequence))
341
330
  return [];
342
- return [
343
- sequence
344
- ];
331
+ return [sequence];
345
332
  }
346
333
  function extend(target, source) {
347
334
  var index, length, key, sourceKeys;
@@ -863,7 +850,7 @@ var require_int = __commonJS({
863
850
  return sign * parseInt(value, 10);
864
851
  }
865
852
  function isInteger(object) {
866
- return Object.prototype.toString.call(object) === "[object Number]" && object % 1 === 0 && !common.isNegativeZero(object);
853
+ return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common.isNegativeZero(object));
867
854
  }
868
855
  module2.exports = new Type("tag:yaml.org,2002:int", {
869
856
  kind: "scalar",
@@ -887,22 +874,10 @@ var require_int = __commonJS({
887
874
  },
888
875
  defaultStyle: "decimal",
889
876
  styleAliases: {
890
- binary: [
891
- 2,
892
- "bin"
893
- ],
894
- octal: [
895
- 8,
896
- "oct"
897
- ],
898
- decimal: [
899
- 10,
900
- "dec"
901
- ],
902
- hexadecimal: [
903
- 16,
904
- "hex"
905
- ]
877
+ binary: [2, "bin"],
878
+ octal: [8, "oct"],
879
+ decimal: [10, "dec"],
880
+ hexadecimal: [16, "hex"]
906
881
  }
907
882
  });
908
883
  }
@@ -1041,8 +1016,12 @@ var require_timestamp = __commonJS({
1041
1016
  "../../node_modules/.pnpm/js-yaml@3.14.1/node_modules/js-yaml/lib/js-yaml/type/timestamp.js"(exports2, module2) {
1042
1017
  "use strict";
1043
1018
  var Type = require_type();
1044
- var YAML_DATE_REGEXP = new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$");
1045
- var YAML_TIMESTAMP_REGEXP = new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");
1019
+ var YAML_DATE_REGEXP = new RegExp(
1020
+ "^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"
1021
+ );
1022
+ var YAML_TIMESTAMP_REGEXP = new RegExp(
1023
+ "^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$"
1024
+ );
1046
1025
  function resolveYamlTimestamp(data) {
1047
1026
  if (data === null)
1048
1027
  return false;
@@ -1273,10 +1252,7 @@ var require_pairs = __commonJS({
1273
1252
  keys = Object.keys(pair);
1274
1253
  if (keys.length !== 1)
1275
1254
  return false;
1276
- result[index] = [
1277
- keys[0],
1278
- pair[keys[0]]
1279
- ];
1255
+ result[index] = [keys[0], pair[keys[0]]];
1280
1256
  }
1281
1257
  return true;
1282
1258
  }
@@ -1288,10 +1264,7 @@ var require_pairs = __commonJS({
1288
1264
  for (index = 0, length = object.length; index < length; index += 1) {
1289
1265
  pair = object[index];
1290
1266
  keys = Object.keys(pair);
1291
- result[index] = [
1292
- keys[0],
1293
- pair[keys[0]]
1294
- ];
1267
+ result[index] = [keys[0], pair[keys[0]]];
1295
1268
  }
1296
1269
  return result;
1297
1270
  }
@@ -1453,9 +1426,7 @@ var require_function = __commonJS({
1453
1426
  if (data === null)
1454
1427
  return false;
1455
1428
  try {
1456
- var source = "(" + data + ")", ast = esprima.parse(source, {
1457
- range: true
1458
- });
1429
+ var source = "(" + data + ")", ast = esprima.parse(source, { range: true });
1459
1430
  if (ast.type !== "Program" || ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement" || ast.body[0].expression.type !== "ArrowFunctionExpression" && ast.body[0].expression.type !== "FunctionExpression") {
1460
1431
  return false;
1461
1432
  }
@@ -1465,9 +1436,7 @@ var require_function = __commonJS({
1465
1436
  }
1466
1437
  }
1467
1438
  function constructJavascriptFunction(data) {
1468
- var source = "(" + data + ")", ast = esprima.parse(source, {
1469
- range: true
1470
- }), params = [], body;
1439
+ var source = "(" + data + ")", ast = esprima.parse(source, { range: true }), params = [], body;
1471
1440
  if (ast.type !== "Program" || ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement" || ast.body[0].expression.type !== "ArrowFunctionExpression" && ast.body[0].expression.type !== "FunctionExpression") {
1472
1441
  throw new Error("Failed to resolve function");
1473
1442
  }
@@ -1587,7 +1556,10 @@ var require_loader = __commonJS({
1587
1556
  if (c <= 65535) {
1588
1557
  return String.fromCharCode(c);
1589
1558
  }
1590
- return String.fromCharCode((c - 65536 >> 10) + 55296, (c - 65536 & 1023) + 56320);
1559
+ return String.fromCharCode(
1560
+ (c - 65536 >> 10) + 55296,
1561
+ (c - 65536 & 1023) + 56320
1562
+ );
1591
1563
  }
1592
1564
  var simpleEscapeCheck = new Array(256);
1593
1565
  var simpleEscapeMap = new Array(256);
@@ -1614,7 +1586,10 @@ var require_loader = __commonJS({
1614
1586
  this.documents = [];
1615
1587
  }
1616
1588
  function generateError(state, message) {
1617
- return new YAMLException(message, new Mark(state.filename, state.input, state.position, state.line, state.position - state.lineStart));
1589
+ return new YAMLException(
1590
+ message,
1591
+ new Mark(state.filename, state.input, state.position, state.line, state.position - state.lineStart)
1592
+ );
1618
1593
  }
1619
1594
  function throwError(state, message) {
1620
1595
  throw generateError(state, message);
@@ -2608,14 +2583,10 @@ var require_loader = __commonJS({
2608
2583
  options2 = iterator;
2609
2584
  iterator = null;
2610
2585
  }
2611
- return loadAll(input, iterator, common.extend({
2612
- schema: DEFAULT_SAFE_SCHEMA
2613
- }, options2));
2586
+ return loadAll(input, iterator, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options2));
2614
2587
  }
2615
2588
  function safeLoad(input, options2) {
2616
- return load(input, common.extend({
2617
- schema: DEFAULT_SAFE_SCHEMA
2618
- }, options2));
2589
+ return load(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options2));
2619
2590
  }
2620
2591
  module2.exports.loadAll = loadAll;
2621
2592
  module2.exports.load = load;
@@ -2835,7 +2806,7 @@ var require_dumper = __commonJS({
2835
2806
  prev_char = i > 0 ? string.charCodeAt(i - 1) : null;
2836
2807
  plain = plain && isPlainSafe(char, prev_char);
2837
2808
  }
2838
- hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
2809
+ hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ");
2839
2810
  }
2840
2811
  if (!hasLineBreak && !hasFoldableLine) {
2841
2812
  return plain && !testAmbiguousType(string) ? STYLE_PLAIN : STYLE_SINGLE;
@@ -3175,9 +3146,7 @@ var require_dumper = __commonJS({
3175
3146
  return "";
3176
3147
  }
3177
3148
  function safeDump(input, options2) {
3178
- return dump(input, common.extend({
3179
- schema: DEFAULT_SAFE_SCHEMA
3180
- }, options2));
3149
+ return dump(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options2));
3181
3150
  }
3182
3151
  module2.exports.dump = dump;
3183
3152
  module2.exports.safeDump = safeDump;
@@ -3240,12 +3209,9 @@ var require_engines = __commonJS({
3240
3209
  };
3241
3210
  engines.json = {
3242
3211
  parse: JSON.parse.bind(JSON),
3243
- stringify: function(obj1, options1) {
3244
- const opts1 = Object.assign({
3245
- replacer: null,
3246
- space: 2
3247
- }, options1);
3248
- return JSON.stringify(obj1, opts1.replacer, opts1.space);
3212
+ stringify: function(obj, options2) {
3213
+ const opts = Object.assign({ replacer: null, space: 2 }, options2);
3214
+ return JSON.stringify(obj, opts.replacer, opts.space);
3249
3215
  }
3250
3216
  };
3251
3217
  engines.javascript = {
@@ -3314,9 +3280,7 @@ var require_utils = __commonJS({
3314
3280
  return stripBom(input);
3315
3281
  };
3316
3282
  exports2.arrayify = function(val) {
3317
- return val ? Array.isArray(val) ? val : [
3318
- val
3319
- ] : [];
3283
+ return val ? Array.isArray(val) ? val : [val] : [];
3320
3284
  };
3321
3285
  exports2.startsWith = function(str2, substr, len) {
3322
3286
  if (typeof len !== "number")
@@ -3355,9 +3319,7 @@ var require_engine = __commonJS({
3355
3319
  throw new Error('gray-matter engine "' + name + '" is not registered');
3356
3320
  }
3357
3321
  if (typeof engine === "function") {
3358
- engine = {
3359
- parse: engine
3360
- };
3322
+ engine = { parse: engine };
3361
3323
  }
3362
3324
  return engine;
3363
3325
  };
@@ -3471,9 +3433,7 @@ var require_to_file = __commonJS({
3471
3433
  var utils = require_utils();
3472
3434
  module2.exports = function(file) {
3473
3435
  if (typeOf(file) !== "object") {
3474
- file = {
3475
- content: file
3476
- };
3436
+ file = { content: file };
3477
3437
  }
3478
3438
  if (typeOf(file.data) !== "object") {
3479
3439
  file.data = {};
@@ -3519,7 +3479,7 @@ var require_parse = __commonJS({
3519
3479
  var require_gray_matter = __commonJS({
3520
3480
  "../../node_modules/.pnpm/gray-matter@4.0.3/node_modules/gray-matter/index.js"(exports2, module2) {
3521
3481
  "use strict";
3522
- var fs = __require("fs");
3482
+ var fs6 = __require("fs");
3523
3483
  var sections = require_section_matter();
3524
3484
  var defaults = require_defaults();
3525
3485
  var stringify = require_stringify();
@@ -3530,12 +3490,7 @@ var require_gray_matter = __commonJS({
3530
3490
  var utils = require_utils();
3531
3491
  function matter(input, options2) {
3532
3492
  if (input === "") {
3533
- return {
3534
- data: {},
3535
- content: input,
3536
- excerpt: "",
3537
- orig: input
3538
- };
3493
+ return { data: {}, content: input, excerpt: "", orig: input };
3539
3494
  }
3540
3495
  let file = toFile(input);
3541
3496
  const cached = matter.cache[file.content];
@@ -3609,7 +3564,7 @@ var require_gray_matter = __commonJS({
3609
3564
  return stringify(file, data, options2);
3610
3565
  };
3611
3566
  matter.read = function(filepath, options2) {
3612
- const str2 = fs.readFileSync(filepath, "utf8");
3567
+ const str2 = fs6.readFileSync(filepath, "utf8");
3613
3568
  const file = matter(str2, options2);
3614
3569
  file.path = filepath;
3615
3570
  return file;
@@ -3639,8 +3594,8 @@ var require_gray_matter = __commonJS({
3639
3594
 
3640
3595
  // src/node/mdx/loader.ts
3641
3596
  var import_gray_matter = __toESM(require_gray_matter());
3642
- import path6 from "path";
3643
- import { createProcessor } from "@mdx-js/mdx";
3597
+ import path10 from "path";
3598
+ import { createProcessor as createProcessor2 } from "@mdx-js/mdx";
3644
3599
 
3645
3600
  // src/node/utils/normalizePath.ts
3646
3601
  import os from "os";
@@ -3653,8 +3608,47 @@ function normalizePath(id) {
3653
3608
  return path.posix.normalize(isWindows ? slash(id) : id);
3654
3609
  }
3655
3610
 
3611
+ // src/node/utils/getPageKey.ts
3612
+ import { removeLeadingSlash } from "@rspress/shared";
3613
+
3614
+ // src/node/utils/createHash.ts
3615
+ import { createHash as createHashFunc } from "crypto";
3616
+
3617
+ // src/node/utils/detectReactVersion.ts
3618
+ import path3 from "path";
3619
+ import fs from "@modern-js/utils/fs-extra";
3620
+ import { logger } from "@rspress/shared/logger";
3621
+ import enhancedResolve from "enhanced-resolve";
3622
+
3623
+ // src/node/constants.ts
3624
+ import path2 from "path";
3625
+ import { fileURLToPath } from "url";
3626
+ import { RSPRESS_TEMP_DIR } from "@rspress/shared";
3627
+ var dirname = path2.dirname(fileURLToPath(new URL(import.meta.url)));
3628
+ var PACKAGE_ROOT = path2.join(dirname, "..");
3629
+ var CLIENT_ENTRY = path2.join(
3630
+ PACKAGE_ROOT,
3631
+ "dist",
3632
+ "runtime",
3633
+ "clientEntry.js"
3634
+ );
3635
+ var SSR_ENTRY = path2.join(
3636
+ PACKAGE_ROOT,
3637
+ "dist",
3638
+ "runtime",
3639
+ "ssrEntry.js"
3640
+ );
3641
+ var TEMP_DIR = path2.join(
3642
+ process.cwd(),
3643
+ "node_modules",
3644
+ RSPRESS_TEMP_DIR
3645
+ );
3646
+
3647
+ // src/node/utils/detectReactVersion.ts
3648
+ var { CachedInputFileSystem, ResolverFactory } = enhancedResolve;
3649
+
3656
3650
  // src/node/mdx/options.ts
3657
- import path5 from "path";
3651
+ import path9 from "path";
3658
3652
  import remarkGFM from "remark-gfm";
3659
3653
  import rehypeSlug from "rehype-slug";
3660
3654
  import rehypeAutoLink from "rehype-autolink-headings";
@@ -3684,11 +3678,7 @@ var parseToc = (tree) => {
3684
3678
  }).join("");
3685
3679
  const id = slugger.slug(originText);
3686
3680
  const { depth } = node;
3687
- toc.push({
3688
- id,
3689
- text: originText,
3690
- depth
3691
- });
3681
+ toc.push({ id, text: originText, depth });
3692
3682
  }
3693
3683
  })(tree);
3694
3684
  return {
@@ -3722,7 +3712,7 @@ var rehypePluginCodeMeta = () => {
3722
3712
  };
3723
3713
 
3724
3714
  // src/node/mdx/remarkPlugins/normalizeLink.ts
3725
- import path2 from "path";
3715
+ import path4 from "path";
3726
3716
  import { visit as visit2 } from "unist-util-visit";
3727
3717
  import { normalizeHref, parseUrl, isExternalUrl, slash as slash2 } from "@rspress/shared";
3728
3718
 
@@ -3740,10 +3730,7 @@ var getASTNodeImport = (name, from) => ({
3740
3730
  specifiers: [
3741
3731
  {
3742
3732
  type: "ImportDefaultSpecifier",
3743
- local: {
3744
- type: "Identifier",
3745
- name
3746
- }
3733
+ local: { type: "Identifier", name }
3747
3734
  }
3748
3735
  ],
3749
3736
  source: {
@@ -3760,33 +3747,37 @@ var getASTNodeImport = (name, from) => ({
3760
3747
  // src/node/mdx/remarkPlugins/normalizeLink.ts
3761
3748
  var remarkPluginNormalizeLink = ({ base, root, cleanUrls }) => (tree, file) => {
3762
3749
  const images = [];
3763
- visit2(tree, (node) => node.type === "link", (node) => {
3764
- if (!node.url) {
3765
- return;
3766
- }
3767
- if (node.url.startsWith("#")) {
3768
- node.url = `#${node.url.slice(1)}`;
3769
- return;
3770
- }
3771
- let { url, hash } = parseUrl(node.url);
3772
- if (isExternalUrl(url)) {
3773
- node.url = url + (hash ? `#${hash}` : "");
3774
- return;
3775
- }
3776
- const extname = path2.extname(url);
3777
- if (extname === ".md" || extname === ".mdx") {
3778
- url = url.replace(extname, "");
3779
- }
3780
- const relativePath = path2.relative(root, file.path);
3781
- if (url.startsWith(".")) {
3782
- url = path2.posix.join(slash2(path2.dirname(relativePath)), url);
3783
- }
3784
- url = normalizeHref(url, cleanUrls);
3785
- if (hash) {
3786
- url += `#${hash}`;
3750
+ visit2(
3751
+ tree,
3752
+ (node) => node.type === "link",
3753
+ (node) => {
3754
+ if (!node.url) {
3755
+ return;
3756
+ }
3757
+ if (node.url.startsWith("#")) {
3758
+ node.url = `#${node.url.slice(1)}`;
3759
+ return;
3760
+ }
3761
+ let { url, hash } = parseUrl(node.url);
3762
+ if (isExternalUrl(url)) {
3763
+ node.url = url + (hash ? `#${hash}` : "");
3764
+ return;
3765
+ }
3766
+ const extname = path4.extname(url);
3767
+ if (extname === ".md" || extname === ".mdx") {
3768
+ url = url.replace(extname, "");
3769
+ }
3770
+ const relativePath = path4.relative(root, file.path);
3771
+ if (url.startsWith(".")) {
3772
+ url = path4.posix.join(slash2(path4.dirname(relativePath)), url);
3773
+ }
3774
+ url = normalizeHref(url, cleanUrls);
3775
+ if (hash) {
3776
+ url += `#${hash}`;
3777
+ }
3778
+ node.url = path4.posix.join(base, url);
3787
3779
  }
3788
- node.url = path2.posix.join(base, url);
3789
- });
3780
+ );
3790
3781
  const normalizeImageUrl = (imageUrl) => {
3791
3782
  if (isExternalUrl(imageUrl) || imageUrl.startsWith("/")) {
3792
3783
  return "";
@@ -3843,10 +3834,7 @@ var remarkPluginNormalizeLink = ({ base, root, cleanUrls }) => (tree, file) => {
3843
3834
  });
3844
3835
  images.push(getASTNodeImport(tempVariableName, imagePath));
3845
3836
  });
3846
- visit2(tree, [
3847
- "mdxJsxFlowElement",
3848
- "mdxJsxTextElement"
3849
- ], (node) => {
3837
+ visit2(tree, ["mdxJsxFlowElement", "mdxJsxTextElement"], (node) => {
3850
3838
  if (node.name !== "img") {
3851
3839
  return;
3852
3840
  }
@@ -3866,32 +3854,76 @@ var remarkPluginNormalizeLink = ({ base, root, cleanUrls }) => (tree, file) => {
3866
3854
  };
3867
3855
 
3868
3856
  // src/node/mdx/remarkPlugins/checkDeadLink.ts
3869
- import path3 from "path";
3857
+ import path7 from "path";
3870
3858
  import { visit as visit3 } from "unist-util-visit";
3871
3859
  import logUtils from "@modern-js/utils/logger";
3872
3860
  import { cleanUrl, isProduction } from "@rspress/shared";
3873
3861
 
3874
3862
  // src/node/runtimeModule/routeData.ts
3875
- import { addLeadingSlash } from "@rspress/shared";
3863
+ import { addLeadingSlash as addLeadingSlash2 } from "@rspress/shared";
3864
+
3865
+ // src/node/runtimeModule/index.ts
3866
+ import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
3867
+
3868
+ // src/node/runtimeModule/siteData.ts
3869
+ import path6 from "path";
3870
+ import {
3871
+ withBase,
3872
+ MDX_REGEXP as MDX_REGEXP2,
3873
+ SEARCH_INDEX_NAME,
3874
+ addLeadingSlash,
3875
+ isExternalUrl as isExternalUrl2,
3876
+ withoutBase
3877
+ } from "@rspress/shared";
3878
+ import yamlFrontMatter from "yaml-front-matter";
3879
+ import { htmlToText } from "html-to-text";
3880
+ import fs3 from "@modern-js/utils/fs-extra";
3881
+ import { compile } from "@rspress/mdx-rs";
3882
+
3883
+ // src/node/utils/flattenMdxContent.ts
3884
+ import path5 from "path";
3885
+ import enhancedResolve2 from "enhanced-resolve";
3886
+ import fs2 from "@modern-js/utils/fs-extra";
3887
+ import { createProcessor } from "@mdx-js/mdx";
3888
+ import { MDX_REGEXP } from "@rspress/shared";
3889
+ var { CachedInputFileSystem: CachedInputFileSystem2, ResolverFactory: ResolverFactory2 } = enhancedResolve2;
3890
+ var processor = createProcessor();
3891
+
3892
+ // src/node/runtimeModule/i18n.ts
3893
+ import { join } from "path";
3894
+ var DEFAULT_I18N_SOURCE = join(process.cwd(), "i18n.json");
3895
+
3896
+ // src/node/runtimeModule/siteData.ts
3897
+ var { loadFront } = yamlFrontMatter;
3898
+
3899
+ // src/node/runtimeModule/globalStyles.ts
3900
+ import fs4 from "@modern-js/utils/fs-extra";
3901
+
3902
+ // src/node/runtimeModule/searchHooks.ts
3903
+ import fs5 from "@modern-js/utils/fs-extra";
3904
+
3905
+ // src/node/runtimeModule/routeData.ts
3876
3906
  var normalizeRoutePath = (routePath) => {
3877
3907
  const result = routePath.replace(/\.(.*)?$/, "").replace(/index$/, "");
3878
- return addLeadingSlash(result);
3908
+ return addLeadingSlash2(result);
3879
3909
  };
3880
3910
 
3881
3911
  // src/node/mdx/remarkPlugins/checkDeadLink.ts
3882
- var { logger } = logUtils;
3912
+ var { logger: logger2 } = logUtils;
3883
3913
  var IGNORE_REGEXP = /^(https?|mailto|tel|#)/;
3884
3914
  function checkLinks(links, filepath, root, routeService) {
3885
3915
  const errorInfos = [];
3886
3916
  links.filter((link) => !IGNORE_REGEXP.test(link)).map((link) => normalizePath(link)).forEach((link) => {
3887
- const relativePath = path3.relative(root, filepath);
3917
+ const relativePath = path7.relative(root, filepath);
3888
3918
  if (!routeService.isExistRoute(cleanUrl(link))) {
3889
- errorInfos.push(`Internal link to ${link} is dead, check it in ${relativePath}`);
3919
+ errorInfos.push(
3920
+ `Internal link to ${link} is dead, check it in ${relativePath}`
3921
+ );
3890
3922
  }
3891
3923
  });
3892
3924
  if (errorInfos.length > 0) {
3893
3925
  errorInfos?.forEach((err) => {
3894
- logger.error(err);
3926
+ logger2.error(err);
3895
3927
  });
3896
3928
  if (isProduction()) {
3897
3929
  throw new Error("Dead link found");
@@ -3913,7 +3945,7 @@ var remarkCheckDeadLinks = (checkLink) => {
3913
3945
  if (!url.startsWith("http") && !url.startsWith("https")) {
3914
3946
  const normalizeUrl = normalizeRoutePath(
3915
3947
  // fix: windows path
3916
- url?.split(path3.sep).join("/")?.split("#")[0]
3948
+ url?.split(path7.sep).join("/")?.split("#")[0]
3917
3949
  );
3918
3950
  internalLinks.add(normalizeUrl);
3919
3951
  }
@@ -3923,11 +3955,13 @@ var remarkCheckDeadLinks = (checkLink) => {
3923
3955
  };
3924
3956
 
3925
3957
  // src/node/mdx/remarkPlugins/builtin.ts
3926
- import path4 from "path";
3927
- var remarkBuiltin = ({ globalComponents }) => {
3958
+ import path8 from "path";
3959
+ var remarkBuiltin = ({
3960
+ globalComponents
3961
+ }) => {
3928
3962
  return (tree) => {
3929
3963
  const demos = globalComponents.map((componentPath) => {
3930
- const filename = path4.parse(componentPath).name;
3964
+ const filename = path8.parse(componentPath).name;
3931
3965
  const componentName = filename[0].toUpperCase() + filename.slice(1);
3932
3966
  return getASTNodeImport(componentName, componentPath);
3933
3967
  });
@@ -3938,18 +3972,28 @@ var remarkBuiltin = ({ globalComponents }) => {
3938
3972
  // src/node/mdx/options.ts
3939
3973
  async function createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver) {
3940
3974
  const cleanUrls = Boolean(config?.route?.cleanUrls);
3941
- const { remarkPlugins: remarkPluginsFromConfig = [], rehypePlugins: rehypePluginsFromConfig = [], globalComponents: globalComponentsFromConfig = [] } = config?.markdown || {};
3975
+ const {
3976
+ remarkPlugins: remarkPluginsFromConfig = [],
3977
+ rehypePlugins: rehypePluginsFromConfig = [],
3978
+ globalComponents: globalComponentsFromConfig = []
3979
+ } = config?.markdown || {};
3942
3980
  const rspressPlugins = pluginDriver.getPlugins();
3943
- const remarkPluginsFromPlugins = rspressPlugins.flatMap((plugin) => plugin.markdown?.remarkPlugins || []);
3944
- const rehypePluginsFromPlugins = rspressPlugins.flatMap((plugin) => plugin.markdown?.rehypePlugins || []);
3981
+ const remarkPluginsFromPlugins = rspressPlugins.flatMap(
3982
+ (plugin) => plugin.markdown?.remarkPlugins || []
3983
+ );
3984
+ const rehypePluginsFromPlugins = rspressPlugins.flatMap(
3985
+ (plugin) => plugin.markdown?.rehypePlugins || []
3986
+ );
3945
3987
  const globalComponents = [
3946
- ...rspressPlugins.flatMap((plugin) => plugin.markdown?.globalComponents || []),
3988
+ ...rspressPlugins.flatMap(
3989
+ (plugin) => plugin.markdown?.globalComponents || []
3990
+ ),
3947
3991
  ...globalComponentsFromConfig
3948
3992
  ];
3949
3993
  const defaultLang = config?.lang || "";
3950
3994
  return {
3951
3995
  providerImportSource: "@mdx-js/react",
3952
- format: path5.extname(filepath).slice(1),
3996
+ format: path9.extname(filepath).slice(1),
3953
3997
  remarkPlugins: [
3954
3998
  remarkGFM,
3955
3999
  remarkPluginToc,
@@ -4017,14 +4061,28 @@ async function mdxLoader(context, source, callback) {
4017
4061
  title: "",
4018
4062
  toc: []
4019
4063
  };
4020
- const { config, docDirectory, checkDeadLinks, routeService, enableMdxRs, pluginDriver } = options2;
4064
+ const {
4065
+ config,
4066
+ docDirectory,
4067
+ checkDeadLinks,
4068
+ routeService,
4069
+ enableMdxRs,
4070
+ pluginDriver
4071
+ } = options2;
4021
4072
  const { data: frontmatter, content } = (0, import_gray_matter.default)(source);
4022
4073
  const hasFrontMatter = Object.keys(frontmatter).length > 0;
4023
4074
  try {
4024
4075
  let compileResult;
4025
4076
  if (!enableMdxRs) {
4026
- const mdxOptions = await createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver);
4027
- const compiler = createProcessor(mdxOptions);
4077
+ const mdxOptions = await createMDXOptions(
4078
+ docDirectory,
4079
+ config,
4080
+ checkDeadLinks,
4081
+ routeService,
4082
+ filepath,
4083
+ pluginDriver
4084
+ );
4085
+ const compiler = createProcessor2(mdxOptions);
4028
4086
  compiler.data("pageMeta", {
4029
4087
  toc: [],
4030
4088
  title: ""
@@ -4038,8 +4096,8 @@ async function mdxLoader(context, source, callback) {
4038
4096
  ...compiler.data("pageMeta")
4039
4097
  };
4040
4098
  } else {
4041
- const { compile } = __require("@rspress/mdx-rs");
4042
- const { toc, links, title, code } = await compile({
4099
+ const { compile: compile2 } = __require("@rspress/mdx-rs");
4100
+ const { toc, links, title, code } = await compile2({
4043
4101
  value: content,
4044
4102
  filepath,
4045
4103
  root: docDirectory,
@@ -4056,17 +4114,16 @@ async function mdxLoader(context, source, callback) {
4056
4114
  }
4057
4115
  const result = `${compileResult}
4058
4116
  MDXContent.__RSPRESS_PAGE_META = {};
4059
- MDXContent.__RSPRESS_PAGE_META["${encodeURIComponent(normalizePath(path6.relative(docDirectory, filepath)))}"] = ${JSON.stringify(pageMeta)};
4117
+ MDXContent.__RSPRESS_PAGE_META["${encodeURIComponent(
4118
+ normalizePath(path10.relative(docDirectory, filepath))
4119
+ )}"] = ${JSON.stringify(pageMeta)};
4060
4120
  ${hasFrontMatter ? `export const frontmatter = ${JSON.stringify(frontmatter)};` : ""}
4061
4121
 
4062
4122
  `;
4063
4123
  callback(null, result);
4064
4124
  } catch (e) {
4065
4125
  console.error(`MDX compile error: ${e.message} in ${filepath}`);
4066
- callback({
4067
- message: e.message,
4068
- name: `${filepath} compile error`
4069
- });
4126
+ callback({ message: e.message, name: `${filepath} compile error` });
4070
4127
  }
4071
4128
  }
4072
4129
  export {