Open Graph link previews in posts

Hi. Is there a way to pull / display open graph info from links that I include in my posts? So when the Hugo engine generates the page, the finished post has the Open Graph preview included? (I’m using the plugin to generate OG info for my posts, and it’s working well)

I’m up for customizing a theme, but my searches on Hugo templating are coming up with nothing for this.

I think you’d have to write some JavaScript to do this “at run time” and go ahead and follow those links, collect their OG data, and then modify your DOM, which, I suspect won’t work for most OG workflows.

I can’t even think of a use case or somewhere else that does it— feels like an anti pattern to generate OG data from something other than the content of your own page…

I see @sod replying

1 Like

It’s doable, but parsing HTML is a bit awkward, and @manton might have opinions on your blog fetching remote resources on every build. :blush: Jason went ahead and built the plugin-cards plug-in with open graph parsing built-in. It might still work. It’s absent in the plug-in directory, but you can install it from the GitHub source.

Thanks all! I’ll do a bit more reading. Maybe a more server friendly way to this would be a local script, inside an Apple Shortcut, so the card generation happens once, locally, and pasted in.

I always forget about stuff that happened in Hugo after I initially started my blog, like the ability to do .Get.Resource and the like.

This also has the advantage of not going down when that URL goes away. Link rot would kill your build if you require retrieving and parsing HTML on every build of your site to every link that you link to.

1 Like