1/**2 * PWA service-worker extension (wired via plugin-pwa's `swCustom`).3 *4 * The site builds with `trailingSlash: false`, so a route like5 * `/docs/getting-started` is emitted as `docs/getting-started.html` — a shape6 * the default worker never checks (it tries only `<path>` and7 * `<path>/index.html`), which would make every deep route miss the precache8 * offline. This handler covers exactly the extensionless, non-slash9 * navigations the default handler cannot match, so the two never race on the10 * same request.11 */12export default function swCustom(params) {13 if (!params.offlineMode) return;14 self.addEventListener("fetch", (event) => {15 if (event.request.mode !== "navigate") return;16 const url = new URL(event.request.url);17 if (url.origin !== self.location.origin) return;18 const path = url.pathname;19 const lastSegment = path.slice(path.lastIndexOf("/") + 1);20 // "/" and trailing-slash paths belong to the default handler; paths with21 // an extension are assets, not routes.22 if (path === "/" || path.endsWith("/") || lastSegment.includes(".")) return;23 event.respondWith((async () => {24 const cached = await caches.match(`${url.origin}${path}.html`, {25 // Precache keys carry a __WB_REVISION__ query.26 ignoreSearch: true,27 });28 if (cached) return cached;29 return fetch(event.request);30 })());31 });32}