2023-01-29 18:50:16 +00:00
{{ $src := $.Page.Resources.GetMatch (.Get "src") }}
{{ $link := $.Page.Resources.GetMatch (.Get "link") }}
2022-11-11 05:48:02 +00:00
< figure { { with . Get " class " } } class = "{{ . }}" { { end } } >
{{- if .Get "link" -}}
2023-01-29 18:50:16 +00:00
{{- if $link }}
< a href = "{{ $link.RelPermalink }}" { { with . Get " rel " } } rel = "{{ . }}" { { end } } >
2022-11-11 05:48:02 +00:00
{{ else }}
< a href = "{{ .Get " link " } } " { { with . Get " target " } } target = "{{ . }}" { { end } } { { with . Get " rel " } } rel = "{{ . }}" { { end } } >
{{ end }}
{{- end -}}
2023-01-29 18:50:16 +00:00
{{- if eq $src.ResourceType "image" -}}
< picture class = "figure__picture" >
< img class = "figure__image"
{{ with $src.Resize (printf "%dx%d webp" $src.Width $src.Height) }}
src="{{ .RelPermalink }}"
{{ end }}
{{- if or ($src.Params.alt) (.Get "caption") }}
alt="{{ with $src.Params.alt }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}"
{{- end -}}
{{- with $src.Params.title }} title="{{ . }}"{{ end -}}
width="{{ $src.Width }}"
height="{{ $src.Height }}"
/>
< / picture >
{{- else if eq $src.ResourceType "video" -}}
{{- if eq $src.MediaType "video/ogg" -}}
< audio controls >
< source src = "{{ $src.RelPermalink }}" type = "{{ $src.MediaType }}" / >
< p > Your browser doesn't support embedded audio, but you can view the audio < a href = "{{ $src.RelPermalink }}" > here< / a > .< / p >
< / audio >
{{- else -}}
< video class = "figure__video"
controls
src="{{ $src.RelPermalink }}"
poster="{{ if $src.Params.poster }}{{ .Get $src.Params.poster }}{{ else }}{{ warnf "No poster defined for resource %q" $src.RelPermalink }}{{ end }}"
>
Your browser doesn't support embedded video, but you can view the video < a href = "{{ $src.RelPermalink }}" > here< / a > .
< / video >
{{- end -}}
{{- else if or ( ne $src.ResourceType "image" ) ( ne $src.ResourceType "video" ) -}}
{{- errorf "No handling for resource of type %q" $src.ResourceType -}}
{{- end -}}
2022-11-11 05:48:02 +00:00
{{- if .Get "link" }}< / a > {{ end -}}
2023-01-29 18:50:16 +00:00
{{- if or (.Get "caption") ($src.Params.attr) -}}
2022-11-11 05:48:02 +00:00
< figcaption class = "figure__caption{{ if not (.Get " caption " ) } } figure__caption--no-height { { end } } " >
2023-01-29 18:50:16 +00:00
{{- if $src.Params.attrlink -}}
< a class = "figcaption__attrlink" href = "{{ $src.Params.attrlink }}"
{{- with $src.Params.attrtarget }} target="{{ . }}"{{ end -}}
{{- with $src.Params.attrrel }} rel="{{ . }}"{{ end -}}
2022-11-11 05:48:02 +00:00
>
{{- end -}}
2023-01-29 18:50:16 +00:00
{{- with $src.Params.attr -}}< p class = "figcaption__attr" > {{ . | safeHTML }}{{ with $src.Params.attrlicence }} < span class = "figcaption__licence" > {{ . | safeHTML }}< / span > {{ end }}< / p > {{- end -}}
{{- if $src.Params.attrlink -}}
2022-11-11 05:48:02 +00:00
< / a >
{{- end -}}
2023-01-29 18:50:16 +00:00
{{- with $src.Params.title -}}< h4 class = "figcaption__title" > {{ . }}< / h4 > {{- end -}}
{{- with .Get "caption" -}}< p class = "figcaption__caption" > {{ . | markdownify }}< / p > {{- end -}}
2022-11-11 05:48:02 +00:00
< / figcaption >
{{- end -}}
< / figure >