This is a shortcode for scrambling and posting youtube playlists. Rather than messing with the youtube API, it takes ids from a json file, scrambles them and prints them to an iframe.
The only problem is it drops an id from the list at the delimit code, here
{{$ids = delimit (after 1 $ids) ", " }}
For example, 15 ids from the following json file, stored in data/playlists.json, go in, and only 14 are printed to the post. The post frontmatter has this variable: playlist = “Jazz 2”
{
"playlists": [
{
"name": "Jazz 2",
"description" : "I did the Samba to Cannonball Adderly",
"songs": "Cannonball Adderly: Autumn Leaves, Wabash, Toy, Groovy Samba, Oscar Peterson: Take the A train, The Girl from Ipanima, Sometimes Im Happy, Happy Go Lucky Localaka: Night Train, A Little Jazz Exercise, Charlie Parker: Bloomdido, Dizzy Gillespie: One Note Samba, Con Alma, Beale Street, Flute Blues",
"ids": [
"IlxPpZC5OQY",
"e-S1Ftz4S-M",
"y7lJRnyRqMw",
"69uh2T1TtTY",
"_7WCzeylk08",
"WeDjbJMb1yw",
"8r1BAb9k7lg",
"_zTkpME1ATQ",
"UjNha6jgOOk",
"EF16My0SRo8",
"eUSYlOTP2_k",
"DggGN8E2vx0",
"J-3FwDJN9-s",
"he56MOJSC8A",
"YvwZ2kwfZ3s"
]
}
]
}
Here is the full shortcode:
{{$ids := slice "" }}
{{$list := "" }}
{{$description := "" }}
{{$songs := "" }}
{{if .Page.Params.playlist}}
{{$list = .Page.Params.playlist}}
{{else}}
{{$list = .Site.Params.playlist}}
{{end}}
{{$playlists := site.Data.playlists }}
{{range $playlists.playlists }}
{{if eq .name $list }}
{{range .ids}}
{{$ids = $ids | append . | shuffle }}
{{ end }}
{{$description = .name}}
{{$songs = .songs}}
{{ end }}
{{ end }}
{{$ids = delimit (after 1 $ids) ", " }}
<h5>Songs:</h5>
<p class= "p-news">{{- $songs -}}</p>
<div class="mobile-iframe">
<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/VIDEO_ID?playlist={{- $ids -}};rel=0;modestbranding=1;iv_load_policy=3;showinfo=0;autohide=0;"frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>
</div> <!-- end mobile-iframe -->
<h5 class="center">Playlist Title: {{- $description -}}</h5>
<br/>
Can anyone see why $ids goes into this code with 15 ids and comes out with 14?