Youtube Embeds

I’ve searched the help and the web and I can’t seem to figure out if MB does any auto-embedding of YouTube videos. Based on my recent post, that answer is no. Or, if there’s a way I can make this happen with the right Markdown incantation. Or, do I need to do all the HTML. If it’s the latter, is that possible in the MB iOS app?

Hugo (the blogging engine powering Micro.blog) comes with a clever little feature called shortcodes. And there’s one for embedding YouTube videos. Just pass it the YouTube identifier like this:

{{< youtube w7Ft2ymGmfc >}}
2 Likes

I didn’t think to look at the Hugo documentation! Thanks!

Note: embeds of all kinds are stripped out of the Micro.blog timeline. Your blog and RSS will all look good though.

To add one more thing: for YouTube embeds specifically (and Apple Music and Spotify too, because they are also common embeds), Micro.blog will show a link in the timeline instead of the embed, so that people viewing the timeline can still click out to it. And then as @jsonbecker said, if they’re reading on your blog post they will get the full embed.

Thanks for the details and explanations. It looks like Hugo supports custom shortcodes. Is that possible with MB or should I figure out how to use a partial for that use case. Specifically, I’d love to create one for Bandcamp embeds. Maybe that’s possible in a plugin scenario?

Yes, a Micro.blog plug-in can provide a custom Hugo shortcode. One example to check out: I made this RSVP plug-in. Really all you need is a template in layouts/shortcodes and you’re good to go. That can be a custom template just for your blog, or as a plug-in so other folks can install it easily.

1 Like

Here’s another good shortcode example for Micro.blog: @jsonbecker’s Bookshop plug-in. (Better than my RSVP example, actually, because the Bookshop shortcode supports different types of parameters.)

1 Like

Looks like I have a little Friday afternoon project. Thanks!

1 Like

Today’s newsletter issue has a post in which I’ve used a Hugo shortcode to embed a YouTube video.

The video shows up great on my site. In the newsletter issue, the shortcode appears.

How do I offer a fallback link?

Short codes don’t work in Newsletters at all— they are not processed by Hugo. When you get the newsletter template, directly edit it with a video tag or the link and remove the shortcode.

Hi, @jsonbecker. Could you explain what you mean by “directly edit it with a video tag,” please?

Also, with the new newsletter template, I don’t see a way to edit the newsletter itself and not the post. When I edit my newsletter, I’m editing the posts themselves. (Just tried it by clicking the “Edit” button beneath one of the posts included in my newsletter, and it took me to the post edit screen.)

Video tag would be an HTML video tag but that’s won’t work for YouTube. You could probably paste the embed link that YouTube give you I think that would work.

Yup. This is a change that was implemented earlier this month. I used to edit some long form posts by adding a “Read More” link so as to keep the length of the email short. But we can’t do that now. In my case, I can see the arguments on both sides so not too torn up about it.

I have the same use case. If I use the newsletter feature, I’m unable to use embeds, which is a major part of my music blogging workflow.