Verbeter weergave afbeeldingen en ondersteun webp
This commit is contained in:
parent
6659fc3378
commit
4efe0a3612
50 changed files with 95 additions and 48 deletions
33
themes/nluug/layouts/partials/show-image.html
Normal file
33
themes/nluug/layouts/partials/show-image.html
Normal file
|
@ -0,0 +1,33 @@
|
|||
<figure>
|
||||
<picture>
|
||||
{{ $isJPG := eq (path.Ext .image) ".jpg" }}
|
||||
{{ $isPNG := eq (path.Ext .image) ".png" }}
|
||||
|
||||
{{ if ($isJPG) -}}
|
||||
{{ $webpPath:= replace .image ".jpg" ".webp" }}
|
||||
{{ $webpPathStatic:= printf "static/%s" $webpPath }}
|
||||
|
||||
{{ if (fileExists $webpPathStatic) -}}
|
||||
<source srcset="{{ $webpPath | safeURL }}" type="image/webp">
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{ if ($isPNG) -}}
|
||||
{{ $webpPath:= replace .image ".png" ".webp" }}
|
||||
{{ $webpPathStatic:= printf "static/%s" $webpPath }}
|
||||
|
||||
{{ if (fileExists $webpPathStatic) -}}
|
||||
<source srcset="{{ $webpPath | safeURL }}" type="image/webp">
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{ $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 }}">
|
||||
{{ if .link }}</a>{{ end }}
|
||||
</picture>
|
||||
{{ if .figcaption }}
|
||||
<figcaption>
|
||||
<small><strong>{{ .figcaption }}</strong></small>
|
||||
</figcaption>
|
||||
</figure>
|
||||
{{ end }}
|
Loading…
Add table
Add a link
Reference in a new issue