@rxdrag/website-lib-core 0.0.127 → 0.0.129
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/README.md +1 -1
- package/index.ts +1 -1
- package/package.json +4 -4
- package/src/astro/animation.ts +146 -146
- package/src/astro/background.ts +82 -86
- package/src/astro/base.ts +7 -0
- package/src/astro/business.ts +13 -0
- package/src/astro/grid/consts.ts +80 -80
- package/src/astro/grid/index.ts +2 -2
- package/src/astro/grid/types.ts +35 -35
- package/src/astro/image.ts +239 -239
- package/src/astro/index.ts +12 -10
- package/src/astro/link.ts +20 -21
- package/src/astro/media.ts +123 -123
- package/src/astro/nav.ts +13 -13
- package/src/astro/section/index.ts +7 -12
- package/src/component-logic/index.ts +1 -1
- package/src/component-logic/link-client.ts +32 -32
- package/src/component-logic/link.ts +61 -61
- package/src/design-tokens.ts +160 -160
- package/src/entify/Entify.ts +111 -101
- package/src/entify/IEntify.ts +157 -177
- package/src/entify/index.ts +4 -4
- package/src/entify/lib/collectCategoryIds.ts +20 -20
- package/src/entify/lib/fulltextSearch.ts +63 -62
- package/src/entify/lib/langFields.ts +14 -14
- package/src/entify/lib/listToTree.ts +23 -23
- package/src/entify/lib/newAvatarQueryOptions.ts +4 -4
- package/src/entify/lib/newOgImageQueryOptions.ts +5 -5
- package/src/entify/lib/newQueryPostOptions.ts +42 -45
- package/src/entify/lib/newQueryProductOptions.ts +96 -98
- package/src/entify/lib/newQueryProductsMediaOptions.ts +28 -28
- package/src/entify/lib/queryAllProducts.ts +40 -40
- package/src/entify/lib/queryBulletin.ts +28 -16
- package/src/entify/lib/queryEntityList.ts +41 -41
- package/src/entify/lib/queryFeaturedProducts.ts +69 -68
- package/src/entify/lib/queryLangs.ts +36 -60
- package/src/entify/lib/queryLatestPosts.ts +92 -91
- package/src/entify/lib/queryOneEntity.ts +63 -63
- package/src/entify/lib/queryOneMedia.ts +27 -27
- package/src/entify/lib/queryOnePostById.ts +21 -21
- package/src/entify/lib/queryOnePostBySlug.ts +40 -39
- package/src/entify/lib/queryOnePostCategoryBySlug.ts +35 -35
- package/src/entify/lib/queryOneProductById.ts +20 -20
- package/src/entify/lib/queryOneProductBySlug.ts +53 -52
- package/src/entify/lib/queryOneProductCategoryBySlug.ts +50 -49
- package/src/entify/lib/queryOneTheme.ts +54 -72
- package/src/entify/lib/queryOneUser.ts +38 -38
- package/src/entify/lib/queryPostCategories.ts +67 -67
- package/src/entify/lib/queryPostSlugs.ts +37 -37
- package/src/entify/lib/queryPosts.ts +175 -174
- package/src/entify/lib/queryProductCategories.ts +59 -59
- package/src/entify/lib/queryProducts.ts +145 -144
- package/src/entify/lib/queryProductsInMenu.ts +45 -45
- package/src/entify/lib/queryTagCategories.ts +58 -58
- package/src/entify/lib/queryTags.ts +57 -57
- package/src/entify/lib/queryUserIds.ts +24 -24
- package/src/entify/lib/queryUserPosts.ts +80 -79
- package/src/entify/lib/queryWebSiteSettings.ts +28 -28
- package/src/entify/lib/queryWebsite.ts +43 -43
- package/src/entify/lib/sendEmail.ts +7 -7
- package/src/entify/lib/toQueryOptions.ts +19 -19
- package/src/entify/lib/upsertEntity.ts +8 -8
- package/src/entify/types/index.ts +1 -1
- package/src/entify/types/utils.ts +11 -6
- package/src/entify/types/variables.ts +0 -1
- package/src/entify/view-model/funcs.ts +230 -230
- package/src/entify/view-model/index.ts +1 -1
- package/src/entify/view-model/models.ts +135 -135
- package/src/global.d.ts +7 -7
- package/src/index.ts +8 -8
- package/src/lib/formatDate.ts +15 -15
- package/src/lib/index.ts +3 -3
- package/src/lib/pagination.ts +114 -114
- package/src/lib/utils.ts +135 -135
- package/src/react/components/Analytics/eventHandlers.ts +173 -173
- package/src/react/components/Analytics/index.tsx +21 -21
- package/src/react/components/Analytics/singleton.ts +214 -214
- package/src/react/components/Analytics/tracking.ts +221 -221
- package/src/react/components/Analytics/types.ts +60 -60
- package/src/react/components/Analytics/utils.ts +95 -95
- package/src/react/components/AttachmentIcon/index.tsx +53 -53
- package/src/react/components/BackgroundHlsVideoPlayer.tsx +97 -97
- package/src/react/components/BackgroundVideoPlayer.tsx +32 -32
- package/src/react/components/Bulletin.tsx +30 -30
- package/src/react/components/ContactForm/ContactForm.tsx +289 -289
- package/src/react/components/ContactForm/Input.tsx +48 -48
- package/src/react/components/ContactForm/Input2.tsx +59 -59
- package/src/react/components/ContactForm/Submit.tsx +48 -48
- package/src/react/components/ContactForm/TelInput.tsx +215 -215
- package/src/react/components/ContactForm/Textarea.tsx +48 -48
- package/src/react/components/ContactForm/Textarea2.tsx +89 -89
- package/src/react/components/ContactForm/funcs.ts +64 -64
- package/src/react/components/ContactForm/index.ts +7 -7
- package/src/react/components/ContactForm/types.ts +68 -68
- package/src/react/components/GoogleConsent/CookieItemPanel.tsx +80 -80
- package/src/react/components/GoogleConsent/CumtomizedModal.tsx +148 -148
- package/src/react/components/GoogleConsent/GoogleConsent.tsx +100 -100
- package/src/react/components/GoogleConsent/gtags.ts +67 -67
- package/src/react/components/GoogleConsent/index.ts +2 -2
- package/src/react/components/GoogleConsent/types.ts +18 -18
- package/src/react/components/GoogleConsent//345/217/202/350/200/203.md +4 -4
- package/src/react/components/Icon/index.tsx +19 -19
- package/src/react/components/Medias/MainMedia.tsx +257 -257
- package/src/react/components/Medias/Thumbnail.tsx +62 -62
- package/src/react/components/Medias/VideoPlayer.tsx +114 -114
- package/src/react/components/Medias/index.tsx +271 -271
- package/src/react/components/ProductCard/ProductCard.tsx +24 -24
- package/src/react/components/ProductCard/ProductCta/index.tsx +28 -28
- package/src/react/components/ProductCard/ProductCta/style.css +3 -3
- package/src/react/components/ProductCard/ProductDescription/index.tsx +12 -12
- package/src/react/components/ProductCard/ProductDescription/style.css +5 -5
- package/src/react/components/ProductCard/ProductMedia/index.tsx +35 -35
- package/src/react/components/ProductCard/ProductMedia/style.css +5 -5
- package/src/react/components/ProductCard/ProductTitle/index.tsx +7 -7
- package/src/react/components/ProductCard/ProductTitle/style.css +3 -3
- package/src/react/components/ProductCard/ProductView.tsx +36 -36
- package/src/react/components/ProductCard/index.ts +4 -4
- package/src/react/components/ProductCard/useQueryProduct.ts +32 -32
- package/src/react/components/ReactModalTrigger.tsx +28 -28
- package/src/react/components/ReactVideoPlayer.tsx +29 -52
- package/src/react/components/RichTextOutline/index.tsx +75 -75
- package/src/react/components/RichTextOutline/useAnchorScroll.ts +23 -23
- package/src/react/components/Scroller.tsx +39 -39
- package/src/react/components/SearchInput.tsx +21 -21
- package/src/react/components/Share/index.tsx +86 -86
- package/src/react/components/Share/socials.tsx +79 -77
- package/src/react/components/Share//350/265/204/346/226/231.md +7 -7
- package/src/react/components/ToTop.tsx +72 -72
- package/src/react/components/VideoPlayIcon.tsx +43 -0
- package/src/react/components/all.ts +38 -38
- package/src/react/components/index.ts +16 -16
- package/src/robots.ts +4 -4
- package/src/entify/lib/newPageMetaOptions.ts +0 -18
- package/src/entify/lib/newQueryPageOptions.ts +0 -14
- package/src/entify/lib/queryOneIcon.ts +0 -27
- package/src/entify/lib/queryPageBySlug.ts +0 -43
- package/src/entify/lib/queryPageByType.ts +0 -44
package/src/astro/media.ts
CHANGED
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import { ImageSizes, Media } from "@rxdrag/rxcms-models";
|
|
2
|
-
|
|
3
|
-
export type FileFieldType =
|
|
4
|
-
| "thumbnail"
|
|
5
|
-
| "original"
|
|
6
|
-
| "small"
|
|
7
|
-
| "medium"
|
|
8
|
-
| "large"
|
|
9
|
-
| "resize";
|
|
10
|
-
|
|
11
|
-
export type ImageResize = {
|
|
12
|
-
width?: number;
|
|
13
|
-
height?: number;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const DEFUALT_WIDTH = 100;
|
|
17
|
-
export const DEFUALT_HEIGHT = 100;
|
|
18
|
-
|
|
19
|
-
export const DEFAULT_SAMLL: ImageResize = {
|
|
20
|
-
width: 400,
|
|
21
|
-
height: 400,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const DEFAULT_MEDIUM: ImageResize = {
|
|
25
|
-
width: 800,
|
|
26
|
-
height: 800,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const DEFAULT_LARGE: ImageResize = {
|
|
30
|
-
width: 1200,
|
|
31
|
-
height: 1200,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const DEFAULT_PRODUCT_IMAGE_SIZE: ImageResize = {
|
|
35
|
-
width: 800,
|
|
36
|
-
height: 800,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const DEFAULT_PRODUCT_THUMBNAIL_IMAGE_SIZE: ImageResize = {
|
|
40
|
-
width: 600,
|
|
41
|
-
height: 400,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const DEFAULT_POST_IMAGE_SIZE: ImageResize = {
|
|
45
|
-
width: 800,
|
|
46
|
-
height: 600,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const DEFAULT_POST_THUMBNAIL_IMAGE_SIZE: ImageResize = {
|
|
50
|
-
width: 600,
|
|
51
|
-
height: 400,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
//TODO:以后还要加transform参数
|
|
55
|
-
export type MediaImageProps = {
|
|
56
|
-
alt?: string;
|
|
57
|
-
className?: string;
|
|
58
|
-
src?: string;
|
|
59
|
-
//默认original
|
|
60
|
-
fileField?: FileFieldType;
|
|
61
|
-
resize?: ImageResize;
|
|
62
|
-
children?: React.ReactNode;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const transformMeidaFields = (
|
|
66
|
-
field?: FileFieldType,
|
|
67
|
-
resize?: ImageResize,
|
|
68
|
-
images?: ImageSizes
|
|
69
|
-
): string[] => {
|
|
70
|
-
const fields = ["original", "thumbnail"];
|
|
71
|
-
if (resize) {
|
|
72
|
-
fields.push(
|
|
73
|
-
`resize(width: ${resize.width || DEFUALT_WIDTH}, height: ${resize.height || DEFUALT_HEIGHT
|
|
74
|
-
})`
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
if (field === "small") {
|
|
78
|
-
fields.push(
|
|
79
|
-
`small(width: ${images?.small?.width || DEFAULT_SAMLL.width}, height: ${images?.small?.height || DEFAULT_SAMLL.height
|
|
80
|
-
})`
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
if (field === "medium") {
|
|
84
|
-
fields.push(
|
|
85
|
-
`medium(width: ${images?.medium?.width || DEFAULT_MEDIUM.width
|
|
86
|
-
}, height: ${images?.medium?.height || DEFAULT_MEDIUM.height})`
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
if (field === "large") {
|
|
90
|
-
fields.push(
|
|
91
|
-
`large(width: ${images?.large?.width || DEFAULT_LARGE.width}, height: ${images?.large?.height || DEFAULT_LARGE.height
|
|
92
|
-
})`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
return fields;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export const extractShowSrc = (
|
|
99
|
-
field?: FileFieldType,
|
|
100
|
-
resize?: ImageResize,
|
|
101
|
-
media?: Media
|
|
102
|
-
) => {
|
|
103
|
-
if (!media?.file) {
|
|
104
|
-
return "";
|
|
105
|
-
}
|
|
106
|
-
if (field === "thumbnail") {
|
|
107
|
-
return media.file.thumbnail;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (field === "resize" && resize) {
|
|
111
|
-
return media.file.resize;
|
|
112
|
-
}
|
|
113
|
-
if (field === "small" && media.file.small) {
|
|
114
|
-
return media.file.small;
|
|
115
|
-
}
|
|
116
|
-
if (field === "medium" && media.file.medium) {
|
|
117
|
-
return media.file.medium;
|
|
118
|
-
}
|
|
119
|
-
if (field === "large" && media.file.large) {
|
|
120
|
-
return media.file.large;
|
|
121
|
-
}
|
|
122
|
-
return media.file.original;
|
|
123
|
-
};
|
|
1
|
+
import { ImageSizes, Media } from "@rxdrag/rxcms-models";
|
|
2
|
+
|
|
3
|
+
export type FileFieldType =
|
|
4
|
+
| "thumbnail"
|
|
5
|
+
| "original"
|
|
6
|
+
| "small"
|
|
7
|
+
| "medium"
|
|
8
|
+
| "large"
|
|
9
|
+
| "resize";
|
|
10
|
+
|
|
11
|
+
export type ImageResize = {
|
|
12
|
+
width?: number;
|
|
13
|
+
height?: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const DEFUALT_WIDTH = 100;
|
|
17
|
+
export const DEFUALT_HEIGHT = 100;
|
|
18
|
+
|
|
19
|
+
export const DEFAULT_SAMLL: ImageResize = {
|
|
20
|
+
width: 400,
|
|
21
|
+
height: 400,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const DEFAULT_MEDIUM: ImageResize = {
|
|
25
|
+
width: 800,
|
|
26
|
+
height: 800,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const DEFAULT_LARGE: ImageResize = {
|
|
30
|
+
width: 1200,
|
|
31
|
+
height: 1200,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const DEFAULT_PRODUCT_IMAGE_SIZE: ImageResize = {
|
|
35
|
+
width: 800,
|
|
36
|
+
height: 800,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const DEFAULT_PRODUCT_THUMBNAIL_IMAGE_SIZE: ImageResize = {
|
|
40
|
+
width: 600,
|
|
41
|
+
height: 400,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const DEFAULT_POST_IMAGE_SIZE: ImageResize = {
|
|
45
|
+
width: 800,
|
|
46
|
+
height: 600,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const DEFAULT_POST_THUMBNAIL_IMAGE_SIZE: ImageResize = {
|
|
50
|
+
width: 600,
|
|
51
|
+
height: 400,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//TODO:以后还要加transform参数
|
|
55
|
+
export type MediaImageProps = {
|
|
56
|
+
alt?: string;
|
|
57
|
+
className?: string;
|
|
58
|
+
src?: string;
|
|
59
|
+
//默认original
|
|
60
|
+
fileField?: FileFieldType;
|
|
61
|
+
resize?: ImageResize;
|
|
62
|
+
children?: React.ReactNode;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const transformMeidaFields = (
|
|
66
|
+
field?: FileFieldType,
|
|
67
|
+
resize?: ImageResize,
|
|
68
|
+
images?: ImageSizes
|
|
69
|
+
): string[] => {
|
|
70
|
+
const fields = ["original", "thumbnail"];
|
|
71
|
+
if (resize) {
|
|
72
|
+
fields.push(
|
|
73
|
+
`resize(width: ${resize.width || DEFUALT_WIDTH}, height: ${resize.height || DEFUALT_HEIGHT
|
|
74
|
+
})`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (field === "small") {
|
|
78
|
+
fields.push(
|
|
79
|
+
`small(width: ${images?.small?.width || DEFAULT_SAMLL.width}, height: ${images?.small?.height || DEFAULT_SAMLL.height
|
|
80
|
+
})`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (field === "medium") {
|
|
84
|
+
fields.push(
|
|
85
|
+
`medium(width: ${images?.medium?.width || DEFAULT_MEDIUM.width
|
|
86
|
+
}, height: ${images?.medium?.height || DEFAULT_MEDIUM.height})`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (field === "large") {
|
|
90
|
+
fields.push(
|
|
91
|
+
`large(width: ${images?.large?.width || DEFAULT_LARGE.width}, height: ${images?.large?.height || DEFAULT_LARGE.height
|
|
92
|
+
})`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return fields;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const extractShowSrc = (
|
|
99
|
+
field?: FileFieldType,
|
|
100
|
+
resize?: ImageResize,
|
|
101
|
+
media?: Media
|
|
102
|
+
) => {
|
|
103
|
+
if (!media?.file) {
|
|
104
|
+
return "";
|
|
105
|
+
}
|
|
106
|
+
if (field === "thumbnail") {
|
|
107
|
+
return media.file.thumbnail;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (field === "resize" && resize) {
|
|
111
|
+
return media.file.resize;
|
|
112
|
+
}
|
|
113
|
+
if (field === "small" && media.file.small) {
|
|
114
|
+
return media.file.small;
|
|
115
|
+
}
|
|
116
|
+
if (field === "medium" && media.file.medium) {
|
|
117
|
+
return media.file.medium;
|
|
118
|
+
}
|
|
119
|
+
if (field === "large" && media.file.large) {
|
|
120
|
+
return media.file.large;
|
|
121
|
+
}
|
|
122
|
+
return media.file.original;
|
|
123
|
+
};
|
package/src/astro/nav.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { SvgComponent } from "astro/types";
|
|
2
|
-
import { LinkType } from "../component-logic";
|
|
3
|
-
import { ImageMetadata } from "./image";
|
|
4
|
-
|
|
5
|
-
export type NavItem = {
|
|
6
|
-
label: string;
|
|
7
|
-
to?: string;
|
|
8
|
-
type?: LinkType | string;
|
|
9
|
-
image?: ImageMetadata;
|
|
10
|
-
icon?: SvgComponent;
|
|
11
|
-
class?: string;
|
|
12
|
-
children?: NavItem[];
|
|
13
|
-
};
|
|
1
|
+
import { SvgComponent } from "astro/types";
|
|
2
|
+
import { LinkType } from "../component-logic";
|
|
3
|
+
import { ImageMetadata } from "./image";
|
|
4
|
+
|
|
5
|
+
export type NavItem = {
|
|
6
|
+
label: string;
|
|
7
|
+
to?: string;
|
|
8
|
+
type?: LinkType | string;
|
|
9
|
+
image?: ImageMetadata;
|
|
10
|
+
icon?: SvgComponent;
|
|
11
|
+
class?: string;
|
|
12
|
+
children?: NavItem[];
|
|
13
|
+
};
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
backgrounds?: BackgroundConfig[];
|
|
9
|
-
//动效
|
|
10
|
-
animation?: AOSAnimationConfig;
|
|
11
|
-
disableContainer?: boolean;
|
|
12
|
-
};
|
|
1
|
+
import { BackgroundConfig } from "../background";
|
|
2
|
+
|
|
3
|
+
export type SectionProps = {
|
|
4
|
+
class?: string;
|
|
5
|
+
className?: string;
|
|
6
|
+
backgrounds?: BackgroundConfig[];
|
|
7
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./link";
|
|
1
|
+
export * from "./link";
|
|
2
2
|
export * from "./link-client";
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
export const initLinks = () => {
|
|
2
|
-
// 获取当前URL的路径部分(去除域名)
|
|
3
|
-
const currentPath = window.location.pathname;
|
|
4
|
-
|
|
5
|
-
// 获取所有导航链接
|
|
6
|
-
const links = document.querySelectorAll<HTMLAnchorElement>(
|
|
7
|
-
"[data-actived-path]"
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
links.forEach((anchorLink) => {
|
|
11
|
-
// 从链接URL中提取路径部分
|
|
12
|
-
try {
|
|
13
|
-
const linkUrl = anchorLink.href ? new URL(anchorLink.href) : null;
|
|
14
|
-
const linkPath =
|
|
15
|
-
anchorLink.dataset.activedPath === "true"
|
|
16
|
-
? linkUrl?.pathname
|
|
17
|
-
: anchorLink.dataset.activedPath;
|
|
18
|
-
// 检查当前路径是否与链接路径匹配或是其子路径
|
|
19
|
-
if (
|
|
20
|
-
currentPath === linkPath ||
|
|
21
|
-
(linkPath !== "/" && linkPath && currentPath.startsWith(linkPath))
|
|
22
|
-
) {
|
|
23
|
-
anchorLink.classList.add("actived");
|
|
24
|
-
} else {
|
|
25
|
-
anchorLink.classList.remove("actived");
|
|
26
|
-
}
|
|
27
|
-
} catch (e) {
|
|
28
|
-
// 处理无效URL的情况
|
|
29
|
-
console.warn("Invalid URL:", e, anchorLink);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
};
|
|
1
|
+
export const initLinks = () => {
|
|
2
|
+
// 获取当前URL的路径部分(去除域名)
|
|
3
|
+
const currentPath = window.location.pathname;
|
|
4
|
+
|
|
5
|
+
// 获取所有导航链接
|
|
6
|
+
const links = document.querySelectorAll<HTMLAnchorElement>(
|
|
7
|
+
"[data-actived-path]"
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
links.forEach((anchorLink) => {
|
|
11
|
+
// 从链接URL中提取路径部分
|
|
12
|
+
try {
|
|
13
|
+
const linkUrl = anchorLink.href ? new URL(anchorLink.href) : null;
|
|
14
|
+
const linkPath =
|
|
15
|
+
anchorLink.dataset.activedPath === "true"
|
|
16
|
+
? linkUrl?.pathname
|
|
17
|
+
: anchorLink.dataset.activedPath;
|
|
18
|
+
// 检查当前路径是否与链接路径匹配或是其子路径
|
|
19
|
+
if (
|
|
20
|
+
currentPath === linkPath ||
|
|
21
|
+
(linkPath !== "/" && linkPath && currentPath.startsWith(linkPath))
|
|
22
|
+
) {
|
|
23
|
+
anchorLink.classList.add("actived");
|
|
24
|
+
} else {
|
|
25
|
+
anchorLink.classList.remove("actived");
|
|
26
|
+
}
|
|
27
|
+
} catch (e) {
|
|
28
|
+
// 处理无效URL的情况
|
|
29
|
+
console.warn("Invalid URL:", e, anchorLink);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
export type LinkType =
|
|
2
|
-
| "home"
|
|
3
|
-
| "product"
|
|
4
|
-
| "post"
|
|
5
|
-
| "page"
|
|
6
|
-
| "user"
|
|
7
|
-
| "product-category"
|
|
8
|
-
| "post-category"
|
|
9
|
-
| "link"
|
|
10
|
-
| "products"
|
|
11
|
-
| "posts";
|
|
12
|
-
|
|
13
|
-
export function toHref(
|
|
14
|
-
type: LinkType | string,
|
|
15
|
-
to: string,
|
|
16
|
-
options?: { productsSlug?: string; postsSlug?: string }
|
|
17
|
-
) {
|
|
18
|
-
const { productsSlug = "products", postsSlug = "posts" } = options || {};
|
|
19
|
-
|
|
20
|
-
if (type === "home") {
|
|
21
|
-
return "/";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (type === "link" || !type) {
|
|
25
|
-
return to;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (type === "products") {
|
|
29
|
-
return `/${productsSlug}/page/1`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (type === "posts") {
|
|
33
|
-
return `/${postsSlug}/page/1`;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (type === "page") {
|
|
37
|
-
return `/${to}`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (type === "post") {
|
|
41
|
-
return `/${postsSlug}/${to}`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (type === "product") {
|
|
45
|
-
return `/${productsSlug}/${to}`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (type === "user") {
|
|
49
|
-
return `/profiles/${to}`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (type === "product-category") {
|
|
53
|
-
return `/${productsSlug}/categories/${to}/1`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (type === "post-category") {
|
|
57
|
-
return `/${postsSlug}/categories/${to}/1`;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return `/${type}/${to}`;
|
|
61
|
-
}
|
|
1
|
+
export type LinkType =
|
|
2
|
+
| "home"
|
|
3
|
+
| "product"
|
|
4
|
+
| "post"
|
|
5
|
+
| "page"
|
|
6
|
+
| "user"
|
|
7
|
+
| "product-category"
|
|
8
|
+
| "post-category"
|
|
9
|
+
| "link"
|
|
10
|
+
| "products"
|
|
11
|
+
| "posts";
|
|
12
|
+
|
|
13
|
+
export function toHref(
|
|
14
|
+
type: LinkType | string,
|
|
15
|
+
to: string,
|
|
16
|
+
options?: { productsSlug?: string; postsSlug?: string }
|
|
17
|
+
) {
|
|
18
|
+
const { productsSlug = "products", postsSlug = "posts" } = options || {};
|
|
19
|
+
|
|
20
|
+
if (type === "home") {
|
|
21
|
+
return "/";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (type === "link" || !type) {
|
|
25
|
+
return to;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (type === "products") {
|
|
29
|
+
return `/${productsSlug}/page/1`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (type === "posts") {
|
|
33
|
+
return `/${postsSlug}/page/1`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (type === "page") {
|
|
37
|
+
return `/${to}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (type === "post") {
|
|
41
|
+
return `/${postsSlug}/${to}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (type === "product") {
|
|
45
|
+
return `/${productsSlug}/${to}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (type === "user") {
|
|
49
|
+
return `/profiles/${to}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (type === "product-category") {
|
|
53
|
+
return `/${productsSlug}/categories/${to}/1`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (type === "post-category") {
|
|
57
|
+
return `/${postsSlug}/categories/${to}/1`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return `/${type}/${to}`;
|
|
61
|
+
}
|