Skip to content

Commit 3e8bf19

Browse files
committed
wip: service worker
1 parent a0ae090 commit 3e8bf19

8 files changed

Lines changed: 2819 additions & 170 deletions

File tree

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// @ts-check
22
import {defineConfig} from "astro/config";
3+
import serviceWorker from "astrojs-service-worker";
34

45
// https://astro.build/config
5-
export default defineConfig({});
6+
export default defineConfig({
7+
integrations: [serviceWorker()],
8+
});

examples/example-site/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
"astro": "astro"
1212
},
1313
"dependencies": {
14-
"astro": "^4.16.7",
1514
"@astrojs/check": "^0.9.4",
15+
"@binz/visor": "workspace:*",
16+
"astro": "^4.16.7",
17+
"astrojs-service-worker": "^2.0.0",
1618
"sharp": "^0.33.5",
1719
"sharp-ico": "^0.1.5",
18-
"typescript": "^5.6.3",
19-
"@binz/visor": "workspace:*"
20+
"typescript": "^5.6.3"
2021
}
2122
}
Lines changed: 36 additions & 9 deletions
Loading

examples/example-site/src/pages/manifest.json.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ export const GET: APIRoute = Manifest({
1010
background_color: "#FFFFFF",
1111
description: "An example site",
1212
display: "standalone",
13-
favicon: {
13+
icon: {
1414
src: favicon,
15-
faviconSizes: faviconPngSizes,
15+
iconSizes: faviconPngSizes,
1616
},
1717
id: "example-com",
1818
short_name: "Example",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"clean": "turbo run clean",
1313
"dev": "turbo run dev",
1414
"lint": "turbo run lint",
15+
"preview": "turbo run preview",
1516
"test": "turbo run test",
1617
"ci:publish": "turbo run build && changeset publish"
1718
},

packages/visor/src/lib/manifest.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {APIRoute, UnresolvedImageTransform} from "astro";
22
import {getImage} from "astro:assets";
33

4-
const faviconPngSizes = [192, 384, 512, 1024];
4+
const iconPngSizes = [192, 384, 512, 1024];
55

66
interface Manifest {
77
name: string;
@@ -16,8 +16,8 @@ interface Manifest {
1616
}
1717

1818
export interface ManifestConfig extends Omit<Manifest, "icons"> {
19-
favicon: Omit<UnresolvedImageTransform, "width" | "height"> & {
20-
faviconSizes?: number[];
19+
icon: Omit<UnresolvedImageTransform, "width" | "height"> & {
20+
iconSizes?: number[];
2121
};
2222
}
2323

@@ -37,21 +37,22 @@ export const buildManifest: ManifestRoute =
3737
theme_color = "#000000",
3838
background_color = "#ffffff",
3939
id = name.replace(/[\s.]/g, "-").toLowerCase(),
40-
favicon: {src, faviconSizes = faviconPngSizes, ...faviconOptions},
40+
icon: {src, iconSizes = iconPngSizes, ...iconOptions},
4141
}): APIRoute =>
4242
async () => {
4343
const icons = await Promise.all(
44-
faviconSizes.map(async size => {
44+
iconSizes.map(async size => {
4545
const image = await getImage({
4646
src,
4747
width: size,
4848
height: size,
49-
...faviconOptions,
49+
...iconOptions,
5050
});
5151
return {
5252
src: image.src,
5353
type: `image/${image.options.format}`,
5454
sizes: `${image.options.width}x${image.options.height}`,
55+
purpose: "any",
5556
};
5657
})
5758
);

0 commit comments

Comments
 (0)