7
0
Fork 0

Gehele figure-tag linken ipv alleen img, anders worden alsnog jpg/png geladen ipv webp

This commit is contained in:
Michael Boelen 2023-05-24 02:47:20 +02:00
parent 5172b4f62f
commit a7092d3990

View file

@ -1,33 +1,34 @@
{{ if .link }}<a href="{{ .link }}">{{ end }}
<figure> <figure>
<picture> <picture>
{{ $isJPG := eq (path.Ext .image) ".jpg" }} {{ $isJPG := eq (path.Ext .image) ".jpg" }}
{{ $isPNG := eq (path.Ext .image) ".png" }} {{ $isPNG := eq (path.Ext .image) ".png" }}
{{ if ($isJPG) -}} {{ if ($isJPG) -}}
{{ $webpPath:= replace .image ".jpg" ".webp" }} {{ $webpPath:= replace .image ".jpg" ".webp" }}
{{ $webpPathStatic:= printf "static/%s" $webpPath }} {{ $webpPathStatic:= printf "static/%s" $webpPath }}
{{ if (fileExists $webpPathStatic) -}} {{ if (fileExists $webpPathStatic) -}}
<source srcset="{{ $webpPath | safeURL }}" type="image/webp"> <source srcset="{{ $webpPath | safeURL }}" type="image/webp">
{{- end }}
{{- end }} {{- end }}
{{- end }}
{{ if ($isPNG) -}} {{ if ($isPNG) -}}
{{ $webpPath:= replace .image ".png" ".webp" }} {{ $webpPath:= replace .image ".png" ".webp" }}
{{ $webpPathStatic:= printf "static/%s" $webpPath }} {{ $webpPathStatic:= printf "static/%s" $webpPath }}
{{ if (fileExists $webpPathStatic) -}} {{ if (fileExists $webpPathStatic) -}}
<source srcset="{{ $webpPath | safeURL }}" type="image/webp"> <source srcset="{{ $webpPath | safeURL }}" type="image/webp">
{{- end }}
{{- end }} {{- end }}
{{- end }} {{ $img := imageConfig (add "/static" (.image | safeURL)) }}
{{ $img := imageConfig (add "/static" (.image | safeURL)) }}
{{ if .link }}<a href="{{ .link }}">{{ end }} <img src="{{ .image | safeURL }}" alt="{{ .alt }}" loading="lazy" decoding="async" width="{{ $img.Width }}" height="{{ $img.Height }}">
<img src="{{ .image | safeURL }}" alt="{{ .alt }}" loading="lazy" decoding="async" width="{{ $img.Width }}" height="{{ $img.Height }}"> </picture>
{{ if .link }}</a>{{ end }} {{ if .figcaption }}
</picture> <figcaption>
{{ if .figcaption }} <small><strong>{{ .figcaption }}</strong></small>
<figcaption> </figcaption>
<small><strong>{{ .figcaption }}</strong></small> {{ end }}
</figcaption>
</figure> </figure>
{{ end }} {{ if .link }}</a>{{ end }}