From 2c9b1d0fa5e439e99c05aa8a2cceb71ad5a35031 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/layouts/partials/images/image.html b/layouts/partials/images/image.html index 5fa8b33..55afdec 100644 --- a/layouts/partials/images/image.html +++ b/layouts/partials/images/image.html @@ -62,12 +62,16 @@ {{- 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 }} + {{- warnf "%v" $res.MediaType }} + {{- $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)) }}