sknob/music v5.2.1 Release Notes, OG:image Edition!

#blogpost #music #coding

I didn’t see that one coming...

Having all the albums and songs on a single page means that by default, when you link to the page from somewhere else like a messaging app or your #fediverse feed, you always get the preview image specified in the <meta property="og:image..."> tag in the page header...

But then it dawned on me. Since I’m already using PHP to prep my XML playlist, it should be possible in theory to use PHP to dynamically change the og:image property based on the incoming URL.

Problem was, I’m an absolute PHP beginner.

Undaunted, I went ahead and figured it out, and tada, it works. If you call sknob.fr/music/?mysong, the og:image meta tag image is dynamically changed to mysong.jpg.

Out of laziness, I kept the somewhat complex image organization from the v4 version of the site (yes, I aim to clean that up eventually, but it’s not a trivial task), which means that the code won’t always find an image, in which case it defaults back to the default image. Same if you type in a garbage URL.

I’m really happy about this, because that was one thing that bothered me about going the single page route. I even sometimes shied away from posting links to my site on Mastodon because of it.

No more!