Simplify img style builder

master
Will Faught 2 years ago
parent 385f2105ae
commit 7360c7d90b

@ -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 }}
<img {{ with $alt }} alt="{{ . }}" {{ end }} {{ with $class }} class="{{ . }}" {{ end }} crossorigin="{{ $crossorigin }}" {{ with $fetchpriority }} fetchpriority="{{ . }}" {{ end }} {{ with $intrinsicheight }} height="{{ . }}" {{ end }} loading="{{ $loading }}" referrerpolicy="{{ $referrerpolicy }}" src="{{ $src }}" {{ with $style }} style="{{ . | safeCSS }}" {{ end }} {{ with $title }} title="{{ . }}" {{ end }} {{ with $intrinsicwidth }} width="{{ . }}" {{ end }}>

Loading…
Cancel
Save