Add support for embedding videos in the figures/image shortcode

This commit is contained in:
Eryn Wells 2024-10-31 08:06:05 -07:00
parent d679ae6c39
commit 8bfa3fc8bf

View file

@ -17,31 +17,35 @@
{{ errorf "No images found for name(s) parameter" }} {{ errorf "No images found for name(s) parameter" }}
{{- end -}} {{- end -}}
<figure class="figure figure--image{{ with $class }} {{ . }}{{ end }}"> {{ with $item := index $imgs 0 }}
<figure class="figure figure--{{ $item.ResourceType }}{{ with $class }} {{ . }}{{ end }}">
<div class="figure__container"> <div class="figure__container">
{{ range $img := $imgs }} {{ if eq $item.ResourceType "image" }}
{{- $linkedImg := $img -}} {{- $processedImage := $item -}}
{{- if not $img }}
{{ errorf "Found nil in images list for %s" $.Page.Permalink }}
{{ end -}}
{{- if $shouldResize -}} {{- if $shouldResize -}}
{{ $linkedImg = $img.Fit "1280x1280" }} {{ $processedImage = $item.Fit "1280x1280" }}
{{- end -}} {{- end -}}
{{- $altText := $img.Params.alt | default $img.Title -}} {{- $altText := $item.Params.alt | default $item.Title -}}
<a href="{{ $img.RelPermalink }}"> <a href="{{ $item.RelPermalink }}">
<img src="{{ $linkedImg.RelPermalink }}" <img src="{{ $processedImage.RelPermalink }}"
{{- with $altText }} alt="{{ . }}"{{- end }} {{- with $altText }} alt="{{ . }}"{{- end }}
{{- with $img.Title }} title="{{ . }}"{{- end }}> {{- with $item.Title }} title="{{ . }}"{{- end }}>
</a> </a>
{{ else if eq $item.ResourceType "video" }}
<video controls width="100%">
<source src="{{ $item.RelPermalink }}" type="{{ $item.MediaType.Type }}">
</video>
{{- end }} {{- end }}
</div> </div>
{{ if $shouldShowTitle -}} {{ if $shouldShowTitle -}}
{{- range $imgs -}} {{- with $item -}}
{{- if gt (len .Title) 0 -}} {{- if gt (len .Title) 0 -}}
<figcaption>{{ .Title }}</figcaption> <figcaption>{{ .Title | markdownify }}</figcaption>
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- end }} {{- end }}
</figure> </figure>
{{ else }}
{{ errorf "Found nil in items list for %s" $.Page.Permalink }}
{{ end }}