The Crusty Dev

Audioplayer With Hugo


How to implement a simple audioplayer with the HUGO framework:

  • Create a folder in your hugo-project/layouts/shortcodes
  • Create layouts/shortcodes/audio.html file
  • Open to edit & paste
<figure {{ with .Get "class" }}class="{{ . }}"{{ end }}>
  <audio controls preload="{{ .Get "preload" | default "metadata" }}">
    {{ with .Get "src" }}<source src="{{ . | relURL }}" type="audio/mpeg">{{ end }}
  </audio>	
  {{ with .Get "caption" }}<figcaption>{{ . }}</figcaption>{{ end }}
</figure>
  • save & exit
  • In your page or post you will need to add the audio shortcode
  • and it will populate an html5 audio player.
{{<audio src="/media/audio/your-audio-file.mp3" caption="your caption">}}

The output

Radio

NostosFM Logo

Nostos Fm

BBC Radio One Logo

BBC Radio One