feat: add blacklist option for image optimisation and adapt Hugo 0.153.0+ (#666)

* feat: add blacklist option for image optimisation and enhance shortcode parameters

To ensure compatibility with Hugo 0.153.0, converting GIFs to WebP is prohibited. (gohugoio/hugo#14282)

* feat: enhance image plugin with Matches parameter for better resource handling and improve featured image rendering
This commit is contained in:
Cell
2025-12-21 23:42:15 +08:00
committed by GitHub
parent 88dfed5486
commit 3f14576073
5 changed files with 53 additions and 25 deletions
+7 -10
View File
@@ -3,16 +3,13 @@
<article class="single summary" itemscope itemtype="http://schema.org/Article">
{{- /* Featured image */ -}}
{{- $image := $params.featuredimagepreview | default $params.featuredimage -}}
{{- with dict "Path" $image "Resources" .Resources | partial "function/resource.html" }}
{{- $image = .RelPermalink }}
{{- end }}
{{- with .Resources.GetMatch "featured-image" -}}
{{- $image = .RelPermalink -}}
{{- $matches := slice -}}
{{- if .Resources.GetMatch "featured-image-preview" -}}
{{- $matches = $matches | append "featured-image-preview" -}}
{{- else if .Resources.GetMatch "featured-image" -}}
{{- $matches = $matches | append "featured-image" -}}
{{- end -}}
{{- with .Resources.GetMatch "featured-image-preview" -}}
{{- $image = .RelPermalink -}}
{{- end -}}
{{- with $image -}}
{{- if $image | or (gt (len $matches) 0) -}}
<div class="featured-image-preview">
<a href="{{ $.RelPermalink }}" aria-label="{{ $.Title }}">
{{- $optim := slice
@@ -20,7 +17,7 @@
(dict "Process" "fill 1200x360 Center webp q75" "descriptor" "1200w")
(dict "Process" "fill 1600x480 Center webp q75" "descriptor" "1600w")
-}}
{{- dict "Src" . "Title" $.Title "Resources" $.Resources "Loading" "eager" "Width" "800" "Height" "240" "Sizes" "(max-width: 680px) 100vw, (max-width: 960px) 80vw, (max-width: 1440px) 56vw, 800px" "OptimConfig" $optim "Alt" (printf "Featured image for %v" $.Title) | partial "plugin/image.html" -}}
{{- dict "Src" $image "Title" $.Title "Resources" $.Resources "Matches" $matches "Loading" "eager" "Width" "800" "Height" "240" "Sizes" "(max-width: 680px) 100vw, (max-width: 960px) 80vw, (max-width: 1440px) 56vw, 800px" "OptimConfig" $optim "Alt" (printf "Featured image for %v" $.Title) | partial "plugin/image.html" -}}
</a>
</div>
{{- end -}}