feat: add Audio shortcode

This commit is contained in:
George Cushen committed 2020-07-29 13:57:10 +01:00
1 parent 4afdb4deba
commit ca4f7b07ef
1 file changed
+25
+25
View File
@@ -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 }}
<audio controls>
<source src="{{ . }}" type="audio/{{$audio_type}}">
</audio>
{{ end }}