diff options
-rw-r--r-- | astro.config.ts | 59 | ||||
-rw-r--r-- | deno.lock | 5 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | public/blog/read/TEMPLATE (renamed from public/blog/TEMPLATE) | 0 | ||||
-rw-r--r-- | public/blog/read/legislativas-2025.md (renamed from public/blog/legislativas-2025.md) | 0 | ||||
-rw-r--r-- | public/blog/read/legislativas-2025.md.sig (renamed from public/blog/legislativas-2025.md.sig) | bin | 2097 -> 2097 bytes | |||
-rw-r--r-- | public/blog/read/micro-test.md (renamed from public/blog/micro-test.md) | 0 | ||||
-rw-r--r-- | src/components/BaseHead.astro | 7 | ||||
-rw-r--r-- | src/components/signature/Downloads.astro | 2 | ||||
-rw-r--r-- | src/content.config.ts | 2 |
10 files changed, 43 insertions, 34 deletions
diff --git a/astro.config.ts b/astro.config.ts index c7d4946..35fb69d 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -15,9 +15,7 @@ import remarkToc from "remark-toc"; import { get } from "./src/utils/anonymous.ts"; import { loadEnv } from "vite"; import process from "node:process"; -import { generateSW, injectManifest } from "workbox-build"; -import { NetworkFirst, StaleWhileRevalidate } from "workbox-strategies"; -import { ExpirationPlugin } from "workbox-expiration"; +import { generateSW } from "workbox-build"; // deno-lint-ignore no-non-null-assertion const { PUBLIC_SITE_URL } = loadEnv(process.env.NODE_ENV!, process.cwd(), ""); @@ -80,40 +78,51 @@ export default defineConfig({ name: "service worker", hooks: { "astro:build:done": async ({ dir, logger }) => { - // const { warnings, count, size } = await injectManifest({ - // globDirectory: dir.pathname, - // swSrc: "src/sw.ts", - // swDest: new URL("sw.js", dir).pathname, - // }); - - const theLatest = /^(\/public)?\/blog/; const { warnings, count, size } = await generateSW({ swDest: new URL("sw.js", dir).pathname, globDirectory: dir.pathname, - globPatterns: ["**/*"], - skipWaiting: true, + globPatterns: [ + "**/*.{html,css,webmanifest,svg,txt,xml}", + "_astro/*.js", + ], + globIgnores: ["blog/**/*", "keys/**/*"], + globStrict: true, + skipWaiting: false, clientsClaim: true, runtimeCaching: [{ - urlPattern({ sameOrigin, url }) { - return sameOrigin && theLatest.test(url.pathname); - }, - handler: new NetworkFirst({ + urlPattern: ({ sameOrigin, url }) => + sameOrigin && + /^\/blog\/read\/[a-z0-9-]+(?:\/|\.md|\.md\.sig)?$/.test( + url.pathname, + ), + handler: "NetworkFirst", + options: { cacheName: "posts", networkTimeoutSeconds: 3, - }), + }, }, { - urlPattern({ sameOrigin, url }) { - return sameOrigin && !theLatest.test(url.pathname); + urlPattern: ({ sameOrigin, url }) => + sameOrigin && + /^\/blog(\/(20\d{2}(\/\d{2}(\/\d{2})?)?)?|\/keywords(\/[\w-]+)?)?\/?$/ + .test(url.pathname), + handler: "NetworkFirst", + options: { + cacheName: "indexes", + networkTimeoutSeconds: 3, }, - handler: new StaleWhileRevalidate({ + }, { + urlPattern: ({ sameOrigin, url }) => + sameOrigin && /^(?!\/blog).*/.test(url.pathname), + handler: "StaleWhileRevalidate", + options: { cacheName: "resources", - plugins: [ - new ExpirationPlugin({ maxAgeSeconds: 60 * 60 * 24 * 30 }), - ], - }), + expiration: { + maxAgeSeconds: 60 * 60 * 24 * 30, + }, + }, }], navigateFallback: undefined, - navigationPreload: undefined, + navigationPreload: true, inlineWorkboxRuntime: true, cleanupOutdatedCaches: true, dontCacheBustURLsMatching: /^_astro\/.*\.js$/, @@ -41,8 +41,7 @@ "npm:vfile@^6.0.3": "6.0.3", "npm:vite@7": "7.0.0_picomatch@4.0.2_@types+node@22.15.15", "npm:workbox-build@^7.3.0": "7.3.0_ajv@8.17.1_@babel+core@7.27.7_rollup@2.79.2", - "npm:workbox-expiration@^7.3.0": "7.3.0", - "npm:workbox-strategies@^7.3.0": "7.3.0", + "npm:workbox-core@^7.3.0": "7.3.0", "npm:workbox-window@^7.3.0": "7.3.0", "npm:yaqrcode@~0.2.1": "0.2.1", "npm:zod@^3.25.67": "3.25.67" @@ -5321,8 +5320,6 @@ "npm:vfile@^6.0.3", "npm:vite@7", "npm:workbox-build@^7.3.0", - "npm:workbox-expiration@^7.3.0", - "npm:workbox-strategies@^7.3.0", "npm:workbox-window@^7.3.0", "npm:yaqrcode@~0.2.1", "npm:zod@^3.25.67" diff --git a/package.json b/package.json index e93d4b7..f0adf95 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,6 @@ "unist-util-visit": "^5.0.0", "vfile": "^6.0.3", "workbox-build": "^7.3.0", - "workbox-expiration": "^7.3.0", - "workbox-strategies": "^7.3.0", "workbox-window": "^7.3.0", "yaqrcode": "^0.2.1", "zod": "^3.25.67" diff --git a/public/blog/TEMPLATE b/public/blog/read/TEMPLATE index ea0bdd7..ea0bdd7 100644 --- a/public/blog/TEMPLATE +++ b/public/blog/read/TEMPLATE diff --git a/public/blog/legislativas-2025.md b/public/blog/read/legislativas-2025.md index f6baf82..f6baf82 100644 --- a/public/blog/legislativas-2025.md +++ b/public/blog/read/legislativas-2025.md diff --git a/public/blog/legislativas-2025.md.sig b/public/blog/read/legislativas-2025.md.sig Binary files differindex 8ad85c9..8ad85c9 100644 --- a/public/blog/legislativas-2025.md.sig +++ b/public/blog/read/legislativas-2025.md.sig diff --git a/public/blog/micro-test.md b/public/blog/read/micro-test.md index 8d64b60..8d64b60 100644 --- a/public/blog/micro-test.md +++ b/public/blog/read/micro-test.md diff --git a/src/components/BaseHead.astro b/src/components/BaseHead.astro index 41926ad..65e568c 100644 --- a/src/components/BaseHead.astro +++ b/src/components/BaseHead.astro @@ -98,9 +98,14 @@ const { const wb = new Workbox("/sw.js", { type: "module" }); wb.addEventListener("activated", (_event) => { + if (!location.pathname.startsWith("/blog/read/")) { + return; + } const urlsToCache = [ location.href, - ...performance.getEntriesByType("resource").map((r) => r.name), + location.href + ".md", + location.href + ".md.sig", + ///...performance.getEntriesByType("resource").map((r) => r.name), ]; wb.messageSW({ type: "CACHE_URLS", diff --git a/src/components/signature/Downloads.astro b/src/components/signature/Downloads.astro index ac8215f..3497b37 100644 --- a/src/components/signature/Downloads.astro +++ b/src/components/signature/Downloads.astro @@ -9,7 +9,7 @@ interface Props { const { lang } = Astro.props; let source = new URL( - `${Astro.url.href.replace("read/", "").replace(/\/$/, "")}.md`, + `${Astro.url.href.replace(/\/$/, "")}.md`, ); const dir = await gitDir(); diff --git a/src/content.config.ts b/src/content.config.ts index 821faf5..d3504e5 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -5,7 +5,7 @@ import { parse } from "toml"; import { Blog, Entity } from "./lib/collection/schemas.ts"; const blog = defineCollection({ - loader: glob({ base: "./public/blog", pattern: "+([0-9a-z-]).md" }), + loader: glob({ base: "./public/blog/read", pattern: "+([0-9a-z-]).md" }), schema: Blog, }); |