Files
aether/layouts/shortcodes/smallimg.html
2021-02-04 00:51:38 -05:00

39 lines
2.2 KiB
HTML

<picture class="small-pic {{ if eq .Params.clear "true" -}} clear {{- end }}">
{{ $image := $.Page.Resources.GetMatch (.Get "src") }}
{{ if or (gt $image.Width 711) (and (isset .Params "width") (gt $image.Width (.Get "width"))) -}}
{{ $.Scratch.Set "imgwidth" "711" }}
{{ $.Scratch.Set "imgwidth_2" "1422" }}
{{ $.Scratch.Set "imgwidth_3" "2133" }}
{{ if and (isset .Params "width") (lt (.Get "width") 711) -}}
{{ $.Scratch.Set "imgwidth" (int (trim (.Get "width") "px")) }}
{{ $.Scratch.Set "imgwidth_2" (mul (int (trim (.Get "width") "px")) 2) }}
{{ $.Scratch.Set "imgwidth_3" (mul (int (trim (.Get "width") "px")) 3) }}
{{- end }}
{{ $resized := $image.Resize (printf "%dx Lanczos" ($.Scratch.Get "imgwidth")) }}
{{ $resized_2 := $image.Resize (printf "%dx Lanczos" ($.Scratch.Get "imgwidth_2")) }}
{{ $resized_3 := $image.Resize (printf "%dx Lanczos" ($.Scratch.Get "imgwidth_3")) }}
<source srcset="{{ $resized.Permalink }} 1x, {{ $resized_2.Permalink }} 2x, {{ $resized_3.Permalink }} 3x">
<img src="{{ $resized.Permalink }}" class="small-img {{ if isset .Params "smartfloat" -}}
{{- if eq .Params.smartfloat "left" -}}
smartfloat-left
{{- else if eq .Params.smartfloat "right" -}}
smartfloat-right
{{- end -}}
{{- end }}"
{{- with .Get "alt" }} alt="{{ . }}" {{ end -}}
{{- with .Get "width" }} style="width: {{ . }};" {{- end -}}
/>
{{ else }}
<source srcset="{{ $image.Permalink }}">
<img src="{{ $image.Permalink }}" class="small-img {{ if isset .Params "smartfloat" -}}
{{- if eq .Params.smartfloat "left" -}}
smartfloat-left
{{- else if eq .Params.smartfloat "right" -}}
smartfloat-right
{{- end -}}
{{- end }}"
{{- with .Get "alt" }} alt="{{ . }}" {{ end -}}
{{- with .Get "width" }} style="width: {{ . }};" {{- end -}}
/>
{{- end }}
</picture>