diff options
| author | Danilo M. <danix@danix.xyz> | 2026-04-15 22:55:05 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-04-15 22:55:05 +0200 |
| commit | dca88f8faf82b6fbc925afc344a07953eb2c8ca0 (patch) | |
| tree | 051f967bc4ba17c36fb9767c2031b5035d557635 /themes | |
| parent | b14e1db1b6bd40b401387e90af4bdd2acde41ca7 (diff) | |
| download | danixxyz-dca88f8faf82b6fbc925afc344a07953eb2c8ca0.tar.gz danixxyz-dca88f8faf82b6fbc925afc344a07953eb2c8ca0.zip | |
Resolve page bundle video paths using Resources API
- Use .Page.Resources.GetMatch to resolve video files in page bundles
- For videos in the same directory as index.md, use src="filename.webm"
- Template automatically resolves to correct permalink (/articles/slug/filename.webm)
- Falls back to literal path if resource not found (for external URLs)
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Diffstat (limited to 'themes')
| -rw-r--r-- | themes/danix-xyz-hacker/layouts/shortcodes/video.html | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/themes/danix-xyz-hacker/layouts/shortcodes/video.html b/themes/danix-xyz-hacker/layouts/shortcodes/video.html new file mode 100644 index 0000000..a07500a --- /dev/null +++ b/themes/danix-xyz-hacker/layouts/shortcodes/video.html @@ -0,0 +1,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> |
