video.html 867 B

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