From e83ba90c62ea11a57f55defb9c0561eb70686ec8 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Thu, 3 Nov 2022 09:16:13 -0700 Subject: [PATCH] Update the photo_thumbnail template to return the thumbnail itself, unmodified, if no changes are required --- layouts/partials/images/photo_thumbnail.html | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/layouts/partials/images/photo_thumbnail.html b/layouts/partials/images/photo_thumbnail.html index 16940a3..7c5836e 100644 --- a/layouts/partials/images/photo_thumbnail.html +++ b/layouts/partials/images/photo_thumbnail.html @@ -1,8 +1,23 @@ {{- $thumbnailResource := .Resources.GetMatch (index .Page.Params "thumbnail") | default (index (.Page.Resources.ByType "image") 0) -}} {{- if not $thumbnailResource -}} - {{- errorf "No thumbnail available for %s" .Page.Permalink }} + {{- errorf "No thumbnail available for %s" .Page.Permalink }} {{- end -}} -{{- $orientation := partial "images/orientation_angle.html" $thumbnailResource -}} -{{- $thumbnail := $thumbnailResource.Fit (printf "%dx%d r%d" .Width .Height (sub 360 $orientation)) -}} + +{{ $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 }}