2024-04-27 12:38:19 +00:00
{{- /* based on Hugo 0.125.5 render-image.html */}}
2023-07-27 14:14:55 +00:00
{{- $page := .page }}
{{- if and (not $page) .context }}
{{- $page = .context }}
2023-11-20 23:53:33 +00:00
{{- 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 }}
2023-07-27 14:14:55 +00:00
{{- end }}
2022-11-06 09:03:18 +00:00
{{- $title := .title }}
{{- $alt := .alt }}
2024-03-16 09:00:40 +00:00
{{- $effects := dict "border" false "lazy" true "lightbox" true "shadow" false }}
2023-08-25 17:09:50 +00:00
{{- if $page.Site.Params.imageeffects }}
{{- $effects = merge $effects $page.Site.Params.imageeffects }}
{{- end }}
{{- if $page.Params.imageEffects }}
{{- $effects = merge $effects $page.Params.imageEffects }}
{{- end }}
2022-11-06 15:26:11 +00:00
{{- $height := "auto" }}
{{- $width := "auto" }}
2024-04-07 11:45:16 +00:00
{{- $attributes := .attributes | default dict }}
2024-05-28 19:48:37 +00:00
{{- $u := urls.Parse .url }}
{{- $src := $u.String }}
{{- if not $u.IsAbs }}
{{- $path := strings.TrimPrefix "./" $u.Path }}
2024-03-10 13:40:23 +00:00
{{- with or
2024-05-28 19:48:37 +00:00
($page.Resources.Get $path)
(resources.Get $path)
2024-03-10 13:40:23 +00:00
}}
2024-05-28 19:48:37 +00:00
{{- $src = .RelPermalink }}
{{- with $u.RawQuery }}
{{- $src = printf "%s?%s" $src . }}
2024-02-24 11:57:48 +00:00
{{- end }}
2024-05-28 19:48:37 +00:00
{{- with $u.Fragment }}
{{- $src = printf "%s#%s" $src . }}
2024-03-10 13:40:23 +00:00
{{- end }}
2024-02-24 11:57:48 +00:00
{{- else }}
2024-08-02 08:32:31 +00:00
{{- $errorlevel := or $page.Params.image.errorlevel $page.Site.Params.image.errorlevel }}
{{- if eq $errorlevel "warning" }}
2024-02-24 11:57:48 +00:00
{{- warnf "%q: image '%s' is not a resource but linked anyways" $page.File.Filename .url }}
2024-08-02 08:32:31 +00:00
{{- else if eq $errorlevel "error" }}
2024-02-24 11:57:48 +00:00
{{- errorf "%q: image '%s' is not a resource" $page.File.Filename .url }}
{{- end }}
2023-12-05 13:45:35 +00:00
{{- end }}
{{- end }}
2024-05-28 19:48:37 +00:00
{{- if $u.RawQuery }}
{{- if $u.Query.Has "classes" }}
{{- $classes := slice | append (split ($u.Query.Get "classes") ",") }}
2023-08-25 17:09:50 +00:00
{{- range $classes }}
{{- $k := . }}
{{- $v := true }}
{{- if strings.HasPrefix $k "no" }}
{{- $k := strings.TrimPrefix "no" $k }}
{{- $v := false }}
{{- end }}
{{- $effects = merge $effects (dict $k $v) }}
{{- end }}
{{- end }}
2024-05-28 19:48:37 +00:00
{{- if $u.Query.Has "featherlight" }}
2023-11-20 23:53:33 +00:00
{{- 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 }}
2024-05-28 19:48:37 +00:00
{{- $effects = merge $effects (dict "lightbox" (ne ($u.Query.Get "featherlight") "false")) }}
2023-08-25 17:09:50 +00:00
{{- end }}
{{- range $k, $v := $effects }}
2024-05-28 19:48:37 +00:00
{{- if $u.Query.Has $k }}
{{- $effects = merge $effects (dict $k (ne ($u.Query.Get $k) "false")) }}
2023-08-25 17:09:50 +00:00
{{- end }}
{{- end }}
2024-05-28 19:48:37 +00:00
{{- with $u.Query.Get "height" }}
2023-08-25 21:51:18 +00:00
{{- $height = . }}
2023-08-25 17:09:50 +00:00
{{- end }}
2024-05-28 19:48:37 +00:00
{{- with $u.Query.Get "width" }}
2023-08-25 21:51:18 +00:00
{{- $width = . }}
2023-08-25 17:09:50 +00:00
{{- end }}
{{- end }}
{{- $classes := slice }}
{{- range $k, $v := $effects }}
{{- $c := printf "%s%s" (cond $v "" "no") $k }}
{{- $classes = $classes | append $c }}
2022-11-06 15:26:11 +00:00
{{- end }}
2024-08-29 10:28:34 +00:00
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "_relearn/makeRandomMd5.gotmpl" $page) .id }}
2024-05-28 19:48:37 +00:00
{{- $attributes = merge $attributes (dict "alt" $alt "src" $src "title" ($title | transform.HTMLEscape)) }}
2024-03-16 09:00:40 +00:00
{{- if $effects.lazy }}
{{- $attributes = merge $attributes (dict "loading" "lazy") }}
{{- end }}
2023-08-25 21:51:18 +00:00
{{- if $effects.lightbox -}}
2023-09-23 08:18:31 +00:00
< a href = "#R-image-{{ $id }}" class = "lightbox-link" >
2024-03-10 13:40:23 +00:00
{{- end }}
{{- $attributes_figure := merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) "figure-image" $classes) " ")) }}
{{- $attributes_figure = merge $attributes_figure (dict "style" (delimit (slice (index $attributes "style") (printf "height: %s; width: %s;" $height $width)) " ")) -}}
< img
{{- range $k, $v := $attributes_figure }}
{{- if $v }}
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
{{- end }}
{{- end }}>
2023-08-25 21:51:18 +00:00
{{- if $effects.lightbox -}}
2022-11-06 15:26:11 +00:00
< / a >
2024-03-10 13:40:23 +00:00
< a href = "javascript:history.back();" class = "lightbox-back" id = "R-image-{{ $id }}" >
{{- $attributes_lightbox := merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) "lightbox-image" $classes) " ")) -}}
< img
{{- range $k, $v := $attributes_lightbox }}
{{- if $v }}
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
{{- end }}
{{- end }}>< / a >
2022-11-06 15:26:11 +00:00
{{- end }}