video.html 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. {{/* Video Shortcode for Wowchemy. */}}
  2. {{/* Load video from page dir falling back to media library at `assets/media/` and then to remote URI. */}}
  3. {{ $destination := .Get "src" }}
  4. {{ $video_ext_with_dot := path.Ext (.Get "src") }}
  5. {{ $video_ext := strings.TrimPrefix "." $video_ext_with_dot }}
  6. {{ $video_type := $video_ext }}
  7. {{ $destination_preview := (.Get "poster") | default (replace $destination $video_ext_with_dot ".jpg") }}
  8. {{ $is_remote := strings.HasPrefix $destination "http" }}
  9. {{- $asset := "" -}}
  10. {{- $asset_preview := "" -}}
  11. {{- if not $is_remote -}}
  12. {{- $asset = (.Page.Resources.ByType "video").GetMatch $destination -}}
  13. {{- $asset_preview = (.Page.Resources.ByType "image").GetMatch $destination_preview -}}
  14. {{- if not $asset -}}
  15. {{- $asset = resources.Get (path.Join "media" $destination) -}}
  16. {{- $asset_preview = resources.Get (path.Join "media" $destination_preview) -}}
  17. {{- end -}}
  18. {{ $video_type = $asset.MediaType.SubType }}
  19. {{- end -}}
  20. {{ if $asset }}
  21. {{ $destination = $asset.RelPermalink }}
  22. {{ else }}
  23. {{ $destination = $destination | safeURL }}
  24. {{ end }}
  25. {{ $poster := (.Get "poster") | default "" }}
  26. {{ if $asset_preview }}
  27. {{ $poster = $asset_preview.RelPermalink }}
  28. {{ end }}
  29. <video {{if (.Get "controls")}}controls{{else}}autoplay loop{{end}} {{with $poster}}poster="{{.}}"{{end}} {{ with (.Get "id") }}id="video-{{.|anchorize}}"{{end}}>
  30. <source src="{{$destination}}" type="video/{{$video_type}}">
  31. </video>