How can I look up OpenGraph/Twitter cards when building a site?


#1

I’m building a tumblelog theme for Hugo and I want to have a Link content type that HTTP GETs the OpenGraph metadata/Twitter card from the given URL when the site is built so that I can display the target page’s title, featured image etc. Is there any way I can make HTTP GET requests to remote URLs when building the site so that this data can be fetched? And just as importantly, how would that data be stored?

To be clear: I know how to generate OpenGraph/Twitter cards for the content on my own site. I want to know how to fetch that metadata from other people’s sites given the URLs at build time.


#2

This is fairly out of scope for something Hugo does on its own.

Since you want it at build time, javascript is out, but that could handle it on page render.

If you are adding them via a shortcode, you could reference a data file, and then have some external script go through it and update it, but that seems like an easy system to break and spam sites whenever your site builds.

Here’s the thing, I can think of a couple of ways to get that to work, during a build script, but it is so convoluted and inelegant, it would be a waste of time.

Maybe you find an external service that updates the metadata, and can serve all of it as a datafile to Hugo at build time.