fix: keep external image url, and use reflect.IsImageResourceProcessable to check for svg and other non-processable image formats (#1282)

* fix: keep external image url, and use reflect.IsImageResourceProcessable to check for svg

* build: update Hugo version to 0.157.0 in the build script.

* docs: remove `Local` return value and simplify `Resource` description in image helper

* Check for reflect.IsImageResourceProcessable before getting color from image

* chore: update minimum Hugo version to 0.157.0
This commit is contained in:
Jimmy
2026-03-04 13:05:17 +01:00
committed by GitHub
parent a0bd0073bb
commit 78800c7379
5 changed files with 21 additions and 20 deletions
+1 -1
View File
@@ -10,7 +10,7 @@
main() { main() {
DART_SASS_VERSION=1.97.1 DART_SASS_VERSION=1.97.1
GO_VERSION=1.25.5 GO_VERSION=1.25.5
HUGO_VERSION=0.156.0 HUGO_VERSION=0.157.0
NODE_VERSION=24.12.0 NODE_VERSION=24.12.0
export TZ=Europe/Oslo export TZ=Europe/Oslo
+1 -1
View File
@@ -1,3 +1,3 @@
[hugoVersion] [hugoVersion]
extended = true extended = true
min = "0.154.0" min = "0.157.0"
+1 -1
View File
@@ -9,7 +9,7 @@
{{ end }} {{ end }}
<div class="article-details" <div class="article-details"
{{- if and $image $image.Resource -}} {{- if and $image (reflect.IsImageResourceProcessable $image.Resource) -}}
{{- $colors := $image.Resource.Colors -}} {{- $colors := $image.Resource.Colors -}}
{{- if $colors -}} {{- if $colors -}}
{{- $vibrant := index $colors 0 -}} {{- $vibrant := index $colors 0 -}}
+17 -16
View File
@@ -3,8 +3,7 @@
/// Image: Image URL /// Image: Image URL
/// Returns: /// Returns:
/// Local: true if the image is local, false if it is remote /// Resource: Hugo image resource object
/// Resource: Hugo image resource object, not nil if the image is local
/// Permalink: Image URL /// Permalink: Image URL
/// Height: Image height /// Height: Image height
/// Width: Image width /// Width: Image width
@@ -13,10 +12,15 @@
{{ if .Image }} {{ if .Image }}
{{ $url := urls.Parse .Image }} {{ $url := urls.Parse .Image }}
{{ $permalink := .Image }}
{{ $resource := "" }} {{ $resource := "" }}
{{ if not (in (slice "https" "http") $url.Scheme) }} {{ if not (in (slice "https" "http") $url.Scheme) }}
{{/* Local image */}}
{{ $resource = .Resources.Get (printf "%s" (.Image | safeURL)) }} {{ $resource = .Resources.Get (printf "%s" (.Image | safeURL)) }}
{{ $permalink = $resource.RelPermalink }}
{{ else }} {{ else }}
{{/* Remote image */}}
{{ with try (resources.GetRemote $url) }} {{ with try (resources.GetRemote $url) }}
{{ with .Err }} {{ with .Err }}
{{ errorf "%s" . }} {{ errorf "%s" . }}
@@ -28,25 +32,22 @@
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ if $resource }} {{ with $resource }}
{{- $isSVG := eq $resource.MediaType.SubType "svg" -}} {{ if reflect.IsImageResourceProcessable . }}
{{- if $isSVG -}}
{{ $result = dict {{ $result = dict
"Local" true
"Resource" $resource "Resource" $resource
"Permalink" $resource.RelPermalink "Permalink" $permalink
"Height" nil
"Width" nil
}}
{{- else -}}
{{- $result = dict
"Local" true
"Resource" $resource
"Permalink" $resource.RelPermalink
"Height" $resource.Height "Height" $resource.Height
"Width" $resource.Width "Width" $resource.Width
}} }}
{{- end -}} {{ else }}
{{ $result = dict
"Resource" $resource
"Permalink" $permalink
"Height" nil
"Width" nil
}}
{{ end }}
{{ end }} {{ end }}
{{ end }} {{ end }}
+1 -1
View File
@@ -20,7 +20,7 @@ features = [
"search", "search",
] ]
min_version = "0.154.0" min_version = "0.157.0"
[author] [author]
name = "Jimmy Cai" name = "Jimmy Cai"