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:
+1
-1
@@ -10,7 +10,7 @@
|
||||
main() {
|
||||
DART_SASS_VERSION=1.97.1
|
||||
GO_VERSION=1.25.5
|
||||
HUGO_VERSION=0.156.0
|
||||
HUGO_VERSION=0.157.0
|
||||
NODE_VERSION=24.12.0
|
||||
|
||||
export TZ=Europe/Oslo
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
[hugoVersion]
|
||||
extended = true
|
||||
min = "0.154.0"
|
||||
min = "0.157.0"
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
{{ end }}
|
||||
|
||||
<div class="article-details"
|
||||
{{- if and $image $image.Resource -}}
|
||||
{{- if and $image (reflect.IsImageResourceProcessable $image.Resource) -}}
|
||||
{{- $colors := $image.Resource.Colors -}}
|
||||
{{- if $colors -}}
|
||||
{{- $vibrant := index $colors 0 -}}
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
/// Image: Image URL
|
||||
|
||||
/// Returns:
|
||||
/// Local: true if the image is local, false if it is remote
|
||||
/// Resource: Hugo image resource object, not nil if the image is local
|
||||
/// Resource: Hugo image resource object
|
||||
/// Permalink: Image URL
|
||||
/// Height: Image height
|
||||
/// Width: Image width
|
||||
@@ -13,10 +12,15 @@
|
||||
|
||||
{{ if .Image }}
|
||||
{{ $url := urls.Parse .Image }}
|
||||
{{ $permalink := .Image }}
|
||||
{{ $resource := "" }}
|
||||
|
||||
{{ if not (in (slice "https" "http") $url.Scheme) }}
|
||||
{{/* Local image */}}
|
||||
{{ $resource = .Resources.Get (printf "%s" (.Image | safeURL)) }}
|
||||
{{ $permalink = $resource.RelPermalink }}
|
||||
{{ else }}
|
||||
{{/* Remote image */}}
|
||||
{{ with try (resources.GetRemote $url) }}
|
||||
{{ with .Err }}
|
||||
{{ errorf "%s" . }}
|
||||
@@ -28,25 +32,22 @@
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if $resource }}
|
||||
{{- $isSVG := eq $resource.MediaType.SubType "svg" -}}
|
||||
{{- if $isSVG -}}
|
||||
{{ with $resource }}
|
||||
{{ if reflect.IsImageResourceProcessable . }}
|
||||
{{ $result = dict
|
||||
"Local" true
|
||||
"Resource" $resource
|
||||
"Permalink" $resource.RelPermalink
|
||||
"Height" nil
|
||||
"Width" nil
|
||||
}}
|
||||
{{- else -}}
|
||||
{{- $result = dict
|
||||
"Local" true
|
||||
"Resource" $resource
|
||||
"Permalink" $resource.RelPermalink
|
||||
"Permalink" $permalink
|
||||
"Height" $resource.Height
|
||||
"Width" $resource.Width
|
||||
}}
|
||||
{{- end -}}
|
||||
{{ else }}
|
||||
{{ $result = dict
|
||||
"Resource" $resource
|
||||
"Permalink" $permalink
|
||||
"Height" nil
|
||||
"Width" nil
|
||||
}}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ features = [
|
||||
"search",
|
||||
]
|
||||
|
||||
min_version = "0.154.0"
|
||||
min_version = "0.157.0"
|
||||
|
||||
[author]
|
||||
name = "Jimmy Cai"
|
||||
|
||||
Reference in New Issue
Block a user