From 4e5fe8d90a9d135c36de5b25f6a3fff592d5d6a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Thu, 22 Feb 2024 23:12:53 +0100 Subject: [PATCH] link: backout #777 --- layouts/partials/shortcodes/image.html | 32 ++++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/layouts/partials/shortcodes/image.html b/layouts/partials/shortcodes/image.html index ff3fd920f5..642d6f3814 100644 --- a/layouts/partials/shortcodes/image.html +++ b/layouts/partials/shortcodes/image.html @@ -17,22 +17,24 @@ {{- $width := "auto" }} {{- $dest_url := urls.Parse $url }} {{- $dest_path := $dest_url.Path }} -{{- $image := "" }} -{{- if not $dest_url.IsAbs }} - {{- with or ($page.Resources.Get $dest_url.Path) (resources.Get $dest_url.Path) }} - {{- $image = . }} +{{- $image := $page.Resources.GetMatch (path.Clean $dest_url.Path) }} +{{- if not $image }} + {{- $image = .Resources.GetMatch $dest_path }} +{{- end }} +{{- if not $image }} + {{- $image = .Resources.GetRemote $url }} +{{- end }} +{{- if $image }} + {{- $url = $image.RelPermalink }} + {{- if $dest_url.RawQuery }} + {{- $url = printf "%s?%s" $url $dest_url.RawQuery }} {{- end }} - {{- with $image }} - {{- $url = $image.RelPermalink }} - {{- with $dest_url.RawQuery }} - {{- $url = printf "%s?%s" $url . }} - {{- end }} - {{- else }} - {{- if eq $page.Site.Params.image.errorlevel "warning" }} - {{- warnf "%q: image '%s' is not a resource but linked anyways" $page.File.Filename .url }} - {{- else if eq $page.Site.Params.image.errorlevel "error" }} - {{- errorf "%q: image '%s' is not a resource" $page.File.Filename .url }} - {{- end }} +{{- end }} +{{- if and (not $image) (not $dest_url.IsAbs) }} + {{- if eq $page.Site.Params.image.errorlevel "warning" }} + {{- warnf "%q: image '%s' is not a resource but linked anyways" $page.File.Filename .url }} + {{- else if eq $page.Site.Params.image.errorlevel "error" }} + {{- errorf "%q: image '%s' is not a resource" $page.File.Filename .url }} {{- end }} {{- end }} {{- if $dest_url.RawQuery }}