2023-07-27 14:14:55 +00:00
{{- $page := .page }}
{{- if and (not $page) .context }}
{{- $page = .context }}
2023-10-27 22:36:30 +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 }}
2023-07-27 14:14:55 +00:00
{{- $image := $page.Resources.GetMatch $dest_path }}
2022-11-18 23:23:02 +00:00
{{- if not $image }}
2023-08-25 17:09:50 +00:00
{{- $image = .Resources.GetMatch $dest_path }}
2022-11-18 23:23:02 +00:00
{{- end }}
{{- if not $image }}
2023-08-25 17:09:50 +00:00
{{- $image = .Resources.GetRemote $url }}
2022-11-06 15:26:11 +00:00
{{- end }}
2022-11-06 09:03:18 +00:00
{{- if $image }}
2023-08-25 17:09:50 +00:00
{{- $url = $image.RelPermalink }}
{{- if $dest_url.RawQuery }}
{{- $url = printf "%s?%s" $url $dest_url.RawQuery }}
{{- end }}
2022-11-06 15:26:11 +00:00
{{- end }}
{{- 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-10-27 22:36:30 +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 }}
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" >
2023-08-25 21:51:18 +00:00
{{- end -}}
< img src = "{{ $url | safeURL }}" alt = "{{ $alt }}" { { with $ title } } title = "{{ . }}" { { end } } class = "figure-image {{ delimit $classes " " } } " style = "height: {{ $height }}; width: {{ $width }};" loading = "lazy" >
{{- if $effects.lightbox -}}
2022-11-06 15:26:11 +00:00
< / a >
2023-09-23 08:18:31 +00:00
< a href = "javascript:history.back();" class = "lightbox-back" id = "R-image-{{ $id }}" > < img src = "{{ $url | safeURL }}" alt = "{{ $alt }}" { { with $ title } } title = "{{ . }}" { { end } } class = "lightbox-image {{ delimit $classes " " } } " loading = "lazy" > < / a >
2022-11-06 15:26:11 +00:00
{{- end }}