audio.html 963 B

1234567891011121314151617181920212223242526272829
  1. {{/* Audio Shortcode for Wowchemy. */}}
  2. {{/* Load audio from page dir falling back to media library at `assets/media/` and then to remote URI. */}}
  3. {{/* Supports primarily MP3 and MP4. */}}
  4. {{ $destination := .Get "src" }}
  5. {{ $is_remote := strings.HasPrefix $destination "http" }}
  6. {{- $asset := "" -}}
  7. {{- if not $is_remote -}}
  8. {{- $asset = (.Page.Resources.ByType "audio").GetMatch $destination -}}
  9. {{- if not $asset -}}
  10. {{- $asset = resources.Get (path.Join "media" $destination) -}}
  11. {{- end -}}
  12. {{- end -}}
  13. {{ if $asset }}
  14. {{ $destination = $asset.RelPermalink }}
  15. {{ else }}
  16. {{ $destination = $destination | safeURL }}
  17. {{ end }}
  18. {{ $audio_type := strings.TrimPrefix "." (path.Ext $destination) | lower }}
  19. {{/* Set MP3 mime type to mpeg. */}}
  20. {{ $audio_type = replace $audio_type "mp3" "mpeg" }}
  21. <audio controls {{ with (.Get "id") }}id="audio-{{.|anchorize}}"{{end}}>
  22. <source src="{{$destination}}" type="audio/{{$audio_type}}">
  23. </audio>