hackertours/layouts/_markup/render-image.html
Stefan Bethke f6a698a64b
All checks were successful
/ build (pull_request) Successful in 1m38s
/ accessibility (pull_request) Successful in 2m49s
Fix orientation of thumbnails
2026-10-17 10:55:54 +02:00

33 lines
1.5 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 and height as the browser shows the image, i.e. turned as its EXIF orientation
says (only JPEG and TIFF carry one). */ -}}
{{- $shown := cond (in (slice "jpeg" "tiff") .MediaType.SubType) (.Filter images.AutoOrient) . -}}
{{- $width = $shown.Width -}}
{{- $height = $shown.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 -}}