added video shortcode
authordanix <danix@danix.xyz>
Fri, 10 Feb 2023 16:06:10 +0000 (17:06 +0100)
committerdanix <danix@danix.xyz>
Fri, 10 Feb 2023 16:06:10 +0000 (17:06 +0100)
layouts/shortcodes/gravatar.html
layouts/shortcodes/video.html [new file with mode: 0644]

index 10b15e0..004ba93 100644 (file)
@@ -25,6 +25,7 @@
        *       </figure>
        *
        */}}
+
 {{- if .Get "mail" -}}
        {{- $mailaddr := .Get "mail" -}}
        {{- .Scratch.Set "mailhash" $mailaddr -}}
diff --git a/layouts/shortcodes/video.html b/layouts/shortcodes/video.html
new file mode 100644 (file)
index 0000000..ec96125
--- /dev/null
@@ -0,0 +1,36 @@
+{{/*
+       * 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>
+       *
+       */}}
+
+{{ $ext := (.Get "src") | path.Ext }}
+{{ $filetype := slicestr $ext 1}}
+
+<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 class="html-video" >
+    <source src="{{ ( .Get "src" ) }}" type="video/{{ $filetype }}">
+</video>