From f13c4787187896a5e0b831a04936caaf0ddc6467 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 6 Mar 2026 00:13:13 +0100 Subject: [PATCH] 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 --- layouts/_partials/helper/image.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/layouts/_partials/helper/image.html b/layouts/_partials/helper/image.html index 36a7480..1ebc586 100644 --- a/layouts/_partials/helper/image.html +++ b/layouts/_partials/helper/image.html @@ -9,7 +9,7 @@ /// Height: Image height /// Width: Image width -{{ $result := "" }} +{{ $result := dict }} {{ if .Image }} {{ $url := urls.Parse .Image }} @@ -20,7 +20,6 @@ {{ 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) }} @@ -39,11 +38,12 @@ {{ if and .Context.Site.Params.imageProcessing.autoOrient (reflect.IsImageResourceProcessable $resource) }} {{ $filter := images.AutoOrient }} {{ $resource = $resource | images.Filter $filter }} - {{ if $local }} - {{ $permalink = $resource.RelPermalink }} - {{ end }} {{ end }} - + + {{ if $local }} + {{ $permalink = $resource.RelPermalink }} + {{ end }} + {{ if reflect.IsImageResourceWithMeta $resource }} {{ $result = dict "Resource" $resource