@rspress-theme-anatole/theme-default 0.3.5 → 0.4.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.
Files changed (2) hide show
  1. package/dist/bundle.js +49 -20
  2. package/package.json +3 -3
package/dist/bundle.js CHANGED
@@ -1065,7 +1065,7 @@ function DocLayout(props) {
1065
1065
  const { headingTitle, title, toc = [], frontmatter, routePath } = page;
1066
1066
  const [tabData, setTabData] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)({});
1067
1067
  const headers = toc;
1068
- const { themeConfig } = siteData;
1068
+ const { themeConfig, base } = siteData;
1069
1069
  const enableScrollToTop = themeConfig.enableScrollToTop ?? false;
1070
1070
  const localesData = useLocaleSiteData();
1071
1071
  const outlineTitle = localesData?.outlineTitle || themeConfig?.outlineTitle || 'ON THIS PAGE';
@@ -1110,10 +1110,10 @@ function DocLayout(props) {
1110
1110
  function findActiveBreadcrumb(items, activeMatcher, parents = []) {
1111
1111
  for (const item of items) {
1112
1112
  if ('link' in item && item.link && activeMatcher(item.link)) {
1113
- return [...parents, item.text];
1113
+ return [...parents, { text: item.text, link: item.link }];
1114
1114
  }
1115
1115
  if ('items' in item) {
1116
- const found = findActiveBreadcrumb(item.items, activeMatcher, [...parents, item.text]);
1116
+ const found = findActiveBreadcrumb(item.items, activeMatcher, [...parents, { text: item.text, link: item.link, key: item._fileKey }]);
1117
1117
  if (found) return found;
1118
1118
  }
1119
1119
  }
@@ -1122,18 +1122,44 @@ function DocLayout(props) {
1122
1122
 
1123
1123
  const breadcrumb = findActiveBreadcrumb(sidebarData, activeMatcher) || [];
1124
1124
 
1125
- const breadcrumbNav = breadcrumb.map((text, idx) => (
1126
- text = text + (idx < breadcrumb.length - 1 ? ' > ' : '')
1127
- ));
1125
+ const breadcrumbNav = breadcrumb.map((item, idx) => {
1126
+ const normalizedBase = base.endsWith('/') ? base.slice(0, -1) : base;
1128
1127
 
1129
- if (frontmatter.breadcrumb) {
1130
- if (breadcrumbNav.length > 0) {
1131
- breadcrumbNav.unshift(frontmatter.breadcrumb + ' > ');
1132
- }
1133
- else {
1134
- breadcrumbNav.unshift(frontmatter.breadcrumb);
1128
+ if (idx === breadcrumb.length - 1) {
1129
+ return [
1130
+ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("span", {
1131
+ children: item.text
1132
+ }, idx)
1133
+ ];
1135
1134
  }
1136
- }
1135
+ return (
1136
+ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("span", {
1137
+ children: [
1138
+ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("a", {
1139
+ href: normalizedBase + (item.link || ''),
1140
+ style: { textDecoration: 'underline', fontWeight: 400, marginRight: 4, cursor: 'pointer' },
1141
+ onClick: (e) => {
1142
+ e.preventDefault();
1143
+
1144
+ if (item.link) {
1145
+ // 父级可点击,跳转到父级页面
1146
+ window.location.href = normalizedBase + item.link;
1147
+ return;
1148
+ } else {
1149
+ // 父级不可点击,跳转到当前级别下的第一个子节点页面
1150
+ window.location.href = normalizedBase + (item.key.startsWith('/') ? item.key : `/${item.key}`);
1151
+ return;
1152
+ }
1153
+ },
1154
+ children: [
1155
+ item.text,
1156
+ ]
1157
+ }, idx),
1158
+ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("span", { children: ' > ' })
1159
+ ]
1160
+ }, idx)
1161
+ );
1162
+ });
1137
1163
 
1138
1164
  return [
1139
1165
  (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
@@ -1191,18 +1217,21 @@ function DocLayout(props) {
1191
1217
  textDecoration: 'underline',
1192
1218
  fontWeight: 400
1193
1219
  },
1194
- href: '/',
1220
+ href: base,
1195
1221
  children: 'Home'
1196
1222
  }),
1197
1223
  (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("span", {
1198
1224
  children: ' > '
1199
1225
  }),
1200
- (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("span", {
1201
- style: {
1202
- fontWeight: '600'
1203
- },
1204
- children: breadcrumbNav
1205
- })
1226
+ frontmatter.breadcrumb ?
1227
+ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("span", {
1228
+ style: { fontWeight: '600' },
1229
+ children: [
1230
+ frontmatter.breadcrumb,
1231
+ breadcrumb.length > 0 ? (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("span", { children: ' > ' }) : null
1232
+ ]
1233
+ }) : null,
1234
+ ...breadcrumbNav
1206
1235
  ]
1207
1236
  }),
1208
1237
  ]
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rspress-theme-anatole/theme-default",
3
3
  "author": "Anatole Tong",
4
- "version": "0.3.5",
4
+ "version": "0.4.0",
5
5
  "license": "MIT",
6
6
  "sideEffects": [
7
7
  "*.css",
@@ -21,7 +21,7 @@
21
21
  "types": "./dist/bundle.d.ts",
22
22
  "dependencies": {
23
23
  "@mdx-js/react": "2.3.0",
24
- "@rspress-theme-anatole/shared": "0.3.5",
24
+ "@rspress-theme-anatole/shared": "0.4.0",
25
25
  "@rspress/runtime": "1.43.8",
26
26
  "body-scroll-lock": "4.0.0-beta.0",
27
27
  "copy-to-clipboard": "^3.3.3",
@@ -35,7 +35,7 @@
35
35
  "react-helmet-async": "^1.3.0",
36
36
  "react-router-dom": "6.29.0",
37
37
  "react-syntax-highlighter": "^15.6.1",
38
- "@rspress-theme-anatole/rspress-plugin-mermaid": "0.3.5"
38
+ "@rspress-theme-anatole/rspress-plugin-mermaid": "0.4.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@microsoft/api-extractor": "^7.49.2",