mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-06 14:14:04 +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.
26 lines
725 B
HTML
26 lines
725 B
HTML
{{/* Enable audio to be loaded from local page dir or media library at `static/media/`. */}}
|
|
{{/* Supports primarily MP3 and MP4. */}}
|
|
|
|
{{ $path := "" }}
|
|
{{ $root_dir := "" }}
|
|
{{ $media_dir := $.Scratch.Get "media_dir" }}
|
|
{{ if .Get "library" }}
|
|
{{ $path = printf "%s/" $media_dir }}
|
|
{{ $root_dir = "static/" }}
|
|
{{ end }}
|
|
|
|
{{ $audio := printf "%s%s" $path (.Get "src") }}
|
|
{{ $audio_type := strings.TrimPrefix "." (path.Ext (.Get "src")) | lower }}
|
|
|
|
{{/* Set MP3 mime type to mpeg. */}}
|
|
{{ $audio_type = replace $audio_type "mp3" "mpeg" }}
|
|
|
|
{{ if .Get "library" }}
|
|
{{ $audio = $audio | relURL }}
|
|
{{ end }}
|
|
|
|
{{ with $audio }}
|
|
<audio controls>
|
|
<source src="{{ . }}" type="audio/{{$audio_type}}">
|
|
</audio>
|
|
{{ end }} |