From 8afe41efb8c510967227657ed0f56a9b653c7dce Mon Sep 17 00:00:00 2001 From: razonyang Date: Fri, 15 Mar 2024 10:28:36 +0800 Subject: [PATCH] fix: check if the image resource media type is avif and print error when necessary --- layouts/partials/images/image.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/layouts/partials/images/image.html b/layouts/partials/images/image.html index 5fa8b33..5c000a4 100644 --- a/layouts/partials/images/image.html +++ b/layouts/partials/images/image.html @@ -62,12 +62,15 @@ {{- end }} {{- with $res }} {{- $originalSrc = ($res | fingerprint "md5").RelPermalink }} - {{- $originalWidth = $res.Width }} - {{- $originalHeight = $res.Height }} {{/* Check if the image resource is valid. */}} {{- if ne $res.MediaType.MainType "image" }} {{- errorf "the image is invalid: %s" $filename }} {{- end }} + {{- if in (slice "image/avif") $res.MediaType.Type }} + {{- errorf "the image resource type %q is not supported: %s" $res.MediaType.Type $url.Path }} + {{- end }} + {{- $originalWidth = $res.Width }} + {{- $originalHeight = $res.Height }} {{/* Resize the image. */}} {{- if and $width $height }} {{- $res = .Resize (printf "%sx%s" (strings.TrimSuffix "px" $width) (strings.TrimSuffix "px" $height)) }}