@rxdrag/website-lib 0.0.144 → 0.0.145
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/components/Document.astro +113 -4
- package/package.json +4 -4
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
---
|
|
2
|
+
import "aos/dist/aos.css";
|
|
2
3
|
import { PageType, type PageMeta } from "@rxdrag/rxcms-models";
|
|
3
4
|
import type { Locals } from "@rxdrag/website-lib-core";
|
|
4
5
|
import Meta from "@rxdrag/website-lib/components/Meta.astro";
|
|
5
6
|
import { Entify } from "@rxdrag/website-lib-core";
|
|
7
|
+
import { ClientRouter } from "astro:transitions";
|
|
6
8
|
|
|
7
9
|
const { env, imageSizes } = Astro.locals as Locals;
|
|
8
10
|
|
|
@@ -31,6 +33,15 @@ const {
|
|
|
31
33
|
...rest
|
|
32
34
|
} = Astro.props;
|
|
33
35
|
|
|
36
|
+
const bodyAttrs = {
|
|
37
|
+
"data-aos-easing": "ease-out-cubic",
|
|
38
|
+
"data-aos-duration": "800",
|
|
39
|
+
"data-aos-delay": "0",
|
|
40
|
+
"data-aos-offset": "50",
|
|
41
|
+
"data-aos-once": "true",
|
|
42
|
+
...rest,
|
|
43
|
+
};
|
|
44
|
+
|
|
34
45
|
//TODO: 添加meta获取逻辑,有可能需要重构后端数据结构,现在看来,只有动态内容需要获取meta,其它页面可以传入
|
|
35
46
|
|
|
36
47
|
let resolvedMeta: PageMeta | undefined = meta;
|
|
@@ -40,8 +51,10 @@ let resolvedTitle: string | undefined = title;
|
|
|
40
51
|
if (!resolvedMeta || !resolvedTitle) {
|
|
41
52
|
try {
|
|
42
53
|
const pathname = Astro.url?.pathname || "";
|
|
43
|
-
const slug =
|
|
44
|
-
|
|
54
|
+
const slug =
|
|
55
|
+
typeof Astro.params?.slug === "string" ? Astro.params.slug : undefined;
|
|
56
|
+
const id =
|
|
57
|
+
typeof Astro.params?.id === "string" ? Astro.params.id : undefined;
|
|
45
58
|
|
|
46
59
|
if (slug && pathname.startsWith("/posts/categories/")) {
|
|
47
60
|
const category = await rx.getPostCategoryBySlug(slug);
|
|
@@ -63,7 +76,10 @@ if (!resolvedMeta || !resolvedTitle) {
|
|
|
63
76
|
resolvedTitle = resolvedTitle ?? post?.title;
|
|
64
77
|
resolvedMeta = resolvedMeta ?? post?.meta;
|
|
65
78
|
} else if (slug && pathname.startsWith("/products/")) {
|
|
66
|
-
const product = await rx.getProductBySlug(slug, {
|
|
79
|
+
const product = await rx.getProductBySlug(slug, {
|
|
80
|
+
width: 800,
|
|
81
|
+
height: 800,
|
|
82
|
+
});
|
|
67
83
|
resolvedTitle = resolvedTitle ?? product?.title;
|
|
68
84
|
resolvedMeta = resolvedMeta ?? product?.meta;
|
|
69
85
|
}
|
|
@@ -86,6 +102,99 @@ if (!resolvedMeta || !resolvedTitle) {
|
|
|
86
102
|
<link rel="sitemap" href="/sitemap-index.xml" />
|
|
87
103
|
<link rel="icon" type="image/png" href="/favicon.png" />
|
|
88
104
|
<!-- 给上层 Layout/页面注入自定义 head 内容(预加载、脚本、样式等) -->
|
|
105
|
+
<!-- 预连接 -->
|
|
106
|
+
<link
|
|
107
|
+
rel="preconnect"
|
|
108
|
+
href="https://customer-amj1dt4tnge8w6ji.cloudflarestream.com"
|
|
109
|
+
crossorigin
|
|
110
|
+
/>
|
|
111
|
+
<script>
|
|
112
|
+
const w = window as any;
|
|
113
|
+
const state =
|
|
114
|
+
w.__aos_state__ ||
|
|
115
|
+
(w.__aos_state__ = { inited: false, loading: null, aos: null });
|
|
116
|
+
|
|
117
|
+
const el = document.documentElement;
|
|
118
|
+
const raf = () =>
|
|
119
|
+
new Promise((resolve) =>
|
|
120
|
+
requestAnimationFrame(() => resolve(undefined)),
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const ensureAos = async () => {
|
|
124
|
+
if (state.aos) return state.aos;
|
|
125
|
+
if (!state.loading) {
|
|
126
|
+
state.loading = import("aos").then((m) => {
|
|
127
|
+
state.aos = m.default;
|
|
128
|
+
return state.aos;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return state.loading;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const bootOrRefresh = async () => {
|
|
135
|
+
if (
|
|
136
|
+
window.matchMedia &&
|
|
137
|
+
window.matchMedia("(prefers-reduced-motion: reduce)").matches
|
|
138
|
+
) {
|
|
139
|
+
el.classList.add("aos-ready");
|
|
140
|
+
el.classList.remove("aos-preload");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!document.querySelector("[data-aos]")) {
|
|
145
|
+
el.classList.add("aos-ready");
|
|
146
|
+
el.classList.remove("aos-preload");
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
el.classList.add("aos-preload");
|
|
151
|
+
el.classList.remove("aos-ready");
|
|
152
|
+
|
|
153
|
+
const AOS = await ensureAos();
|
|
154
|
+
if (!state.inited) {
|
|
155
|
+
state.inited = true;
|
|
156
|
+
AOS.init({
|
|
157
|
+
duration: 800,
|
|
158
|
+
easing: "ease-out-cubic",
|
|
159
|
+
once: true,
|
|
160
|
+
offset: 50,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
await raf();
|
|
165
|
+
await raf();
|
|
166
|
+
AOS.refresh();
|
|
167
|
+
|
|
168
|
+
el.classList.add("aos-ready");
|
|
169
|
+
el.classList.remove("aos-preload");
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const boot = () => {
|
|
173
|
+
bootOrRefresh();
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
if (document.readyState === "loading") {
|
|
177
|
+
document.addEventListener("DOMContentLoaded", boot, { once: true });
|
|
178
|
+
} else {
|
|
179
|
+
boot();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
document.addEventListener("astro:page-load", boot);
|
|
183
|
+
document.addEventListener("astro:after-swap", boot);
|
|
184
|
+
</script>
|
|
185
|
+
<ClientRouter />
|
|
186
|
+
<!-- Consent default (Google) -->
|
|
187
|
+
<script is:inline>
|
|
188
|
+
window.dataLayer = window.dataLayer || [];
|
|
189
|
+
function gtag() {
|
|
190
|
+
dataLayer.push(arguments);
|
|
191
|
+
}
|
|
192
|
+
gtag("js", new Date());
|
|
193
|
+
gtag("consent", "default", {
|
|
194
|
+
ad_storage: "denied",
|
|
195
|
+
analytics_storage: "denied",
|
|
196
|
+
});
|
|
197
|
+
</script>
|
|
89
198
|
<slot name="head" />
|
|
90
199
|
<Meta title={resolvedTitle} content={resolvedMeta} />
|
|
91
200
|
<style>
|
|
@@ -97,7 +206,7 @@ if (!resolvedMeta || !resolvedTitle) {
|
|
|
97
206
|
</style>
|
|
98
207
|
</head>
|
|
99
208
|
<!-- rest 会被展开到 body 上,方便上层控制 data-* 等属性 -->
|
|
100
|
-
<body class:list={[className, className2]} {...
|
|
209
|
+
<body class:list={[className, className2]} {...bodyAttrs}>
|
|
101
210
|
<slot />
|
|
102
211
|
</body>
|
|
103
212
|
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxdrag/website-lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.145",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.ts",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"gsap": "^3.12.7",
|
|
30
30
|
"swiper": "^12.0.3",
|
|
31
31
|
"typescript": "^5",
|
|
32
|
-
"@rxdrag/entify-hooks": "0.2.79",
|
|
33
32
|
"@rxdrag/rxcms-models": "0.3.106",
|
|
34
|
-
"@rxdrag/
|
|
33
|
+
"@rxdrag/tiptap-preview": "0.0.3",
|
|
34
|
+
"@rxdrag/entify-hooks": "0.2.79",
|
|
35
35
|
"@rxdrag/tsconfig": "0.2.1",
|
|
36
|
-
"@rxdrag/
|
|
36
|
+
"@rxdrag/eslint-config-custom": "0.2.13"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"aos": "3.0.0-beta.6",
|