fix: check if resource exists before accessing .RelPermalink (#1299)
* fix: check if resource exists before accessing `.RelPermalink` closes https://github.com/CaiJimmy/hugo-theme-stack/issues/1297 * Set default value of $result in `helper/image` to dict
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
/// Height: Image height
|
/// Height: Image height
|
||||||
/// Width: Image width
|
/// Width: Image width
|
||||||
|
|
||||||
{{ $result := "" }}
|
{{ $result := dict }}
|
||||||
|
|
||||||
{{ if .Image }}
|
{{ if .Image }}
|
||||||
{{ $url := urls.Parse .Image }}
|
{{ $url := urls.Parse .Image }}
|
||||||
@@ -20,7 +20,6 @@
|
|||||||
{{ if not (in (slice "https" "http") $url.Scheme) }}
|
{{ if not (in (slice "https" "http") $url.Scheme) }}
|
||||||
{{/* Local image */}}
|
{{/* Local image */}}
|
||||||
{{ $resource = .Resources.Get (printf "%s" (.Image | safeURL)) }}
|
{{ $resource = .Resources.Get (printf "%s" (.Image | safeURL)) }}
|
||||||
{{ $permalink = $resource.RelPermalink }}
|
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{/* Remote image */}}
|
{{/* Remote image */}}
|
||||||
{{ with try (resources.GetRemote $url) }}
|
{{ with try (resources.GetRemote $url) }}
|
||||||
@@ -39,11 +38,12 @@
|
|||||||
{{ if and .Context.Site.Params.imageProcessing.autoOrient (reflect.IsImageResourceProcessable $resource) }}
|
{{ if and .Context.Site.Params.imageProcessing.autoOrient (reflect.IsImageResourceProcessable $resource) }}
|
||||||
{{ $filter := images.AutoOrient }}
|
{{ $filter := images.AutoOrient }}
|
||||||
{{ $resource = $resource | images.Filter $filter }}
|
{{ $resource = $resource | images.Filter $filter }}
|
||||||
{{ if $local }}
|
|
||||||
{{ $permalink = $resource.RelPermalink }}
|
|
||||||
{{ end }}
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if $local }}
|
||||||
|
{{ $permalink = $resource.RelPermalink }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
{{ if reflect.IsImageResourceWithMeta $resource }}
|
{{ if reflect.IsImageResourceWithMeta $resource }}
|
||||||
{{ $result = dict
|
{{ $result = dict
|
||||||
"Resource" $resource
|
"Resource" $resource
|
||||||
|
|||||||
Reference in New Issue
Block a user