* 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
54 lines
1.5 KiB
HTML
54 lines
1.5 KiB
HTML
/// Params:
|
|
/// Resources: Where to search for images
|
|
/// Image: Image URL
|
|
|
|
/// Returns:
|
|
/// Resource: Hugo image resource object
|
|
/// Permalink: Image URL
|
|
/// Height: Image height
|
|
/// Width: Image width
|
|
|
|
{{ $result := "" }}
|
|
|
|
{{ 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" . }}
|
|
{{ else with .Value }}
|
|
{{ $resource = . }}
|
|
{{ else }}
|
|
{{ errorf "Unable to get remote resource %q" $url }}
|
|
{{ end }}
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
{{ with $resource }}
|
|
{{ if reflect.IsImageResourceProcessable . }}
|
|
{{ $result = dict
|
|
"Resource" $resource
|
|
"Permalink" $permalink
|
|
"Height" $resource.Height
|
|
"Width" $resource.Width
|
|
}}
|
|
{{ else }}
|
|
{{ $result = dict
|
|
"Resource" $resource
|
|
"Permalink" $permalink
|
|
"Height" nil
|
|
"Width" nil
|
|
}}
|
|
{{ end }}
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
{{ return $result }} |