@rspress/core 0.1.1 → 1.0.0-beta.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/index.js +62 -24
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +17 -33
- package/dist/loader.js.map +1 -1
- package/dist/runtime/App.js +4 -4
- package/dist/runtime/Content.js +14 -2
- package/dist/runtime/hooks.d.ts +17 -0
- package/dist/runtime/hooks.js +27 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/utils.d.ts +3 -2
- package/dist/runtime/utils.js +6 -2
- package/dist/theme/bundle.css +44 -4
- package/dist/theme/bundle.d.ts +6 -1
- package/dist/theme/bundle.js +150 -77
- package/dist/theme/bundle.js.map +1 -1
- package/package.json +7 -7
- package/src/runtime/App.tsx +5 -6
- package/src/runtime/Content.tsx +24 -2
- package/src/runtime/global.d.ts +4 -5
- package/src/runtime/hooks.ts +67 -1
- package/src/runtime/index.ts +1 -1
- package/src/runtime/utils.ts +9 -8
- package/src/theme-default/components/DocFooter/index.tsx +1 -1
- package/src/theme-default/components/HomeHero/index.tsx +1 -1
- package/src/theme-default/components/Link/index.module.scss +0 -1
- package/src/theme-default/components/Link/index.tsx +21 -2
- package/src/theme-default/components/Nav/NavMenuSingleItem.tsx +1 -1
- package/src/theme-default/components/Nav/index.tsx +19 -5
- package/src/theme-default/components/Overview/index.tsx +1 -1
- package/src/theme-default/components/Search/logic/search.ts +1 -1
- package/src/theme-default/components/Sidebar/SidebarGroup.tsx +1 -1
- package/src/theme-default/components/Sidebar/SidebarItem.tsx +1 -1
- package/src/theme-default/index.ts +2 -0
- package/src/theme-default/layout/DocLayout/docComponents/index.module.scss +4 -0
- package/src/theme-default/layout/DocLayout/docComponents/link.tsx +14 -23
- package/src/theme-default/layout/DocLayout/index.module.scss +46 -0
- package/src/theme-default/layout/HomeLayout/index.tsx +1 -0
- package/src/theme-default/logic/index.ts +1 -0
- package/src/theme-default/logic/sideEffects.ts +7 -0
- package/src/theme-default/logic/usePathUtils.ts +73 -0
package/dist/loader.js
CHANGED
|
@@ -3724,7 +3724,7 @@ var rehypePluginCodeMeta = () => {
|
|
|
3724
3724
|
// src/node/mdx/remarkPlugins/normalizeLink.ts
|
|
3725
3725
|
import path2 from "path";
|
|
3726
3726
|
import { visit as visit2 } from "unist-util-visit";
|
|
3727
|
-
import {
|
|
3727
|
+
import { normalizeHref, parseUrl, isExternalUrl, slash as slash2 } from "@rspress/shared";
|
|
3728
3728
|
|
|
3729
3729
|
// src/node/utils/getASTNodeImport.ts
|
|
3730
3730
|
var getASTNodeImport = (name, from) => ({
|
|
@@ -3758,25 +3758,7 @@ var getASTNodeImport = (name, from) => ({
|
|
|
3758
3758
|
});
|
|
3759
3759
|
|
|
3760
3760
|
// src/node/mdx/remarkPlugins/normalizeLink.ts
|
|
3761
|
-
|
|
3762
|
-
const [lang] = filePath.split(path2.sep);
|
|
3763
|
-
return lang;
|
|
3764
|
-
}
|
|
3765
|
-
function normalizeLangPrefix(rawUrl, lang, defaultLang) {
|
|
3766
|
-
if (!defaultLang) {
|
|
3767
|
-
return rawUrl;
|
|
3768
|
-
}
|
|
3769
|
-
const url = addLeadingSlash(rawUrl);
|
|
3770
|
-
const hasLangPrefix = url.startsWith(`/${lang}/`);
|
|
3771
|
-
if (hasLangPrefix && lang === defaultLang) {
|
|
3772
|
-
return url.replace(`/${lang}`, "");
|
|
3773
|
-
}
|
|
3774
|
-
if (hasLangPrefix || lang === defaultLang) {
|
|
3775
|
-
return url;
|
|
3776
|
-
}
|
|
3777
|
-
return `/${lang}${url}`;
|
|
3778
|
-
}
|
|
3779
|
-
var remarkPluginNormalizeLink = ({ base, defaultLang, root }) => (tree, file) => {
|
|
3761
|
+
var remarkPluginNormalizeLink = ({ base, root, cleanUrls }) => (tree, file) => {
|
|
3780
3762
|
const images = [];
|
|
3781
3763
|
visit2(tree, (node) => node.type === "link", (node) => {
|
|
3782
3764
|
if (!node.url) {
|
|
@@ -3799,8 +3781,7 @@ var remarkPluginNormalizeLink = ({ base, defaultLang, root }) => (tree, file) =>
|
|
|
3799
3781
|
if (url.startsWith(".")) {
|
|
3800
3782
|
url = path2.posix.join(slash2(path2.dirname(relativePath)), url);
|
|
3801
3783
|
}
|
|
3802
|
-
|
|
3803
|
-
url = normalizeLangPrefix(normalizeHref(url), lang, defaultLang);
|
|
3784
|
+
url = normalizeHref(url, cleanUrls);
|
|
3804
3785
|
if (hash) {
|
|
3805
3786
|
url += `#${hash}`;
|
|
3806
3787
|
}
|
|
@@ -3891,10 +3872,10 @@ import logUtils from "@modern-js/utils/logger";
|
|
|
3891
3872
|
import { cleanUrl, isProduction } from "@rspress/shared";
|
|
3892
3873
|
|
|
3893
3874
|
// src/node/runtimeModule/routeData.ts
|
|
3894
|
-
import { addLeadingSlash
|
|
3875
|
+
import { addLeadingSlash } from "@rspress/shared";
|
|
3895
3876
|
var normalizeRoutePath = (routePath) => {
|
|
3896
3877
|
const result = routePath.replace(/\.(.*)?$/, "").replace(/index$/, "");
|
|
3897
|
-
return
|
|
3878
|
+
return addLeadingSlash(result);
|
|
3898
3879
|
};
|
|
3899
3880
|
|
|
3900
3881
|
// src/node/mdx/remarkPlugins/checkDeadLink.ts
|
|
@@ -3956,6 +3937,7 @@ var remarkBuiltin = ({ globalComponents }) => {
|
|
|
3956
3937
|
|
|
3957
3938
|
// src/node/mdx/options.ts
|
|
3958
3939
|
async function createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver) {
|
|
3940
|
+
const cleanUrls = Boolean(config?.route?.cleanUrls);
|
|
3959
3941
|
const { remarkPlugins: remarkPluginsFromConfig = [], rehypePlugins: rehypePluginsFromConfig = [], globalComponents: globalComponentsFromConfig = [] } = config?.markdown || {};
|
|
3960
3942
|
const rspressPlugins = pluginDriver.getPlugins();
|
|
3961
3943
|
const remarkPluginsFromPlugins = rspressPlugins.flatMap((plugin) => plugin.markdown?.remarkPlugins || []);
|
|
@@ -3975,6 +3957,7 @@ async function createMDXOptions(docDirectory, config, checkDeadLinks, routeServi
|
|
|
3975
3957
|
remarkPluginNormalizeLink,
|
|
3976
3958
|
{
|
|
3977
3959
|
base: config?.base || "",
|
|
3960
|
+
cleanUrls,
|
|
3978
3961
|
defaultLang,
|
|
3979
3962
|
root: docDirectory
|
|
3980
3963
|
}
|
|
@@ -4032,11 +4015,11 @@ async function mdxLoader(context, source, callback) {
|
|
|
4032
4015
|
context.cacheable(true);
|
|
4033
4016
|
let pageMeta = {
|
|
4034
4017
|
title: "",
|
|
4035
|
-
toc: []
|
|
4036
|
-
frontmatter: {}
|
|
4018
|
+
toc: []
|
|
4037
4019
|
};
|
|
4038
4020
|
const { config, docDirectory, checkDeadLinks, routeService, enableMdxRs, pluginDriver } = options2;
|
|
4039
4021
|
const { data: frontmatter, content } = (0, import_gray_matter.default)(source);
|
|
4022
|
+
const hasFrontMatter = Object.keys(frontmatter).length > 0;
|
|
4040
4023
|
try {
|
|
4041
4024
|
let compileResult;
|
|
4042
4025
|
if (!enableMdxRs) {
|
|
@@ -4052,8 +4035,7 @@ async function mdxLoader(context, source, callback) {
|
|
|
4052
4035
|
});
|
|
4053
4036
|
compileResult = String(vFile);
|
|
4054
4037
|
pageMeta = {
|
|
4055
|
-
...compiler.data("pageMeta")
|
|
4056
|
-
frontmatter
|
|
4038
|
+
...compiler.data("pageMeta")
|
|
4057
4039
|
};
|
|
4058
4040
|
} else {
|
|
4059
4041
|
const { compile } = __require("@rspress/mdx-rs");
|
|
@@ -4066,16 +4048,18 @@ async function mdxLoader(context, source, callback) {
|
|
|
4066
4048
|
compileResult = code;
|
|
4067
4049
|
pageMeta = {
|
|
4068
4050
|
toc,
|
|
4069
|
-
title
|
|
4070
|
-
frontmatter
|
|
4051
|
+
title
|
|
4071
4052
|
};
|
|
4072
4053
|
if (checkDeadLinks) {
|
|
4073
4054
|
checkLinks(links, filepath, docDirectory, routeService);
|
|
4074
4055
|
}
|
|
4075
4056
|
}
|
|
4076
|
-
const result =
|
|
4077
|
-
|
|
4078
|
-
${
|
|
4057
|
+
const result = `${compileResult}
|
|
4058
|
+
MDXContent.__RSPRESS_PAGE_META = {};
|
|
4059
|
+
MDXContent.__RSPRESS_PAGE_META["${encodeURIComponent(normalizePath(path6.relative(docDirectory, filepath)))}"] = ${JSON.stringify(pageMeta)};
|
|
4060
|
+
${hasFrontMatter ? `export const frontmatter = ${JSON.stringify(frontmatter)};` : ""}
|
|
4061
|
+
|
|
4062
|
+
`;
|
|
4079
4063
|
callback(null, result);
|
|
4080
4064
|
} catch (e) {
|
|
4081
4065
|
console.error(`MDX compile error: ${e.message} in ${filepath}`);
|