audio.html 664 B

12345678910111213141516171819202122232425
  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. {{ if .Get "library" }}
  6. {{ $path = "media/" }}
  7. {{ $root_dir = "static/" }}
  8. {{ end }}
  9. {{ $audio := printf "%s%s" $path (.Get "src") }}
  10. {{ $audio_type := strings.TrimPrefix "." (path.Ext (.Get "src")) | lower }}
  11. {{/* Set MP3 mime type to mpeg. */}}
  12. {{ $audio_type = replace $audio_type "mp3" "mpeg" }}
  13. {{ if .Get "library" }}
  14. {{ $audio = $audio | relURL }}
  15. {{ end }}
  16. {{ with $audio }}
  17. <audio controls>
  18. <source src="{{ . }}" type="audio/{{$audio_type}}">
  19. </audio>
  20. {{ end }}