feat(pwa): 全站 PWA 化——manifest+Service Worker+图标三件

- manifest.webmanifest:standalone 双语描述、192/512/maskable 图标
  (favicon.svg 经 sharp 直出)
- sw.js 保守策略:HTML network-first(不比 ESA 边缘更激进,防双重
  陈旧)+ install 预缓存 16 核心路由(SSG 全站 <1MB,全站离线可读)
  + /_astro|fonts|photos 不可变 cache-first + 评论 API/CMS 绕行
- BaseLayout:manifest+双 scheme theme-color+apple-touch-icon+一次性
  SW 注册(controller 守卫×VT 不重跑双保险)
- 踩坑入档:python 单线程 http.server 拖慢 16 并发预缓存,验收须等
  缓存键数稳定(曾误判 install 未跑);allSettled 静默是调试黑洞,
  install 失败必须探针可见

验证: 离线导航 6 页全 200(预缓存 16 条 500ms 就绪);node
      tests/e2e.mjs 31/31 PASS;manifest/sw/图标三路由 200

Spec: none (PWA 基建:manifest+SW+图标,离线矩阵入档)

Co-authored-by: GLM-5.3
This commit is contained in:
wait4xandGLM-5.3 committed 2026-10-25 20:49:16 +08:00
1 parent 8fe9455c23
commit a347ce8baf
6 files changed
+117

No files matched your search

+11
View File
@@ -60,6 +60,17 @@ const withSlash = (p: string) => (p.endsWith('/') ? p : `${p}/`);
<link rel="stylesheet" href={mono400} />
{track === 'reading' && <link rel="stylesheet" href={serifVar} />}
</noscript>
<!-- PWA:manifest + 双方案 theme-color(明暗随系统)+ iOS 图标 -->
<link rel="manifest" href="/manifest.webmanifest" />
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#fafafa" />
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#14161a" />
<link rel="apple-touch-icon" href="/icons/icon-192.png" />
<script is:inline>
// SW 注册一次性守卫:View Transitions 下内联脚本不重跑,双保险避免重复注册
if ('serviceWorker' in navigator && !navigator.serviceWorker.controller) {
addEventListener('load', () => navigator.serviceWorker.register('/sw.js'));
}
</script>
<link rel="alternate" hreflang="zh" href={new URL(withSlash(zhPath), Astro.site)} />
<link rel="alternate" hreflang="en" href={new URL(withSlash(enPath), Astro.site)} />
<link rel="alternate" hreflang="x-default" href={new URL(withSlash(zhPath), Astro.site)} />