Repository navigation
Expand file tree
/
Copy pathHead.astro
More file actions
82 lines (76 loc) · 2.32 KB
/
Copy pathHead.astro
File metadata and controls
82 lines (76 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
import StarlightHead from "@astrojs/starlight/components/Head.astro";
import VtbotStarlight from "astro-vtbot/components/starlight/Base.astro";
import PageOffset from "astro-vtbot/components/PageOffset.astro";
import AutoNameSelected from "astro-vtbot/components/AutoNameSelected.astro";
import ProgressBar from "astro-vtbot/components/ProgressBar.astro";
import PageOrder from "astro-vtbot/components/starlight/PageOrder.astro";
import { pwaInfo } from "virtual:pwa-info";
---
<script>
import { registerSW } from "virtual:pwa-register";
// 每10分钟检查一次更新,页面将自动刷新
const intervalMS = 10 * 60 * 1000;
const updateSW = registerSW({
immediate: true,
onRegisteredSW(swUrl, r) {
console.log("SW registered: ", swUrl);
r &&
setInterval(async () => {
if (r.installing || !navigator) return;
if ("connection" in navigator && !navigator.onLine) return;
const resp = await fetch(swUrl, {
cache: "no-store",
headers: {
cache: "no-store",
"cache-control": "no-cache",
},
});
if (resp?.status === 200) await r.update();
}, intervalMS);
},
onOfflineReady() {
console.log("PWA application ready to work offline");
},
});
</script>
<script is:inline type="module">
await import("/pagefind/pagefind-highlight.js");
new PagefindHighlight({
highlightParam: "highlight",
addStyles: false,
markOptions: {
className: "pagefind-highlight",
exclude: ["[data-pagefind-ignore]", "[data-pagefind-ignore] *"],
accuracy: { value: "complementary", limiters: [",", "", ".", ":"] },
acrossElements: true,
synonyms: {
1: "one",
2: "two",
},
},
});
</script>
{pwaInfo && <Fragment set:html={pwaInfo.webManifest.linkTag} />}
<VtbotStarlight replaceSidebarContent retainCurrentPageMarker>
<StarlightHead><slot /></StarlightHead>
</VtbotStarlight>
<PageOffset name="main" />
<AutoNameSelected
selector="starlight-toc li"
prefix="vtbot-toc"
shuffle={true}
/>
<ProgressBar />
<PageOrder />
<style is:global>
.swup-progress-bar {
background: linear-gradient(
to bottom,
var(--sl-color-accent),
var(--sl-color-accent-high),
var(--sl-color-accent)
);
height: 5px;
}
</style>