image: adjust to Hugo 0.123 #777

This commit is contained in:
Sören Weber 2024-02-22 23:00:38 +01:00
parent 065d27f8a2
commit e516a1bdd1
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
2 changed files with 16 additions and 18 deletions

View file

@ -17,25 +17,23 @@
{{- $width := "auto" }} {{- $width := "auto" }}
{{- $dest_url := urls.Parse $url }} {{- $dest_url := urls.Parse $url }}
{{- $dest_path := $dest_url.Path }} {{- $dest_path := $dest_url.Path }}
{{- $image := $page.Resources.GetMatch (path.Clean $dest_url.Path) }} {{- $image := "" }}
{{- if not $image }} {{- if not $dest_url.IsAbs }}
{{- $image = .Resources.GetMatch $dest_path }} {{- with or ($page.Resources.Get $dest_url.Path) (resources.Get $dest_url.Path) }}
{{- end }} {{- $image = . }}
{{- 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 }} {{- end }}
{{- end }} {{- with $image }}
{{- if and (not $image) (not $dest_url.IsAbs) }} {{- $url = $image.RelPermalink }}
{{- with $dest_url.RawQuery }}
{{- $url = printf "%s?%s" $url . }}
{{- end }}
{{- else }}
{{- if eq $page.Site.Params.image.errorlevel "warning" }} {{- if eq $page.Site.Params.image.errorlevel "warning" }}
{{- warnf "%q: image '%s' is not a resource but linked anyways" $page.File.Filename .url }} {{- warnf "%q: image '%s' is not a resource but linked anyways" $page.File.Filename .url }}
{{- else if eq $page.Site.Params.image.errorlevel "error" }} {{- else if eq $page.Site.Params.image.errorlevel "error" }}
{{- errorf "%q: image '%s' is not a resource" $page.File.Filename .url }} {{- errorf "%q: image '%s' is not a resource" $page.File.Filename .url }}
{{- end }} {{- end }}
{{- end }}
{{- end }} {{- end }}
{{- if $dest_url.RawQuery }} {{- if $dest_url.RawQuery }}
{{- if $dest_url.Query.Has "classes" }} {{- if $dest_url.Query.Has "classes" }}

View file

@ -16,7 +16,6 @@
{{- $u := urls.Parse $url }} {{- $u := urls.Parse $url }}
{{- $href := $u.String }} {{- $href := $u.String }}
{{- $path := $u.Path }} {{- $path := $u.Path }}
{{- $linkPage := "" }}
{{- if $u.IsAbs }} {{- if $u.IsAbs }}
{{- $target = "_blank" }} {{- $target = "_blank" }}
{{- if isset $page.Site.Params "externallinktarget" }} {{- if isset $page.Site.Params "externallinktarget" }}
@ -24,6 +23,7 @@
{{- end }} {{- end }}
{{- $attributes = $attributes | merge (dict "target" $target) }} {{- $attributes = $attributes | merge (dict "target" $target) }}
{{- else }} {{- else }}
{{- $linkPage := "" }}
{{- if $path }} {{- if $path }}
{{- with or {{- with or
($page.Page.GetPage $path) ($page.Page.GetPage $path)