audio.html 794 B

1234567891011121314151617181920212223242526
  1. {{/* Enable audio to be loaded from local page dir or media library at `static/media/`. */}}
  2. {{/* Supports primarily MP3 and MP4. */}}
  3. {{ $path := "" }}
  4. {{ $root_dir := "" }}
  5. {{ $media_dir := site.Params.media_dir | default "media" }}
  6. {{ if .Get "library" }}
  7. {{ $path = printf "%s/" $media_dir }}
  8. {{ $root_dir = "static/" }}
  9. {{ end }}
  10. {{ $audio := printf "%s%s" $path (.Get "src") }}
  11. {{ $audio_type := strings.TrimPrefix "." (path.Ext (.Get "src")) | lower }}
  12. {{/* Set MP3 mime type to mpeg. */}}
  13. {{ $audio_type = replace $audio_type "mp3" "mpeg" }}
  14. {{ if .Get "library" }}
  15. {{ $audio = $audio | relURL }}
  16. {{ end }}
  17. {{ if $audio }}
  18. <audio controls {{ with (.Get "id") }}id="audio-{{.|urlize}}"{{end}}>
  19. <source src="{{$audio}}" type="audio/{{$audio_type}}">
  20. </audio>
  21. {{ end }}