Omphaloskepsis-2/layouts/shortcodes/video.html
2024-04-02 20:36:21 +01:00

47 lines
No EOL
1.6 KiB
HTML

<!--
Shortcode to render a video as part of content where the place in text flow is important.
@params src Video `src` path.
@params link URI or Page Resource to wrap video 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 $src ) -}}
{{- errorf "No Page Resource found for src %q (%q)" ( .Get "src" ) .Page.File.Path -}}
{{- end -}}
{{- if not ( eq $src.ResourceType "video" ) -}}
{{- errorf "Resource %q has resource type %q (expected \"video\") (%q)" ( .Get "src" ) $src.ResourceType .Page.File.Path -}}
{{- else if ( eq $src.MediaType "video/ogg" ) -}}
{{- errorf "Resource %q has 'video/ogg' media type %q (expected \"video/webm\" or other video type) (%q)" ( .Get "src" ) $src.MediaType .Page.File.Path -}}
{{- end -}}
{{- with .Get "rel" -}}
{{- if not ( in $valid_rel_values . ) -}}
{{- errorf "Invalid rel value %q (%q)" . .Page.File.Path -}}
{{- end -}}
{{- end -}}
<!-- Rendering -->
{{- if .Get "link" -}}
{{- if $linkedResource -}}
<a href="{{- $linkedResource.RelPermalink -}}"{{- with .Get "rel" }} rel="{{- . -}}"{{- end -}}>
{{- else -}}
<a href="{{- .Get "link" -}}">
{{- end -}}
{{- end -}}
{{- partial "media/video.html.tmpl" ( dict "." $src "page_file_path" .Page.File.Path ) -}}
{{- if .Get "link" -}}
</a>
{{- end -}}