summaryrefslogtreecommitdiffstats
path: root/themes/danix-xyz-hacker/layouts/shortcodes/video.html
blob: a07500ac412db9574179ea769d4d5288e3aeb55e (plain)
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
{{/*
	* The video shortcode:
	* All arguments are optional, except for src which is where you define your video file
	* This shortcode supports only webm video files.
	* Args:
	*		class: [string] The class(es) to give to the video block.
	*		width: [int] The width of the video
	*		height: [int] The height of the video
	*		autoplay: [bool] true or false for autoplay - defaults to false
	*		loop: [bool] true or false for loop - defaults to false
	*		mute: [bool] true or false for mute - defaults to false
	*
	* Usage:
	*		{{< video src="my-awesome-video.mp4" width=600 height=600 autoplay=true loop=true mute=true class="some class" >}}
	*
	* Output:
	*	<video class="some class" controls preload="auto" width="600" height="600" autoplay loop muted>
			<source src="my-awesome-video.mp4" type="video/webm">
	*	</video>
	*
	*/}}

{{ $srcParam := .Get "src" }}
{{ $ext := $srcParam | path.Ext }}
{{ $filetype := slicestr $ext 1 }}

{{ $videoURL := $srcParam }}
{{ $resource := .Page.Resources.GetMatch $srcParam }}
{{ if $resource }}
  {{ $videoURL = $resource.RelPermalink }}
{{ end }}

<video{{ with .Get "class" }} class="{{ . }}"{{ end }}
	controls
	preload="auto"
	{{ with .Get "width" }}width="{{.}}"{{ end }}
	{{ with .Get "height" }}height="{{.}}"{{ end }}
	{{ if eq (.Get "autoplay") "true" }}autoplay {{ end }}
	{{ if eq (.Get "loop") "true" }}loop {{ end }}
	{{ if eq (.Get "muted") "true" }}muted {{ end }}
	playsinline >
    <source src="{{ $videoURL }}" type="video/{{ $filetype }}">
</video>