Skip to content

Commit f13c478

Browse files
authored
fix: check if resource exists before accessing .RelPermalink (#1299)
* fix: check if resource exists before accessing `.RelPermalink` closes #1297 * Set default value of $result in `helper/image` to dict
1 parent bde2914 commit f13c478

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

layouts/_partials/helper/image.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/// Height: Image height
1010
/// Width: Image width
1111

12-
{{ $result := "" }}
12+
{{ $result := dict }}
1313

1414
{{ if .Image }}
1515
{{ $url := urls.Parse .Image }}
@@ -20,7 +20,6 @@
2020
{{ if not (in (slice "https" "http") $url.Scheme) }}
2121
{{/* Local image */}}
2222
{{ $resource = .Resources.Get (printf "%s" (.Image | safeURL)) }}
23-
{{ $permalink = $resource.RelPermalink }}
2423
{{ else }}
2524
{{/* Remote image */}}
2625
{{ with try (resources.GetRemote $url) }}
@@ -39,11 +38,12 @@
3938
{{ if and .Context.Site.Params.imageProcessing.autoOrient (reflect.IsImageResourceProcessable $resource) }}
4039
{{ $filter := images.AutoOrient }}
4140
{{ $resource = $resource | images.Filter $filter }}
42-
{{ if $local }}
43-
{{ $permalink = $resource.RelPermalink }}
44-
{{ end }}
4541
{{ end }}
46-
42+
43+
{{ if $local }}
44+
{{ $permalink = $resource.RelPermalink }}
45+
{{ end }}
46+
4747
{{ if reflect.IsImageResourceWithMeta $resource }}
4848
{{ $result = dict
4949
"Resource" $resource

0 commit comments

Comments
 (0)