AMPERION_Webpage/layouts/partials/img.html

27 lines
811 B
HTML
Raw Normal View History

2025-09-08 01:15:11 +02:00
{{/* Re-usable image partial with alt + size fallback
Usage:
{{ partial "img.html" (dict "src" "/images/foo.webp" "alt" "Kurzbeschreibung" "class" "img-fluid" "loading" "lazy" "page" .) }}
*/}}
{{- $src := .src -}}
{{- $alt := .alt | default .page.Title -}}
{{- $class := .class -}}
{{- $loading := .loading | default "lazy" -}}
{{- $w := 0 -}}
{{- $h := 0 -}}
{{- $static := printf "static/%s" (strings.TrimLeft "/" $src) -}}
{{- if fileExists $static -}}
{{- with (imageConfig $static) -}}
{{- $w = .Width -}}
{{- $h = .Height -}}
{{- end -}}
{{- end -}}
<img src="{{ $src | relURL }}"
alt="{{ $alt | plainify }}"
loading="{{ $loading }}"
decoding="async"
{{ if gt $w 0 }}width="{{ $w }}"{{ end }}
{{ if gt $h 0 }}height="{{ $h }}"{{ end }}
class="{{ $class }}">