7
1
mirror of https://gitlab.com/ansol/web-ansol.org.git synced 2024-12-25 21:30:20 +00:00
web-ansol.org/themes/academic/layouts/shortcodes/video.html

27 lines
889 B
HTML
Raw Normal View History

2020-06-11 11:46:16 +00:00
{{/* Enable video to be loaded from local page dir or media library at `static/img/`. */}}
{{ $path := "" }}
{{ $root_dir := "" }}
{{ if .Get "library" }}
{{ $path = "img/" }}
{{ $root_dir = "static/" }}
{{ end }}
{{ $video := printf "%s%s" $path (.Get "src") }}
{{ $video_type := strings.TrimPrefix "." (path.Ext (.Get "src")) }}
{{ if .Get "library" }}
{{ $video = $video | relURL }}
{{ end }}
{{ $poster := printf "%s%s%s" $path (substr (.Get "src") 0 -4) ".jpg" }}
{{ $has_poster := fileExists (printf "%s%s" $root_dir $poster) }}
{{ if and $has_poster (.Get "library") }}
{{ $poster = $poster | relURL }}
{{ else if $has_poster }}
{{ $poster = $poster }}
{{ else }}
{{ $poster = "" }}
{{ end }}
<video {{if (.Get "controls")}}controls{{else}}autoplay loop{{end}} {{with $poster}}poster="{{.}}"{{end}}>
<source src="{{ $video }}" type="video/{{$video_type}}">
</video>