erynwells.me/layouts/shortcodes/figures/image.html

40 lines
1.2 KiB
HTML

{{- $imgs := slice -}}
{{- if .Get "name" -}}
{{- $imgs = $imgs | append (.Page.Resources.GetMatch (.Get "name")) -}}
{{- else if .Get "names" -}}
{{- range (split (.Get "names") ",") -}}
{{- $imgs = $imgs | append ($.Page.Resources.GetMatch .) -}}
{{- end -}}
{{- else -}}
{{ errorf "Missing name or names parameter to figures/image" }}
{{- end -}}
{{- $class := .Get "class" -}}
{{- if lt (len $imgs) 0 -}}
{{ errorf "No images found for name(s) parameter" }}
{{- end -}}
{{- $shouldShowTitle := (.Get "shouldShowTitle") | default true -}}
<figure {{with $class }}class="{{ . }}"{{ end }}>
<div class=container>
{{ range $img := $imgs -}}
{{- $resizedImg := $img.Fit "1280x1280" -}}
{{- $altText := $img.Params.alt | default $img.Title -}}
<a href="{{ $img.RelPermalink }}">
<img src="{{ $resizedImg.RelPermalink }}"
{{- with $altText }} alt="{{ . }}"{{- end }}
{{- with $img.Title }} title="{{ . }}"{{- end }}>
</a>
{{- end }}
</div>
{{ if and $shouldShowTitle -}}
{{- range $imgs -}}
{{- if gt (len .Title) 0 -}}
<figcaption>{{ .Title }}</figcaption>
{{- end -}}
{{- end -}}
{{- end }}
</figure>