diff --git a/layouts/partials/shortcodes/image.html b/layouts/partials/shortcodes/image.html index 5d067c685d..ab0654867a 100644 --- a/layouts/partials/shortcodes/image.html +++ b/layouts/partials/shortcodes/image.html @@ -4,7 +4,6 @@ {{- $page = .context }} {{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'image' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#5180" $page.File.Filename }} {{- end }} -{{- $url := .url }} {{- $title := .title }} {{- $alt := .alt }} {{- $effects := dict "border" false "lazy" true "lightbox" true "shadow" false }} @@ -17,23 +16,20 @@ {{- $height := "auto" }} {{- $width := "auto" }} {{- $attributes := .attributes | default dict }} -{{- $dest_url := urls.Parse $url }} -{{- $dest_path := $dest_url.Path }} -{{- $image := "" }} -{{- if not $dest_url.IsAbs }} +{{- $u := urls.Parse .url }} +{{- $src := $u.String }} +{{- if not $u.IsAbs }} + {{- $path := strings.TrimPrefix "./" $u.Path }} {{- with or - ($page.Resources.Get $dest_url.Path) - (resources.Get $dest_url.Path) + ($page.Resources.Get $path) + (resources.Get $path) }} - {{- $image = . }} - {{- end }} - {{- with $image }} - {{- $url = $image.RelPermalink }} - {{- with $dest_url.RawQuery }} - {{- $url = printf "%s?%s" $url . }} + {{- $src = .RelPermalink }} + {{- with $u.RawQuery }} + {{- $src = printf "%s?%s" $src . }} {{- end }} - {{- with $dest_url.Fragment }} - {{- $url = printf "%s#%s" $url . }} + {{- with $u.Fragment }} + {{- $src = printf "%s#%s" $src . }} {{- end }} {{- else }} {{- if eq $page.Site.Params.image.errorlevel "warning" }} @@ -43,9 +39,9 @@ {{- end }} {{- end }} {{- end }} -{{- if $dest_url.RawQuery }} - {{- if $dest_url.Query.Has "classes" }} - {{- $classes := slice | append (split ($dest_url.Query.Get "classes") ",") }} +{{- if $u.RawQuery }} + {{- if $u.Query.Has "classes" }} + {{- $classes := slice | append (split ($u.Query.Get "classes") ",") }} {{- range $classes }} {{- $k := . }} {{- $v := true }} @@ -56,19 +52,19 @@ {{- $effects = merge $effects (dict $k $v) }} {{- end }} {{- end }} - {{- if $dest_url.Query.Has "featherlight" }} + {{- if $u.Query.Has "featherlight" }} {{- warnf "%q: DEPRECATED usage of 'featherlight' image CSS class found, use 'lightbox' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#5110" $page.File.Filename }} - {{- $effects = merge $effects (dict "lightbox" (ne ($dest_url.Query.Get "featherlight") "false")) }} + {{- $effects = merge $effects (dict "lightbox" (ne ($u.Query.Get "featherlight") "false")) }} {{- end }} {{- range $k, $v := $effects }} - {{- if $dest_url.Query.Has $k }} - {{- $effects = merge $effects (dict $k (ne ($dest_url.Query.Get $k) "false")) }} + {{- if $u.Query.Has $k }} + {{- $effects = merge $effects (dict $k (ne ($u.Query.Get $k) "false")) }} {{- end }} {{- end }} - {{- with $dest_url.Query.Get "height" }} + {{- with $u.Query.Get "height" }} {{- $height = . }} {{- end }} - {{- with $dest_url.Query.Get "width" }} + {{- with $u.Query.Get "width" }} {{- $width = . }} {{- end }} {{- end }} @@ -78,7 +74,7 @@ {{- $classes = $classes | append $c }} {{- end }} {{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $page) .id }} -{{- $attributes = merge $attributes (dict "alt" $alt "src" $url "title" ($title | transform.HTMLEscape)) }} +{{- $attributes = merge $attributes (dict "alt" $alt "src" $src "title" ($title | transform.HTMLEscape)) }} {{- if $effects.lazy }} {{- $attributes = merge $attributes (dict "loading" "lazy") }} {{- end }}