mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-06 18:16:17 +00:00
Move default media library from static/img/ to static/media/ as it can now contain audio, video, and other kinds of media in addition to images. BREAKING CHANGE: Either rename your site's static/img/ to static/media/ (and update any references to this folder in your Markdown files); Or, add `media_dir = "img"` to `params.toml` to continue using the legacy location.
29 lines
955 B
HTML
29 lines
955 B
HTML
{{/* Enable video to be loaded from local page dir or media library at `static/media/`. */}}
|
|
|
|
{{ $path := "" }}
|
|
{{ $root_dir := "" }}
|
|
{{ $media_dir := $.Scratch.Get "media_dir" }}
|
|
{{ if .Get "library" }}
|
|
{{ $path = printf "%s/" $media_dir }}
|
|
{{ $root_dir = "static/" }}
|
|
{{ end }}
|
|
|
|
{{ $video := printf "%s%s" $path (.Get "src") }}
|
|
{{ $video_type := strings.TrimPrefix "." (path.Ext (.Get "src")) }}
|
|
{{ if .Get "library" }}
|
|
{{ $video = $video | relURL }}
|
|
{{ end }}
|
|
|
|
{{ $poster := printf "%s%s%s" $path (substr (.Get "src") 0 -4) ".jpg" }}
|
|
{{ $has_poster := fileExists (printf "%s%s" $root_dir $poster) }}
|
|
{{ if and $has_poster (.Get "library") }}
|
|
{{ $poster = $poster | relURL }}
|
|
{{ else if $has_poster }}
|
|
{{ $poster = $poster }}
|
|
{{ else }}
|
|
{{ $poster = "" }}
|
|
{{ end }}
|
|
|
|
<video {{if (.Get "controls")}}controls{{else}}autoplay loop{{end}} {{with $poster}}poster="{{.}}"{{end}}>
|
|
<source src="{{ $video }}" type="video/{{$video_type}}">
|
|
</video> |