video.html 969 B

1234567891011121314151617181920212223242526272829
  1. {{/* Enable video to be loaded from local page dir or media library at `static/media/`. */}}
  2. {{ $path := "" }}
  3. {{ $root_dir := "" }}
  4. {{ $media_dir := site.Params.media_dir | default "media" }}
  5. {{ if .Get "library" }}
  6. {{ $path = printf "%s/" $media_dir }}
  7. {{ $root_dir = "static/" }}
  8. {{ end }}
  9. {{ $video := printf "%s%s" $path (.Get "src") }}
  10. {{ $video_type := strings.TrimPrefix "." (path.Ext (.Get "src")) }}
  11. {{ if .Get "library" }}
  12. {{ $video = $video | relURL }}
  13. {{ end }}
  14. {{ $poster := printf "%s%s%s" $path (substr (.Get "src") 0 -4) ".jpg" }}
  15. {{ $has_poster := fileExists (printf "%s%s" $root_dir $poster) }}
  16. {{ if and $has_poster (.Get "library") }}
  17. {{ $poster = $poster | relURL }}
  18. {{ else if $has_poster }}
  19. {{ $poster = $poster }}
  20. {{ else }}
  21. {{ $poster = "" }}
  22. {{ end }}
  23. <video {{if (.Get "controls")}}controls{{else}}autoplay loop{{end}} {{with $poster}}poster="{{.}}"{{end}}>
  24. <source src="{{ $video }}" type="video/{{$video_type}}">
  25. </video>