@rspress/core 1.1.3 → 1.2.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/loader.d.ts CHANGED
@@ -17,6 +17,7 @@ declare class PluginDriver {
17
17
  extendPageData(pageData: PageIndexInfo): Promise<any[]>;
18
18
  addPages(): Promise<any[]>;
19
19
  routeGenerated(routes: RouteMeta[]): Promise<any[]>;
20
+ addRuntimeModules(): Promise<Record<string, string>>;
20
21
  addSSGRoutes(): Promise<any[]>;
21
22
  globalUIComponents(): (string | [string, object])[];
22
23
  globalStyles(): string[];
package/dist/loader.js CHANGED
@@ -3593,9 +3593,9 @@ var require_gray_matter = __commonJS({
3593
3593
  });
3594
3594
 
3595
3595
  // src/node/mdx/loader.ts
3596
- var import_gray_matter = __toESM(require_gray_matter());
3597
- import path6 from "path";
3596
+ import path7 from "path";
3598
3597
  import { createProcessor } from "@mdx-js/mdx";
3598
+ import { logger as logger3 } from "@rspress/shared/logger";
3599
3599
 
3600
3600
  // src/node/utils/normalizePath.ts
3601
3601
  import os from "os";
@@ -3608,8 +3608,30 @@ function normalizePath(id) {
3608
3608
  return path.posix.normalize(isWindows ? slash(id) : id);
3609
3609
  }
3610
3610
 
3611
+ // src/node/utils/loadFrontMatter.ts
3612
+ var import_gray_matter = __toESM(require_gray_matter());
3613
+ import path2 from "path";
3614
+ import { logger } from "@rspress/shared/logger";
3615
+ function loadFrontMatter(source, filepath, root, outputWarning = false) {
3616
+ let frontmatter = {};
3617
+ let content = "";
3618
+ try {
3619
+ ({ data: frontmatter, content } = (0, import_gray_matter.default)(source));
3620
+ } catch (e) {
3621
+ if (outputWarning) {
3622
+ logger.warn(
3623
+ `Parse frontmatter error: ${e.message} in ${path2.relative(
3624
+ root,
3625
+ filepath
3626
+ )}`
3627
+ );
3628
+ }
3629
+ }
3630
+ return { frontmatter, content };
3631
+ }
3632
+
3611
3633
  // src/node/mdx/options.ts
3612
- import path5 from "path";
3634
+ import path6 from "path";
3613
3635
  import remarkGFM from "remark-gfm";
3614
3636
  import rehypeSlug from "rehype-slug";
3615
3637
  import rehypeAutoLink from "rehype-autolink-headings";
@@ -3673,7 +3695,7 @@ var rehypePluginCodeMeta = () => {
3673
3695
  };
3674
3696
 
3675
3697
  // src/node/mdx/remarkPlugins/normalizeLink.ts
3676
- import path2 from "path";
3698
+ import path3 from "path";
3677
3699
  import { visit as visit2 } from "unist-util-visit";
3678
3700
  import { normalizeHref, parseUrl, isExternalUrl, slash as slash2 } from "@rspress/shared";
3679
3701
 
@@ -3724,19 +3746,19 @@ var remarkPluginNormalizeLink = ({ base, root, cleanUrls }) => (tree, file) => {
3724
3746
  node.url = url + (hash ? `#${hash}` : "");
3725
3747
  return;
3726
3748
  }
3727
- const extname = path2.extname(url);
3749
+ const extname = path3.extname(url);
3728
3750
  if (extname === ".md" || extname === ".mdx") {
3729
3751
  url = url.replace(extname, "");
3730
3752
  }
3731
- const relativePath = path2.relative(root, file.path);
3753
+ const relativePath = path3.relative(root, file.path);
3732
3754
  if (url.startsWith(".")) {
3733
- url = path2.posix.join(slash2(path2.dirname(relativePath)), url);
3755
+ url = path3.posix.join(slash2(path3.dirname(relativePath)), url);
3734
3756
  }
3735
3757
  url = normalizeHref(url, cleanUrls);
3736
3758
  if (hash) {
3737
3759
  url += `#${hash}`;
3738
3760
  }
3739
- node.url = path2.posix.join(base, url);
3761
+ node.url = path3.posix.join(base, url);
3740
3762
  }
3741
3763
  );
