Files
HugoBlox-kit/layouts/shortcodes/audio.html
T
George Cushen d9ff93a1c2 feat: make media library dir configurable
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.
2020-07-29 18:54:28 +01:00

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 }}