Working on Open Graph

I’m improving something I started last year, to automatically save thumbnail versions of web pages that could be used in various places. As an example, starting this week Micro.blog now makes banners suitable for Open Graph meta tags, combining the profile photo and a rendered thumbnail of the page.

I can’t decide yet if this is actually good, but I think it’s on the right track to something. I’ve never been happy with the way most platforms use Open Graph. It adds a lot of clutter. At the same time, Micro.blog’s previous default of doing nothing wasn’t great either, and some platforms like Threads would pull in the profile photo only, attempting to crop a square photo into a wider banner.

Here’s an example of one of the new images:

Coincidentally the text of my post fit perfectly, otherwise it will be centered or cropped off the bottom.

Another example with a post that has a photo:

I’d love to hear feedback before we go further with this. The new option is available in the Hugo front matter as a URL in .Params.opengraph.image. If a post has a photo, plug-ins can still prefer using the photo URL directly. If you want the web page thumbnail only, that’s in .Params.thumbnail.

I’m imagining it used like this:

{{ if .Params.photos }}  
  {{ with index .Params.photos 0 }}
    <meta property="og:image" content="{{ . }}">
  {{ end }} 
{{ else }}
  {{ with .Params.opengraph }}  
    <meta property="og:title" content="{{ .title }}">
    <meta property="og:image" content="{{ .image }}">
  {{ end }} 
{{ end }}

This hasn’t been added to the built-in themes yet. It can be added by editing your header template, or wait until the dust settles and it’s available in plug-ins.

Testing this has been a little hit or miss because platforms like Threads and Bluesky aggressively cache the metadata for a page. These thumbnails are created right after a blog post is published, so they might not be available the first time a platform checks for them, especially if Micro.blog cross-posts your post to the platform more quickly than the thumbnail is ready. More tweaks likely needed.

Max Jacobson

@manton Neat. I did something similar for my little personal blog mostly just to see if I could. Fun little project. hardscrabble.net/2024/generati

Manton Reece

@maxjacobson Cool, nice blog post!

Jarrod Blundy

Very cool. Thanks for this!

Jim Mitchell

Thanks! I plan to give this a spin this weekend…

Mitch Wagner

If I understand what you're doing here, I like it. jwz does something similar on his blog.

I'm eager to try this out but my meager skills mean I expect I'll have to wait until it's available as a plugin.

Manton Reece

@MitchW Cool, thanks. After a little more experimentation and feedback we can get it rolled into themes and plug-ins.

Mandaris Moore

I'm happy about this. I was playing around with trying to implement something like the following but didn't know if I could run it on Micro.blog. Here are the resources I was going to pull from.

Generating OpenGraph images with Hugo

Dynamically Generating OpenGraph

Best of luck!

prealpinux

Great news!

Manton Reece

@mandaris That's cool. I'm honestly not sure if those Hugo commands will work on Micro.blog or not! Would be fun to experiment with, although I expect it would slow down publishing a little too.

Manton Reece @manton
Lightbox Image