2024-04-27 14:38:19 +02:00
|
|
|
{{- /* based on Hugo 0.125.5 render-image.html */}}
|
2023-07-27 16:14:55 +02:00
|
|
|
{{- $page := .page }}
|
|
|
|
{{- if and (not $page) .context }}
|
|
|
|
{{- $page = .context }}
|
2025-01-31 14:57:10 +01:00
|
|
|
{{- $filepath := "[virtual file]" }}{{ with and $page $page.File $page.File.Filename }}{{ $filepath = . }}{{ end }}
|
|
|
|
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'image' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/5/#5-18-0" $filepath }}
|
2023-07-27 16:14:55 +02:00
|
|
|
{{- end }}
|
2022-11-06 10:03:18 +01:00
|
|
|
{{- $title := .title }}
|
|
|
|
{{- $alt := .alt }}
|
2024-04-07 13:45:16 +02:00
|
|
|
{{- $attributes := .attributes | default dict }}
|
2024-05-28 21:48:37 +02:00
|
|
|
{{- $u := urls.Parse .url }}
|
|
|
|
{{- $src := $u.String }}
|
2025-01-29 18:03:23 +01:00
|
|
|
{{- if $u.IsAbs }}
|
|
|
|
{{- partialCached "_relearn/urlExists.gotmpl" (dict "url" .url "page" $page "type" "image") $u.String }}
|
|
|
|
{{- else }}
|
2025-02-07 14:28:26 +01:00
|
|
|
{{- $linkObject := partial "_relearn/linkObject.gotmpl" (dict "url" .url "page" $page "searchPage" false) }}
|
|
|
|
{{- if $linkObject }}
|
|
|
|
{{- $src = partial "_relearn/decoratedLink.gotmpl" (dict "url" .url "page" $page "linkObject" $linkObject "param" "image") }}
|
2024-02-24 12:57:48 +01:00
|
|
|
{{- else }}
|
2025-01-31 14:57:10 +01:00
|
|
|
{{- $filepath := "[virtual file]" }}{{ with and $page $page.File $page.File.Filename }}{{ $filepath = . }}{{ end }}
|
|
|
|
{{- $msg := printf "%q: image '%s' is not a resource" $filepath .url }}
|
2025-01-29 22:17:39 +01:00
|
|
|
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .url "page" $page "param" "image" "msg" $msg) }}
|
2023-12-05 14:45:35 +01:00
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2024-08-29 12:28:34 +02:00
|
|
|
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "_relearn/makeRandomMd5.gotmpl" $page) .id }}
|
2025-02-07 14:28:26 +01:00
|
|
|
{{- $attributes = merge $attributes (partial "_relearn/imageAttributes.gotmpl" (dict "url" $src "page" $page)) }}
|
|
|
|
{{- $attributes = merge $attributes (dict "alt" $alt "title" ($title | transform.HTMLEscape)) }}
|
|
|
|
{{- $classes := split $attributes.class " " }}
|
|
|
|
{{- $isLightbox := in $classes "lightbox" }}
|
|
|
|
{{- if $isLightbox -}}
|
2023-09-23 10:18:31 +02:00
|
|
|
<a href="#R-image-{{ $id }}" class="lightbox-link">
|
2024-03-10 14:40:23 +01:00
|
|
|
{{- end }}
|
2025-02-07 14:28:26 +01:00
|
|
|
{{- $attributes_figure := $attributes }}
|
|
|
|
{{- $attributes_figure = merge $attributes_figure (dict "class" (delimit ((split $attributes_figure.class " ") | append "figure-image") " ")) }}
|
|
|
|
{{- $attributes_figure = merge $attributes_figure (dict "style" (index $attributes_figure "style")) -}}
|
2024-03-10 14:40:23 +01:00
|
|
|
<img
|
|
|
|
{{- range $k, $v := $attributes_figure }}
|
|
|
|
{{- if $v }}
|
2025-02-07 14:28:26 +01:00
|
|
|
{{- if eq (printf "%T" $v) "bool" }}
|
|
|
|
{{- printf " %s" $k | safeHTMLAttr }}
|
|
|
|
{{- else }}
|
|
|
|
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
|
|
|
|
{{- end }}
|
2024-03-10 14:40:23 +01:00
|
|
|
{{- end }}
|
|
|
|
{{- end }}>
|
2025-02-07 14:28:26 +01:00
|
|
|
{{- if $isLightbox -}}
|
2022-11-06 16:26:11 +01:00
|
|
|
</a>
|
2024-03-10 14:40:23 +01:00
|
|
|
<a href="javascript:history.back();" class="lightbox-back" id="R-image-{{ $id }}">
|
2025-02-07 14:28:26 +01:00
|
|
|
{{- $attributes_lightbox := $attributes }}
|
|
|
|
{{- $attributes_lightbox = merge $attributes_lightbox (dict "class" (delimit ((split $attributes_lightbox.class " ") | append "lightbox-image") " ")) }}
|
|
|
|
{{- $attributes_lightbox = merge $attributes_lightbox (dict "style" "") -}}
|
2024-03-10 14:40:23 +01:00
|
|
|
<img
|
|
|
|
{{- range $k, $v := $attributes_lightbox }}
|
|
|
|
{{- if $v }}
|
2025-02-07 14:28:26 +01:00
|
|
|
{{- if eq (printf "%T" $v) "bool" }}
|
|
|
|
{{- printf " %s" $k | safeHTMLAttr }}
|
|
|
|
{{- else }}
|
|
|
|
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
|
|
|
|
{{- end }}
|
2024-03-10 14:40:23 +01:00
|
|
|
{{- end }}
|
|
|
|
{{- end }}></a>
|
2022-11-06 16:26:11 +01:00
|
|
|
{{- end }}
|