www.byjp.me/layouts/shortcodes/music.html
JP Hastings-Spital ffd9ef9447 Add Schema.org itemprops
Also re-enables openlibrary parsing.
2025-02-12 20:02:59 +00:00

40 lines
2.3 KiB
HTML

{{- $data := (index site.Data.music.musicbrainz (.Get 0)) -}}
{{- with $data -}}
{{- $displayArtist := .composer | default .artist -}}
{{- $displayTitle := .title | default .album -}}
{{- $musicbrainz := .musicbrainz -}}
{{- $klass := "" -}}
{{- $embed := "" -}}
{{- range .links -}}
{{- $u := urls.Parse . -}}
{{- if eq $u.Hostname "open.spotify.com" -}}
{{- $klass = "spotify" -}}
{{- $embed = printf "<iframe src='https://open.spotify.com/embed%s' height='80' frameBorder='0' allowfullscreen allow='autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture' loading='lazy'></iframe>" $u.Path -}}
{{- break -}}
{{- else if eq $u.Hostname "music.apple.com" -}}
{{- $klass = "apple-music" -}}
{{- $embed = printf "<iframe allow='autoplay *; encrypted-media *; fullscreen *; clipboard-write' frameborder='0' height='160' style='width:100%;max-width:660px;overflow:hidden;border-radius:10px;' sandbox='allow-forms allow-popups allow-same-origin allow-scripts allow-storage-access-by-user-activation allow-top-navigation-by-user-activation' src='https://embed.music.apple.com%s'></iframe>" $u.Path -}}
{{- break -}}
{{- else if and (eq $u.Hostname "soundcloud.com") (isset $data "soundcloudtrackid") -}}
{{- $klass = "soundcloud" -}}
{{- $embed = printf "<iframe src='https://w.soundcloud.com/player/?url=https%%3A//api.soundcloud.com/tracks/%s&auto_play=false&hide_related=true&show_comments=false&show_user=false&show_reposts=false&show_teaser=false&visual=false' loading='lazy' scrolling='no' frameborder='no' allow='autoplay'></iframe>" $data.soundcloudtrackid -}}
{{- break -}}
{{- end -}}
{{- end -}}
<figure class="embed audio {{$klass}}" itemscope itemtype="https://schema.org/MusicRecording">
{{ $embed | safeHTML }}
<figcaption>
🎶 <span itemprop="byArtist" itemscope itemtype="https://schema.org/MusicGroup"><span itemprop="name">{{ $displayArtist }}</span></span>{{ with $displayTitle }}{{ if $displayArtist }}: {{ end }}<em itemprop="name">{{ . }}</em>{{ end }}<br/>
{{ with $musicbrainz }}<a href="{{ . }}" target="_blank" style="font-style:italic;" itemprop="url">Listen elsewhere</a>{{ end }}
</figcaption>
</figure>
{{- else -}}
{{ errorf "Missing musicbrainz data for %s" (.Get 0) }}
{{- end -}}