diff options
Diffstat (limited to 'layouts')
| -rw-r--r-- | layouts/_partials/audio.html | 32 | ||||
| -rw-r--r-- | layouts/single.gmi | 4 | ||||
| -rw-r--r-- | layouts/single.html | 6 |
3 files changed, 37 insertions, 5 deletions
diff --git a/layouts/_partials/audio.html b/layouts/_partials/audio.html new file mode 100644 index 0000000..a99e9b3 --- /dev/null +++ b/layouts/_partials/audio.html @@ -0,0 +1,32 @@ +{{/* Returns the page's audio resources, best sounding first, so that a + browser takes the best encoding it can play and the capsule links + the best single file. Public listening tests put Opus ahead of the + field at the bitrates spoken word uses, with Vorbis and AAC close + behind it and MP3 last. Lossless comes after the lossy codecs + rather than before, since a browser that can play FLAC would + otherwise fetch several times the bytes for no audible gain. + + Hugo reports .opus, .oga and .ogg alike as audio/ogg, so the + extension is what tells the codecs apart. Formats not listed here + keep Hugo's own order at the end. Returns an empty slice when there + is no audio. */ -}} + +{{ $preferred := slice ".opus" ".ogg" ".oga" ".m4a" ".aac" ".mp3" ".flac" ".wav" -}} +{{ $audio := where .Resources "MediaType.MainType" "audio" -}} +{{ $ordered := slice -}} + +{{ range $extension := $preferred -}} + {{ range $audio -}} + {{ if eq (lower (path.Ext .Name)) $extension -}} + {{ $ordered = $ordered | append . -}} + {{ end -}} + {{ end -}} +{{ end -}} + +{{ range $audio -}} + {{ if not (in $preferred (lower (path.Ext .Name))) -}} + {{ $ordered = $ordered | append . -}} + {{ end -}} +{{ end -}} + +{{ return $ordered }} diff --git a/layouts/single.gmi b/layouts/single.gmi index 29df881..2cee33d 100644 --- a/layouts/single.gmi +++ b/layouts/single.gmi @@ -8,9 +8,9 @@ {{ partial "pageinfo.gmi" . }} {{- end -}} -{{ with index (where .Resources "MediaType.MainType" "audio") 0 }} +{{ with partial "audio.html" . }}{{ with index . 0 }} => {{ .RelPermalink }} {{ emojify ":link:" }} {{ i18n "downloadAudio" $.Title }} -{{- end }} +{{- end }}{{ end }} {{ $content := chomp (.RawContent) -}} {{ $scratch := newScratch -}} diff --git a/layouts/single.html b/layouts/single.html index 9ea21f4..bb9b10e 100644 --- a/layouts/single.html +++ b/layouts/single.html @@ -11,10 +11,10 @@ {{- if (.Page.Params.pageinfo | default true) }} <p class="entry__pageinfo">{{ partial "pageinfo.html" . }}</p> {{- end -}} - {{ with index (where .Resources "MediaType.MainType" "audio") 0 }} + {{ with partial "audio.html" . }} <audio class="entry__audio" controls preload="metadata" aria-label="{{ i18n "audioVersion" $.Title }}"> - <source src="{{ .RelPermalink }}" type="{{ .MediaType }}"> - {{ i18n "audioUnsupported" }} + {{ range . }}<source src="{{ .RelPermalink }}" type="{{ .MediaType }}"> + {{ end }}{{ i18n "audioUnsupported" }} </audio> {{- end }} </div> |
