@cedgetec-utils/astro-components 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/Head.astro +28 -16
package/package.json
CHANGED
|
@@ -25,33 +25,45 @@ const title =
|
|
|
25
25
|
const ogTitle = slug === "" ? props.siteName : `${props.title}`;
|
|
26
26
|
|
|
27
27
|
// Common favicon / PWA icon sizes.
|
|
28
|
-
const faviconSizes = [
|
|
28
|
+
const faviconSizes = [32, 48, 96, 192, 512];
|
|
29
29
|
|
|
30
30
|
type Icon = { type: string; sizes: string; href: string };
|
|
31
31
|
|
|
32
32
|
const isSvg = (src: string | ImageMetadata) =>
|
|
33
33
|
typeof src === "string" ? src.endsWith(".svg") : src.format === "svg";
|
|
34
34
|
|
|
35
|
+
const buildSvgIcon = async (src: string | ImageMetadata): Promise<Icon[]> => {
|
|
36
|
+
const image = await getImage({ src, format: "svg", quality: "max" });
|
|
37
|
+
return [{ type: "image/svg+xml", sizes: "any", href: image.src }];
|
|
38
|
+
};
|
|
39
|
+
|
|
35
40
|
const buildIcons = async (src: string | ImageMetadata): Promise<Icon[]> => {
|
|
36
41
|
// An SVG favicon scales to any size, so pass it through unchanged rather
|
|
37
42
|
// than rasterizing it to PNG at every size.
|
|
38
43
|
if (isSvg(src)) {
|
|
39
|
-
|
|
40
|
-
return [{ type: "image/svg+xml", sizes: "any", href: image.src }];
|
|
44
|
+
return buildSvgIcon(src);
|
|
41
45
|
}
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
try {
|
|
48
|
+
return await Promise.all(
|
|
49
|
+
faviconSizes.map(async (size) => {
|
|
50
|
+
const image = await getImage({
|
|
51
|
+
src,
|
|
52
|
+
width: size,
|
|
53
|
+
height: size,
|
|
54
|
+
fit: "contain",
|
|
55
|
+
format: "png",
|
|
56
|
+
quality: "max",
|
|
57
|
+
});
|
|
58
|
+
return { type: "image/png", sizes: `${size}x${size}`, href: image.src };
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
} catch {
|
|
62
|
+
// `isSvg` only detects SVGs by their `.svg` extension, so a string URL
|
|
63
|
+
// that points to an SVG without one slips through and fails to
|
|
64
|
+
// rasterize. Fall back to treating it as an SVG.
|
|
65
|
+
return buildSvgIcon(src);
|
|
66
|
+
}
|
|
55
67
|
};
|
|
56
68
|
|
|
57
69
|
const iconsLight = await buildIcons(props.icons.light);
|
|
@@ -123,4 +135,4 @@ const openGraphImage = props.image
|
|
|
123
135
|
{props.type && <meta property="og:type" content={props.type} />}
|
|
124
136
|
{openGraphImage && <meta property="og:image" content={openGraphImage.src} />}
|
|
125
137
|
<slot />
|
|
126
|
-
</head>
|
|
138
|
+
</head>
|