erynwells.me/layouts/partials/photos/thumbnail.html
Eryn Wells c256179803 Expand the width and heigh argument checks
They are more readable when they are not squashed on one line.
2023-04-06 08:45:15 -07:00

34 lines
1.1 KiB
HTML

{{- $thumbnailResource := .Page.Resources.GetMatch
(index .Page.Params "thumbnail" | default "[tT]humbnail*")
| default (index (.Page.Resources.ByType "image") 0) -}}
{{- if not $thumbnailResource -}}
{{- errorf "No thumbnail available for %s" .Page.Permalink }}
{{- end -}}
{{ $orientation := partial "images/orientation_angle.html" $thumbnailResource }}
{{ $targetWidth := 0 }}
{{ if isset . "Width" }}
{{ $targetWidth = .Width }}
{{ else }}
{{ $targetWidth = $thumbnailResource.Width }}
{{ end }}
{{ $targetHeight := 0 }}
{{ if isset . "Height" }}
{{ $targetHeight = .Height }}
{{ else }}
{{ $targetHeight = $thumbnailResource.Height }}
{{ end }}
{{ $thumbnail := false }}
{{ if not (and (eq $orientation 0)
(eq $targetWidth $thumbnailResource.Width)
(eq $targetHeight $thumbnailResource.Height)) }}
{{ $thumbnail = $thumbnailResource.Fit (printf "%dx%d r%d" $targetWidth $targetHeight (sub 360 $orientation)) }}
{{ else }}
{{ $thumbnail = $thumbnailResource }}
{{ end }}
{{ return $thumbnail }}