1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-12-24 17:52:11 +00:00
seirdy.one/layouts/shortcodes/audio.html
Rohan Kumar 2badbe2601
Use cache-busting partial instead of Fingerprint
This gives files much smaller fingerprints, and supports caching.
2023-12-08 16:08:40 -08:00

43 lines
1.3 KiB
HTML

{{ $name := (.Get "name") -}}
{{- $opus := resources.GetMatch (printf "/a/%s.opus" $name) -}}
{{- $mp3 := resources.GetMatch (printf "/a/%s.mp3" $name) -}}
{{- $isTranscribed := false -}}
{{- $download_url := "" -}}
{{- /* preloading an in-page audio asset under 32 KiB is fine. */ -}}
{{- $shouldPreload := lt (len $opus.Content) 32768 -}}
<audio
controls=""
{{ with .Parent -}}
{{ if eq .Name "transcribed-image" -}}
{{- $isTranscribed = true -}}
{{ with .Get "id" -}}
aria-describedby="transcript-{{ . }}"
{{- end -}}
{{- end -}}
{{- end }}
{{ if $shouldPreload -}}
preload="auto"
{{- end -}}
>
{{ with $opus -}}
{{- $download_url = $opus.RelPermalink -}}
{{ $opus_src := partial "cache-bust.html" . -}}
<source
src="{{ $opus_src.RelPermalink }}"
type='audio/ogg; codecs="opus"' />
{{ end -}}
{{ with $mp3 -}}
{{- $download_url = $mp3.RelPermalink -}}
{{ $mp3_src := partial "cache-bust.html" . -}}
<source
src="{{ $mp3_src.RelPermalink }}"
type="audio/mpeg" />
<p role="note">Your browser does not support HTML5 audio.</p>
{{ end -}}
</audio>
<a
href="{{ $download_url }}" download=""
{{ if $isTranscribed -}}
itemprop="audio contentUrl"
{{- end -}}>Download audio file <samp translate="no">{{ $name }}.mp3</samp></a>
{{- /* Strip trailing newline: https://github.com/gohugoio/hugo/issues/1753 */ -}}