fix: actually check image sizes
Some checks failed
Deploy to SFTP Server / build (push) Failing after 2m24s
Some checks failed
Deploy to SFTP Server / build (push) Failing after 2m24s
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
import type { ImageMetadata } from "astro";
|
import type { ImageMetadata } from "astro";
|
||||||
import { Picture as AstroImage } from "astro:assets";
|
import { Picture as AstroImage } from "astro:assets";
|
||||||
import { inferRemoteSize } from "astro/assets/utils";
|
import { inferRemoteSize, inferSize } from "astro/assets/utils";
|
||||||
import { getProcessedImage } from "@helpers/image";
|
import { getProcessedImage } from "@helpers/image";
|
||||||
interface Props {
|
interface Props {
|
||||||
src: ImageMetadata & { fsPath?: string; src?: string };
|
src: ImageMetadata & { fsPath?: string; src?: string };
|
||||||
@@ -15,11 +15,13 @@ interface Props {
|
|||||||
thumbnail?: boolean;
|
thumbnail?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkImage(image: ImageMetadata):Promise<({height:number,width:number}|undefined)> {
|
async function checkImage(
|
||||||
|
image: ImageMetadata,
|
||||||
|
): Promise<{ height: number; width: number } | undefined> {
|
||||||
const src = typeof image === "string" ? image : image.src;
|
const src = typeof image === "string" ? image : image.src;
|
||||||
if (!src) return;
|
if (!src) return;
|
||||||
try {
|
try {
|
||||||
if (src.startsWith("/@fs") || src.startsWith("/_astro")) return;
|
if (src.startsWith("/@fs") || src.startsWith("/_astro")) return {};
|
||||||
const res = await inferRemoteSize(src);
|
const res = await inferRemoteSize(src);
|
||||||
if (res.format) {
|
if (res.format) {
|
||||||
image.format = res.format;
|
image.format = res.format;
|
||||||
@@ -81,7 +83,6 @@ const sizes = thumbnail
|
|||||||
alt={alt}
|
alt={alt}
|
||||||
data-thumbhash={thumbhash}
|
data-thumbhash={thumbhash}
|
||||||
data-exif={JSON.stringify(exif)}
|
data-exif={JSON.stringify(exif)}
|
||||||
inferSize={true}
|
|
||||||
width={imageOk?.width}
|
width={imageOk?.width}
|
||||||
height={imageOk?.height}
|
height={imageOk?.height}
|
||||||
pictureAttributes={{
|
pictureAttributes={{
|
||||||
@@ -94,5 +95,7 @@ const sizes = thumbnail
|
|||||||
.join(", ")}>
|
.join(", ")}>
|
||||||
<slot />
|
<slot />
|
||||||
</AstroImage>
|
</AstroImage>
|
||||||
) : <div>{JSON.stringify({ image })}</div>
|
) : (
|
||||||
|
<div>{JSON.stringify({ "imageOk":imageOk, image })}</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user