-
Notifications
You must be signed in to change notification settings - Fork 51
/
video.html
57 lines (45 loc) · 1.54 KB
/
video.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!--
Embed videos from Hugo Page Resources.
Setting src="my-video" with the Page Bundle containing...
- my-video.png
- my-video.mp4
- my-video.webm
...will render the following:
<video poster="my-video.png">
<source src="my-video.mp4" type="video/mp4" />
<source src="my-video.webm" type="video/webm" />
</video>
-->
{{ $src := .Get "src" }}
{{ if strings.HasPrefix $src "./" }}
<!-- Strip "./" prefix from relative path -->
{{ $src = substr $src 2 }}
{{ end }}
{{ $poster := ((.Page.Resources.ByType "image").GetMatch (printf "%s*" $src)) }}
{{ $videos := (.Page.Resources.ByType "video").Match (printf "%s*" $src) }}
<!--prettier-ignore-->
{{ if .Get "caption" }}
<figure>
{{ end }}
{{ if $videos }}
<video
{{ if eq (.Get "autoplay") "true" }}autoplay{{ end }}
{{ if eq (.Get "controls" | default "true") "true" }}controls{{ end }}
{{ with .Get "height" }}height="{{ . }}"{{ end }}
{{ if eq (.Get "loop") "true" }}loop{{ end }}
{{ if eq (.Get "muted") "true" }}muted{{ end }}
{{ with $poster }}poster="{{ .RelPermalink }}"{{ end }}
{{ with .Get "preload" }}preload="{{ . }}"{{ end }}
{{ with .Get "width" }}width="{{ . }}"{{ end }}
{{ if eq (.Get "playsinline" | default "true") "true" }}playsinline{{ end }}
>
{{- range $videos -}}
<source src="{{ .RelPermalink }}" type="{{ .MediaType }}" />
{{- end -}}
</video>
{{ end }}
<!--prettier-ignore-->
{{ if .Get "caption" }}
<figcaption>{{ .Page.RenderString (.Get "caption") }}</figcaption>
</figure>
{{ end }}