add avif/webp support
This commit is contained in:
49
layouts/_default/_markup/render-image.html
Normal file
49
layouts/_default/_markup/render-image.html
Normal file
@ -0,0 +1,49 @@
|
||||
<center>
|
||||
<picture>
|
||||
{{ $isJPG := eq (path.Ext .Destination) ".jpg" }}
|
||||
{{ $isPNG := eq (path.Ext .Destination) ".png" }}
|
||||
|
||||
{{ if ($isJPG) -}}
|
||||
{{ $avifPath:= replace .Destination ".jpg" ".avif" }}
|
||||
{{ $avifPathStatic:= printf "static/%s" $avifPath }}
|
||||
|
||||
{{ if (fileExists $avifPathStatic) -}}
|
||||
<source srcset="{{ $avifPath | safeURL }}" type="image/avif" >
|
||||
{{- end }}
|
||||
|
||||
{{ $webpPath:= replace .Destination ".jpg" ".webp" }}
|
||||
{{ $webpPathStatic:= printf "static/%s" $webpPath }}
|
||||
|
||||
{{ if (fileExists $webpPathStatic) -}}
|
||||
<source srcset="{{ $webpPath | safeURL }}" type="image/webp" >
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{ if ($isPNG) -}}
|
||||
{{ $avifPath:= replace .Destination ".png" ".avif" }}
|
||||
{{ $avifPathStatic:= printf "static/%s" $avifPath }}
|
||||
|
||||
{{ if (fileExists $avifPathStatic) -}}
|
||||
<source srcset="{{ $avifPath | safeURL }}" type="image/avif" >
|
||||
{{- end }}
|
||||
|
||||
{{ $webpPath:= replace .Destination ".png" ".webp" }}
|
||||
{{ $webpPathStatic:= printf "static/%s" $webpPath }}
|
||||
|
||||
{{ if (fileExists $webpPathStatic) -}}
|
||||
<source srcset="{{ $webpPath | safeURL }}" type="image/webp" >
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{ $img := imageConfig (add "/static" (.Destination | safeURL)) }}
|
||||
|
||||
<img
|
||||
src="{{ .Destination | safeURL }}"
|
||||
alt="{{ .Text }}"
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
width="{{ $img.Width }}"
|
||||
height="{{ $img.Height }}"
|
||||
/>
|
||||
</picture>
|
||||
</center>
|
Reference in New Issue
Block a user