Omphaloskepsis-2/layouts/shortcodes/figure.html

70 lines
2.8 KiB
HTML
Raw Normal View History

2024-04-02 19:36:21 +00:00
<!--
Shortcode to render a media file as part of content where the place in text flow is not important.
@params src Resource `src` path.
@params link URI or Page Resource to wrap resource in. Optional.
@params rel Force relationship value. Optional.
-->
<!-- Variable assignment -->
{{- $src := $.Page.Resources.GetMatch ( .Get "src" ) -}}
{{- $linkedResource := $.Page.Resources.GetMatch ( .Get "link" ) -}}
{{- $valid_rel_values := partialCached "util/get_valid_rel_values.html.tmpl" . -}}
<!-- Validation -->
{{- if not ( in ( slice "image" "video" ) $src.ResourceType ) -}}
{{- errorf "Resource '%q' resource type '%q' is not valid (%q)" ( .Get "src" ) $src.ResourceType .Page.File.Path -}}
{{- end -}}
2023-08-22 10:14:33 +00:00
{{- if ( not $src ) -}}
{{- errorf "No Page Resource found for src '%q' (%q)" ( .Get "src" ) .Page.File.Path -}}
2023-02-18 00:38:04 +00:00
{{- end -}}
2024-04-02 19:36:21 +00:00
{{- with .Get "rel" -}}
{{- if not ( in $valid_rel_values . ) -}}
{{- errorf "Invalid rel value '%q' (%q)" . .Page.File.Path -}}
{{- end -}}
{{- end -}}
<!-- Rendering -->
2023-02-18 00:38:04 +00:00
2023-08-22 10:14:33 +00:00
<figure class="article__figure figure{{ with .Get "class" }} {{ . }}{{ end }}" role="group">
{{- if .Get "link" -}}
{{- if $linkedResource }}
<a href="{{ $linkedResource.RelPermalink }}"{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
{{ else }}
<a href="{{ .Get "link" }}">
{{ end }}
{{- end -}}
2022-11-11 05:48:02 +00:00
2023-08-22 10:14:33 +00:00
{{- if eq $src.ResourceType "image" -}}
2024-04-02 19:36:21 +00:00
{{- partial "media/picture.html.tmpl" $src -}}
2023-08-22 10:14:33 +00:00
{{- else if eq $src.ResourceType "video" -}}
{{- if eq $src.MediaType "video/ogg" -}}
2024-04-02 19:36:21 +00:00
{{- partial "media/audio.html.tmpl" $src -}}
2023-08-22 10:14:33 +00:00
{{- else -}}
2024-04-02 19:36:21 +00:00
{{- partial "media/video.html.tmpl" ( dict "." $src "page_file_path" .Page.File.Path ) -}}
2023-02-18 00:38:04 +00:00
{{- end -}}
2024-04-02 19:36:21 +00:00
2023-08-22 10:14:33 +00:00
{{- else if ( or ( ne $src.ResourceType "image" ) ( ne $src.ResourceType "video" ) ) -}}
{{- errorf "No handling for resource of type %q" $src.ResourceType -}}
2023-01-29 18:50:16 +00:00
{{- end -}}
2024-04-02 19:36:21 +00:00
2023-08-22 10:14:33 +00:00
{{- if .Get "link" }}</a>{{ end -}}
2023-02-18 00:38:04 +00:00
{{- if or ( .Get "caption" ) ( .Get "title" ) ( $src.Params.attr ) -}}
<figcaption class="figure__caption{{ if not ( or ( .Get "caption" ) ( .Get "title" ) ) }} figure__caption--no-height{{ end }}">
2023-08-22 10:14:33 +00:00
{{- if .Params.attrlink -}}<a class="figcaption__attrlink" href="{{ .Params.attrlink }}">{{- end -}}
{{- if .Params.attr -}}<p class="figcaption__attr">{{ .Params.attr | safeHTML }}{{ with .Params.attrlicence }} <span class="figcaption__licence">{{ . | safeHTML }}</span>{{ end }}</p>{{- end -}}
{{- if .Params.attrlink -}}</a>{{- end -}}
2023-07-01 03:16:59 +00:00
{{- with .Get "title" -}}<h4 class="figcaption__title">{{ . | markdownify | safeHTML }}</h4>{{- end -}}
2023-08-22 10:14:33 +00:00
{{- with .Get "caption" -}}<p class="figcaption__caption">{{ . | markdownify | safeHTML }}</p>{{- end -}}
2022-11-11 05:48:02 +00:00
</figcaption>
{{- end -}}
</figure>