hackertours/layouts/_markup/render-image.html
2026-10-17 10:18:01 +02:00

30 lines
1.3 KiB
HTML

{{- /*
Content images. The Markdown title ("![alt](src "© Credit")") is the photo credit; it is shown
as a caption instead of a tooltip, so that it is available on touch devices and to screen readers.
An image on its own line becomes a figure; images sharing a paragraph get an inline credit.
*/ -}}
{{- $src := .Destination -}}
{{- $width := 0 -}}
{{- $height := 0 -}}
{{- with or (.PageInner.Resources.Get (strings.TrimPrefix "./" .Destination)) (resources.Get .Destination) -}}
{{- $src = .RelPermalink -}}
{{- if and (eq .ResourceType "image") (ne .MediaType.SubType "svg") -}}
{{- $width = .Width -}}
{{- $height = .Height -}}
{{- end -}}
{{- end -}}
{{- /* A title that only repeats the alt text is not a credit. */ -}}
{{- $credit := cond (eq .Title .PlainText) "" .Title -}}
{{- $img := printf `<img src="%s" alt="%s"%s>` (htmlEscape $src) (htmlEscape .PlainText) (cond (gt $width 0) (printf ` width="%d" height="%d"` $width $height) "") -}}
{{- if .IsBlock -}}
<figure class="content-image">
{{ $img | safeHTML }}
{{- with $credit }}
<figcaption class="content-image__credit">{{ . }}</figcaption>
{{- end }}
</figure>
{{- else if $credit -}}
<span class="content-image">{{ $img | safeHTML }}<span class="content-image__credit">{{ $credit }}</span></span>
{{- else -}}
{{ $img | safeHTML }}
{{- end -}}