Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# build output
build/
dev-dist/
# generated types
.astro/

Expand Down
30 changes: 13 additions & 17 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,26 +1079,22 @@ export default defineConfig({
}),
AstroPWA({
registerType: "autoUpdate",

workbox: {
skipWaiting: true,
clientsClaim: true,
navigateFallback: "/404",
ignoreURLParametersMatching: [/./],
globPatterns: ["**/*.{html,js,css,png,svg,json,ttf,pf_fragment,pf_index,pf_meta,pagefind,wasm}"]
},
experimental: {
directoryAndTrailingSlashHandler: true
},
manifest: {
name: "Cubic Wiki",
short_name: "Cubic Wiki",
theme_color: "#2196f3",
background_color: "#424242",
display: "standalone",
start_url: "/",
icons: [
{
src: "/icons/book-192.png",
sizes: "192x192",
type: "image/png"
},
{
src: "/icons/book-512.png",
sizes: "512x512",
type: "image/png"
}
]
theme_color: "#2196f3",
background_color: "#424242"
}
}),
mermaid({
Expand All @@ -1108,7 +1104,7 @@ export default defineConfig({
vite: {
plugins: [tailwindcss()],
ssr: {
noExternal: ["naive-ui", "vueuc", "date-fns"]
noExternal: ["naive-ui", "vueuc", "date-fns", "workbox-window"]
}
}
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"starlight-links-validator": "^0.19.2",
"starlight-scroll-to-top": "^0.4.0",
"tailwindcss": "^4.1.18",
"typescript": "^5.9.3"
"typescript": "^5.9.3",
"workbox-window": "^7.4.0"
},
"engines": {
"node": ">=18.0"
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 60 additions & 8 deletions src/components/Head.astro
Original file line number Diff line number Diff line change
@@ -1,19 +1,71 @@
---
import StarlightHead from '@astrojs/starlight/components/Head.astro';
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 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 { fade, slide } from 'astro:transitions';
import PageOrder from "astro-vtbot/components/starlight/PageOrder.astro";
import { pwaInfo } from "virtual:pwa-info";
---

<VtbotStarlight
replaceSidebarContent retainCurrentPageMarker>
<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} />
<AutoNameSelected
selector="starlight-toc li"
prefix="vtbot-toc"
shuffle={true}
/>
<ProgressBar />
<PageOrder />

Expand Down
8 changes: 8 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" />
/// <reference types="vite-plugin-pwa/info" />
/// <reference types="vite-plugin-pwa/vanillajs" />
/// <reference types="@astrojs/starlight/types" />
/// <reference path="@astrojs/starlight/virtual.d.ts" />
/// <reference types="@astrojs/starlight/schema" />
/// <reference path="../node_modules/@astrojs/starlight/virtual.d.ts"/>
2 changes: 0 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"extends": "astro/tsconfigs/strict",
"include": [".astro/types.d.ts", "**/*"],
"exclude": ["dist"],
"compilerOptions": {
"resolveJsonModule": true,
"jsx": "preserve",
Expand Down