forked from markus/AMPERION_Webpage
26 lines
811 B
HTML
26 lines
811 B
HTML
{{/* 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 }}">
|