Simplify img style builder

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

@ -65,44 +65,30 @@
{{ $height = "auto" }} {{ $height = "auto" }}
{{ end }} {{ end }}
{{ $styles := slice }}
{{ if $height }} {{ if $height }}
{{ with printf "height: %v" $height }} {{ $styles = $styles | append (print "height: " $height) }}
{{ if $style }}
{{ $style = printf "%v; %v" $style . }}
{{ else }}
{{ $style = . }}
{{ end }}
{{ end }}
{{ end }} {{ end }}
{{ if $maxheight }} {{ if $maxheight }}
{{ with printf "max-height: %v" $maxheight }} {{ $styles = $styles | append (print "max-height: " $maxheight) }}
{{ if $style }}
{{ $style = printf "%v; %v" $style . }}
{{ else }}
{{ $style = . }}
{{ end }}
{{ end }}
{{ end }} {{ end }}
{{ if $maxwidth }} {{ if $maxwidth }}
{{ with printf "max-width: %v" $maxwidth }} {{ $styles = $styles | append (print "max-width: " $maxwidth) }}
{{ if $style }}
{{ $style = printf "%v; %v" $style . }}
{{ else }}
{{ $style = . }}
{{ end }}
{{ end }}
{{ end }} {{ end }}
{{ if $width }} {{ if $width }}
{{ with printf "width: %v" $width }} {{ $styles = $styles | append (print "width: " $width) }}
{{ end }}
{{ $styles = delimit $styles "; " }}
{{ if $style }} {{ if $style }}
{{ $style = printf "%v; %v" $style . }} {{ $style = print $style "; " $styles }}
{{ else }} {{ else }}
{{ $style = . }} {{ $style = $styles }}
{{ end }}
{{ end }}
{{ end }} {{ 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 }}> <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