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
{{- $url := .url }}
{{- $title := .title }}
{{- $alt := .alt }}
2023-08-25 17:09:50 +00:00
{{- $effects := dict "border" false "lightbox" true "shadow" false }}
{{- 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" }}
2022-11-06 09:03:18 +00:00
{{- $dest_url := urls.Parse $url }}
2022-11-18 23:23:02 +00:00
{{- $dest_path := $dest_url.Path }}
2024-02-24 11:57:48 +00:00
{{- $image := "" }}
{{- if not $dest_url.IsAbs }}
2024-03-10 13:40:23 +00:00
{{- with or
($page.Resources.Get $dest_url.Path)
(resources.Get $dest_url.Path)
}}
2024-02-24 11:57:48 +00:00
{{- $image = . }}
2023-08-25 17:09:50 +00:00
{{- end }}
2024-02-24 11:57:48 +00:00
{{- with $image }}
{{- $url = $image.RelPermalink }}
{{- with $dest_url.RawQuery }}
{{- $url = printf "%s?%s" $url . }}
{{- end }}
2024-03-10 13:40:23 +00:00
{{- with $dest_url.Fragment }}
{{- $url = printf "%s#%s" $url . }}
{{- end }}
2024-02-24 11:57:48 +00:00
{{- 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 }}
2023-12-05 13:45:35 +00:00
{{- end }}
{{- end }}
2022-11-06 15:26:11 +00:00
{{- if $dest_url.RawQuery }}
2023-08-25 17:09:50 +00:00
{{- if $dest_url.Query.Has "classes" }}
{{- $classes := slice | append (split ($dest_url.Query.Get "classes") ",") }}
{{- 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 }}
{{- if $dest_url.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 }}
2023-08-25 17:09:50 +00:00
{{- $effects = merge $effects (dict "lightbox" (ne ($dest_url.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")) }}
{{- end }}
{{- end }}
{{- with $dest_url.Query.Get "height" }}
2023-08-25 21:51:18 +00:00
{{- $height = . }}
2023-08-25 17:09:50 +00:00
{{- end }}
{{- with $dest_url.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-03-10 13:40:23 +00:00
{{- $attributes := merge .attributes (dict "alt" $alt "src" $url "title" $title "loading" "lazy") }}
2023-07-27 14:14:55 +00:00
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $page) .id }}
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 }}