-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrender-image.html
18 lines (18 loc) · 1.21 KB
/
render-image.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{{ $image := .Page.Resources.GetMatch (printf "%s" (.Destination | safeURL)) }}
{{ $p := .Page }}
{{ $alt := (.PlainText | safeHTML) | default "picture" }}{{ $caption := "" }} {{ with .Title }}{{ $caption = . | safeHTML }}{{ end }}
{{ $iw := $image.Width }}{{ $ih := $image.Height }}{{ $ms := site.Params.Images.maxSize | default 1024}}
{{- if or (ge $iw $ms) (ge $ih $ms) -}}{{ $image = $image.Fit (print $ms "x" $ms ) }}{{- end -}}
{{ $srcset := slice }}{{ range site.Params.Images.setSizes -}}
{{ if lt (mul . 1.2) $iw -}}{{ $size := print . "x" .}}{{ $thumb := $image.Fit $size }}{{ $srcset = $srcset | append (printf ("%s %dw") $thumb.RelPermalink $thumb.Width ) }}{{- end }}
{{- end }}
{{ if .IsBlock }}
<figure class="dib {{ .Attributes.class }}">
<img loading=lazy decoding="async" importance=low src={{ $image.RelPermalink }}
{{ if gt (len $srcset) 0 }} sizes={{site.Params.Images.sizes}} {{ $sl := delimit $srcset ", "}} srcset="{{$sl}}" {{ end }} width={{ $image.Width }}
height={{ $image.Height}} alt={{ $alt }} />
{{ with $caption -}}<br /><figcaption class="mb3 i f6">» {{ $p.RenderString . }} «</figcaption>{{- end }}
</figure>
{{ else }}
<img src="{{ $image.RelPermalink }}" alt="{{ $alt }}" />
{{ end }}