From 7360c7d90b5fdd1bd98879db6ba3ec121799c588 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Wed, 1 Mar 2023 21:31:02 -0800 Subject: [PATCH] Simplify img style builder --- layouts/partials/paige/img.html | 42 +++++++++++---------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/layouts/partials/paige/img.html b/layouts/partials/paige/img.html index 0066ecaf..651bc5a7 100644 --- a/layouts/partials/paige/img.html +++ b/layouts/partials/paige/img.html @@ -65,44 +65,30 @@ {{ $height = "auto" }} {{ end }} +{{ $styles := slice }} + {{ if $height }} - {{ with printf "height: %v" $height }} - {{ if $style }} - {{ $style = printf "%v; %v" $style . }} - {{ else }} - {{ $style = . }} - {{ end }} - {{ end }} + {{ $styles = $styles | append (print "height: " $height) }} {{ end }} {{ if $maxheight }} - {{ with printf "max-height: %v" $maxheight }} - {{ if $style }} - {{ $style = printf "%v; %v" $style . }} - {{ else }} - {{ $style = . }} - {{ end }} - {{ end }} + {{ $styles = $styles | append (print "max-height: " $maxheight) }} {{ end }} {{ if $maxwidth }} - {{ with printf "max-width: %v" $maxwidth }} - {{ if $style }} - {{ $style = printf "%v; %v" $style . }} - {{ else }} - {{ $style = . }} - {{ end }} - {{ end }} + {{ $styles = $styles | append (print "max-width: " $maxwidth) }} {{ end }} {{ if $width }} - {{ with printf "width: %v" $width }} - {{ if $style }} - {{ $style = printf "%v; %v" $style . }} - {{ else }} - {{ $style = . }} - {{ end }} - {{ end }} + {{ $styles = $styles | append (print "width: " $width) }} +{{ end }} + +{{ $styles = delimit $styles "; " }} + +{{ if $style }} + {{ $style = print $style "; " $styles }} +{{ else }} + {{ $style = $styles }} {{ end }} {{ . }}