@cedgetec-utils/astro-components 1.11.0 → 1.13.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedgetec-utils/astro-components",
3
- "version": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "keywords": [
5
5
  "astro-component"
6
6
  ],
@@ -25,19 +25,37 @@ const title =
25
25
  const ogTitle = slug === "" ? props.siteName : `${props.title}`;
26
26
 
27
27
  // Common favicon / PWA icon sizes.
28
- const faviconSizes = [16, 32, 48, 96, 192, 512];
28
+ const faviconSizes = [32, 48, 96, 192, 512];
29
29
 
30
30
  type Icon = { type: string; sizes: string; href: string };
31
31
 
32
- const isSvg = (src: string | ImageMetadata) =>
33
- typeof src === "string" ? src.endsWith(".svg") : src.format === "svg";
32
+ const isSvg = async (src: string | ImageMetadata): Promise<boolean> => {
33
+ if (typeof src !== "string") return src.format === "svg";
34
+ if (src.endsWith(".svg")) return true;
35
+
36
+ // Remote / extensionless URLs (e.g. Directus assets) carry no hint in the
37
+ // path, so probe the response's content type. `getImage` can't tell us:
38
+ // it only builds the `/_image` URL — the rasterization (and any
39
+ // UnsupportedImageFormat error) happens later when that URL is requested,
40
+ // outside this component, so we must detect SVGs up front.
41
+ try {
42
+ const res = await fetch(src, { method: "HEAD" });
43
+ return (res.headers.get("content-type") ?? "").includes("svg");
44
+ } catch {
45
+ return false;
46
+ }
47
+ };
48
+
49
+ const buildSvgIcon = async (src: string | ImageMetadata): Promise<Icon[]> => {
50
+ const image = await getImage({ src, format: "svg", inferSize: true});
51
+ return [{ type: "image/svg+xml", sizes: "any", href: image.src }];
52
+ };
34
53
 
35
54
  const buildIcons = async (src: string | ImageMetadata): Promise<Icon[]> => {
36
55
  // An SVG favicon scales to any size, so pass it through unchanged rather
37
56
  // than rasterizing it to PNG at every size.
38
- if (isSvg(src)) {
39
- const image = await getImage({ src, format: "svg" });
40
- return [{ type: "image/svg+xml", sizes: "any", href: image.src }];
57
+ if (await isSvg(src)) {
58
+ return buildSvgIcon(src);
41
59
  }
42
60
 
43
61
  return Promise.all(
@@ -48,6 +66,7 @@ const buildIcons = async (src: string | ImageMetadata): Promise<Icon[]> => {
48
66
  height: size,
49
67
  fit: "contain",
50
68
  format: "png",
69
+ quality: "max",
51
70
  });
52
71
  return { type: "image/png", sizes: `${size}x${size}`, href: image.src };
53
72
  }),
@@ -58,11 +77,9 @@ const iconsLight = await buildIcons(props.icons.light);
58
77
  const iconsDark = await buildIcons(props.icons.dark);
59
78
 
60
79
  const openGraphImage = props.image
61
- ? await getImage({
62
- src: props.image,
63
- width: 1000,
64
- height: 500,
65
- })
80
+ ? (await isSvg(props.image))
81
+ ? await getImage({ src: props.image, format: "svg", quality: "max" })
82
+ : await getImage({ src: props.image, width: 1000, height: 500 })
66
83
  : null;
67
84
  ---
68
85
 
@@ -123,4 +140,4 @@ const openGraphImage = props.image
123
140
  {props.type && <meta property="og:type" content={props.type} />}
124
141
  {openGraphImage && <meta property="og:image" content={openGraphImage.src} />}
125
142
  <slot />
126
- </head>
143
+ </head>