From ca4f7b07ef9994278f14794cd540f4fee5802512 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Wed, 29 Jul 2020 13:57:10 +0100 Subject: [PATCH] feat: add Audio shortcode --- layouts/shortcodes/audio.html | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 layouts/shortcodes/audio.html diff --git a/layouts/shortcodes/audio.html b/layouts/shortcodes/audio.html new file mode 100644 index 00000000..7a1ddf1c --- /dev/null +++ b/layouts/shortcodes/audio.html @@ -0,0 +1,25 @@ +{{/* Enable audio to be loaded from local page dir or media library at `static/media/`. */}} +{{/* Supports primarily MP3 and MP4. */}} + +{{ $path := "" }} +{{ $root_dir := "" }} +{{ if .Get "library" }} + {{ $path = "media/" }} + {{ $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 }} + +{{ end }} \ No newline at end of file