I am using the static site generator hugo to build my website. There is no built in shortcode for audio files, so I created one which fits my needs. It works with page resorces and absolute urls.

audio.html

Put this file with the following code in your projects layouts/shortcodes folder.



  {{- $u := urls.Parse (.Get "src") -}}
  {{- $src := $u.String -}}
  {{- if not $u.IsAbs -}}
    {{- with or (.Page.Resources.Get $u.Path) (resources.Get $u.Path) -}}
      {{- $src = .RelPermalink -}}
    {{- end -}}
  {{- end -}}

  
  {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
    
{{ with (.Get "title") -}}

{{ . }}

{{- end -}} {{- if or (.Get "caption") (.Get "attr") -}}

{{- .Get "caption" | markdownify -}} {{- with .Get "attrlink" }} {{- end -}} {{- .Get "attr" | markdownify -}} {{- if .Get "attrlink" }}{{ end }}

{{- end }}
{{- end }}

Using the shortcode

{{< audio src="example.mp3" type="audio/mpeg" title="Example" caption="Example Audio" >}}