{{< img >}} shortcode

This commit is contained in:
Eryn Wells 2023-11-20 11:55:58 -08:00
parent ee98566283
commit a353c4a549

View file

@ -0,0 +1,21 @@
{{ $img := dict }}
{{ with .Get "name" }}
{{ $img = $.Page.Resources.GetMatch . }}
{{ else }}
{{ errorf "No name given to img shortcode" }}
{{ end }}
{{/* Space separated list of classes to apply to the <img> tag */}}
{{ $classes := .Get "class" }}
{{ $altText := $img.Params.alt | default (.Get "alt") }}
{{ if not $altText }}
{{ warnf "Image doesn't have alt text. %s" $img.Permalink }}
{{ end }}
{{ $resizedImg := $img.Fit "1280x1280" }}
<img src="{{ $resizedImg.RelPermalink }}"
width="{{ $resizedImg.Width }}"
height="{{ $resizedImg.Height }}"
alt="{{ $altText }}"
{{ with $classes }}class="{{ . }}"{{ end }}>