3742
3764
  const normalizeImageUrl = (imageUrl) => {
@@ -3815,7 +3837,7 @@ var remarkPluginNormalizeLink = ({ base, root, cleanUrls }) => (tree, file) => {
3815
3837
  };
3816
3838
 
3817
3839
  // src/node/mdx/remarkPlugins/checkDeadLink.ts
3818
- import path3 from "path";
3840
+ import path4 from "path";
3819
3841
  import { visit as visit3 } from "unist-util-visit";
3820
3842
  import logUtils from "@modern-js/utils/logger";
3821
3843
  import { cleanUrl, isProduction } from "@rspress/shared";
@@ -3828,12 +3850,12 @@ var normalizeRoutePath = (routePath) => {
3828
3850
  };
3829
3851
 
3830
3852
  // src/node/mdx/remarkPlugins/checkDeadLink.ts
3831
- var { logger } = logUtils;
3853
+ var { logger: logger2 } = logUtils;
3832
3854
  var IGNORE_REGEXP = /^(https?|mailto|tel|#)/;
3833
3855
  function checkLinks(links, filepath, root, routeService) {
3834
3856
  const errorInfos = [];
3835
3857
  links.filter((link) => !IGNORE_REGEXP.test(link)).map((link) => normalizePath(link)).forEach((link) => {
3836
- const relativePath = path3.relative(root, filepath);
3858
+ const relativePath = path4.relative(root, filepath);
3837
3859
  if (!routeService.isExistRoute(cleanUrl(link))) {
3838
3860
  errorInfos.push(
3839
3861
  `Internal link to ${link} is dead, check it in ${relativePath}`
@@ -3842,7 +3864,7 @@ function checkLinks(links, filepath, root, routeService) {
3842
3864
  });
3843
3865
  if (errorInfos.length > 0) {
3844
3866
  errorInfos?.forEach((err) => {
3845
- logger.error(err);
3867
+ logger2.error(err);
3846
3868
  });
3847
3869
  if (isProduction()) {
3848
3870
  throw new Error("Dead link found");
@@ -3864,7 +3886,7 @@ var remarkCheckDeadLinks = (checkLink) => {
3864
3886
  if (!url.startsWith("http") && !url.startsWith("https")) {
3865
3887
  const normalizeUrl = normalizeRoutePath(
3866
3888
  // fix: windows path
3867
- url?.split(path3.sep).join("/")?.split("#")[0]
3889
+ url?.split(path4.sep).join("/")?.split("#")[0]
3868
3890
  );
3869
3891
  internalLinks.add(normalizeUrl);
3870
3892
  }
@@ -3874,13 +3896,13 @@ var remarkCheckDeadLinks = (checkLink) => {
3874
3896
  };
3875
3897
 
3876
3898
  // src/node/mdx/remarkPlugins/builtin.ts
3877
- import path4 from "path";
3899
+ import path5 from "path";
3878
3900
  var remarkBuiltin = ({
3879
3901
  globalComponents
3880
3902
  }) => {
3881
3903
  return (tree) => {
3882
3904
  const demos = globalComponents.map((componentPath) => {
3883
- const filename = path4.parse(componentPath).name;
3905
+ const filename = path5.parse(componentPath).name;
3884
3906
  const componentName = filename[0].toUpperCase() + filename.slice(1);
3885
3907
  return getASTNodeImport(componentName, componentPath);
3886
3908
  });
@@ -3912,7 +3934,7 @@ async function createMDXOptions(docDirectory, config, checkDeadLinks, routeServi
3912
3934
  const defaultLang = config?.lang || "";
3913
3935
  return {
3914
3936
  providerImportSource: "@mdx-js/react",
3915
- format: path5.extname(filepath).slice(1),
3937
+ format: path6.extname(filepath).slice(1),
3916
3938
  remarkPlugins: [
3917
3939
  remarkGFM,
3918
3940
  remarkPluginToc,
@@ -3988,7 +4010,12 @@ async function mdxLoader(context, source, callback) {
3988
4010
  enableMdxRs,
3989
4011
  pluginDriver
3990
4012
  } = options2;
3991
- const { data: frontmatter, content } = (0, import_gray_matter.default)(source);
4013
+ const { frontmatter, content } = loadFrontMatter(
4014
+ source,
4015
+ filepath,
4016
+ docDirectory,
4017
+ true
4018
+ );
3992
4019
  const hasFrontMatter = Object.keys(frontmatter).length > 0;
3993
4020
  try {
3994
4021
  let compileResult;
@@ -4034,14 +4061,14 @@ async function mdxLoader(context, source, callback) {
4034
4061
  const result = `${compileResult}
4035
4062
  MDXContent.__RSPRESS_PAGE_META = {};
4036
4063
  MDXContent.__RSPRESS_PAGE_META["${encodeURIComponent(
4037
- normalizePath(path6.relative(docDirectory, filepath))
4064
+ normalizePath(path7.relative(docDirectory, filepath))
4038
4065
  )}"] = ${JSON.stringify(pageMeta)};
4039
4066
  ${hasFrontMatter ? `export const frontmatter = ${JSON.stringify(frontmatter)};` : ""}
4040
4067
 
4041
4068
  `;
4042
4069
  callback(null, result);
4043
4070
  } catch (e) {
4044
- console.error(`MDX compile error: ${e.message} in ${filepath}`);
4071
+ logger3.error(`MDX compile error: ${e.message} in ${filepath}`);
4045
4072
  callback({ message: e.message, name: `${filepath} compile error` });
4046
4073
  }
4047
4074
  }