@xingwangzhe/stalux 1.28.2 → 1.28.4
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xingwangzhe/stalux",
|
|
3
|
-
"version": "1.28.
|
|
3
|
+
"version": "1.28.4",
|
|
4
4
|
"description": "A powerful, modern Astro blog theme — use as template or install as plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -121,13 +121,13 @@
|
|
|
121
121
|
"@biomejs/biome": "2.5.14",
|
|
122
122
|
"@types/node": "^26.6.2",
|
|
123
123
|
"@vitest/coverage-v8": "5.0.1",
|
|
124
|
-
"astro": "^7.3.
|
|
124
|
+
"astro": "^7.3.5",
|
|
125
125
|
"knip": "^6.37.0",
|
|
126
126
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
127
127
|
"vite": "8.3.0",
|
|
128
128
|
"vitest": "5.0.1"
|
|
129
129
|
},
|
|
130
130
|
"peerDependencies": {
|
|
131
|
-
"astro": "7.3.
|
|
131
|
+
"astro": "^7.3.5"
|
|
132
132
|
}
|
|
133
133
|
}
|
|
@@ -12,6 +12,36 @@ declare global {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
function appendWhenIdle(script: HTMLScriptElement): void {
|
|
16
|
+
const append = () => document.head.appendChild(script);
|
|
17
|
+
const requestIdle = (
|
|
18
|
+
window as Window & {
|
|
19
|
+
requestIdleCallback?: (callback: () => void, options?: { timeout: number }) => number;
|
|
20
|
+
}
|
|
21
|
+
).requestIdleCallback;
|
|
22
|
+
|
|
23
|
+
if (requestIdle) requestIdle.call(window, append, { timeout: 1200 });
|
|
24
|
+
else window.setTimeout(append, 0);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function appendAfterPageLoad(script: HTMLScriptElement): void {
|
|
28
|
+
let appended = false;
|
|
29
|
+
const schedule = () => {
|
|
30
|
+
if (appended) return;
|
|
31
|
+
appended = true;
|
|
32
|
+
appendWhenIdle(script);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
if (document.readyState === "complete") {
|
|
36
|
+
schedule();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
window.addEventListener("load", schedule, { once: true });
|
|
41
|
+
// Avoid indefinitely delaying analytics if an image or other resource stalls load.
|
|
42
|
+
window.setTimeout(schedule, 5000);
|
|
43
|
+
}
|
|
44
|
+
|
|
15
45
|
function load() {
|
|
16
46
|
const gaID = document.body?.dataset.staluxGaId;
|
|
17
47
|
if (!gaID) return;
|
|
@@ -21,6 +51,7 @@ function load() {
|
|
|
21
51
|
window.__staluxGoogleScriptLoaded = true;
|
|
22
52
|
const script = document.createElement("script");
|
|
23
53
|
script.async = true;
|
|
54
|
+
script.fetchPriority = "low";
|
|
24
55
|
script.dataset.staluxGoogle = "true";
|
|
25
56
|
script.src = `https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(gaID)}`;
|
|
26
57
|
script.addEventListener("load", () => logger.debug("external script loaded"), {
|
|
@@ -31,8 +62,8 @@ function load() {
|
|
|
31
62
|
() => logger.warn("external script failed to load (network or content blocker)"),
|
|
32
63
|
{ once: true },
|
|
33
64
|
);
|
|
34
|
-
logger.debug("
|
|
35
|
-
|
|
65
|
+
logger.debug("deferred external script until page load and idle time");
|
|
66
|
+
appendAfterPageLoad(script);
|
|
36
67
|
}
|
|
37
68
|
if (!window.__staluxAnalyticsLoaded) {
|
|
38
69
|
window.__staluxAnalyticsLoaded = true;
|