hugo-theme-termlite/layouts/partials/page/figures/fullwidth-image.html
Eryn Wells 05956b83b8 Make some improvements to the fullwidth-image partial
- Add some handling of SVGs so the template doesn't attempt to resize them.
- Include custom classes in the <figure class> attribute
- Do not link to SVG images
- Only include <img srcset> if there are multiple sized images. This mostly supports
  SVG figures where there's only ever one.
2024-12-31 09:37:19 -08:00

45 lines
1.4 KiB
HTML

{{- $image := .resource -}}
{{- $isSVG := strings.Contains $image.MediaType.SubType "svg" -}}
{{- $linksToFullSizeImage := and .linksToFullSizeImage (not $isSVG) -}}
{{- $resizedImages := dict "full" $image -}}
{{- if not $isSVG -}}
{{-
$resizedImages := dict
"full" ($image.Fit "2560x2560")
"half" ($image.Fit "1280x1280")
"quarter" ($image.Fit "640x640")
-}}
{{ end }}
{{- $classes := slice "figure" "figure--image" -}}
{{- if eq .size "main" -}}
{{ $classes = $classes | append "figure--main-column" }}
{{- end -}}
{{- with .class -}}
{{ $classes = $classes | append . }}
{{- end -}}
<figure class="{{ delimit $classes " " }}">
{{ if $linksToFullSizeImage -}}
<a href="{{ $image.RelPermalink }}">
{{- end -}}
<img
src="{{ (index $resizedImages "full").RelPermalink }}"
{{ if gt (len $resizedImages) 1 -}}
srcset="
{{ (index $resizedImages "full").RelPermalink }} 2560w,
{{ (index $resizedImages "half").RelPermalink }} 1280w,
{{ (index $resizedImages "quarter").RelPermalink }} 640w,
"
{{ end }}
{{ with $image.Params.alt | default $image.Title }} alt="{{ . }}"{{ end }}
{{ with $image.Title }} title="{{ . }}"{{ end }}>
{{ if .linksToFullSizeImage -}}
</a>
{{- end -}}
{{ if .shouldShowTitle }}
{{ partial "page/figures/caption.html" . }}
{{ end }}
</figure>