Files
hugo-recipes/layouts/shortcodes/audio.html
2025-11-16 17:38:05 -07:00

24 lines
683 B
HTML

{{ $src := .Get "src" | default (.Get 0)
}} {{ $type := .Get "type"
}} {{ if and (isset .Params "type") (not (eq $type ""))
}} {{ .Scratch.Set "type" $type
}} {{ else
}} {{ $type := strings.TrimSuffix $src (path.Ext $src)
}} {{ $type := strings.TrimPrefix "." $type
}} {{ .Scratch.Set "type" $type
}} {{ end
}}
{{ $text := .Get "text"
}} {{ if and (isset .Params "text") (not (eq $text ""))
}} {{ .Scratch.Set "text" $text
}} {{ else
}} {{ .Scratch.Set "text" "Audio playback is not available on your browser."
}} {{ end
}}
<audio controls>
<source
src='{{ $src }}'
type='audio/{{ .Scratch.Get "type" }}'
>
{{ .Scratch.Get "text" }}
</audio>