Twitter Short Code Timeout

I am using the Twitter Short Code and nearly every other build is failing with:

Building sites … WARN 2019/02/25 16:40:21 Timed out creating content for page "D:\\home\\site\\repository\\content\\blog\\2019-02-15-itpro-level-up.md" (.Content will be empty). This is most likely a circular shortcode content loop that should be fixed. If this is just a shortcode calling a slow remote service, try to set "timeout=30000" (or higher, value is in milliseconds) in config.toml.

Before I change the timeout I was wondering why this would crash the build of the entire page. I could understand if the short code failed to render, but it seems odd that the whole page would be lost.

Perhaps the Twitter API is slow to respond when getJSON is called

I am certain that is the basis of the problem, I just wonder why it crashes the whole page build. I increased my timeout to 30s.

That’s a question for a Hugo developer. I’m sure there are reasons for this, I just have no idea what they are.

This has come up before. If you want to read up on the details then please use the search button in the Forum and also search Hugo’s issue tracker on GitHub.

There was some discussion on GitHub aimed towards addressing this issue but in the end it was decided that when getJSON fails then a project’s build should also fail because this is -after all- an ERROR that needs to be fixed and not masked.

Also note that the above is a recap of the discussion (as I remember it). It is not my opinion.

My advice would be to stop fetching external assets this way.

For posterity it is always preferable to store a tweet’s JSON under /data/ and then simply call it via a shortcode as needed.

1 Like

Interesting, would this advice apply to other built in short codes like Instagram too?

Is there guidance on how to “store the tweet’s JSON”?

It is not complicated at all. Hugo’s internal shortcodes use the public oEmbed API.

You can have a look at each internal shortcode over here

For a tweet the oEmbed URL is in the form of: https://api.twitter.com/1/statuses/oembed.json?id=<enter-tweet-id>

It’s the same for Instagram: https://api.instagram.com/oembed/?url=https://instagram.com/p/<insert-post-ID>

Also note that you may want to have a look at the Simple Shortcodes that can be enabled via the privacy config if you plan to do this for Instagram.

Thanks, I think I’ll change the post and avoid the overhead of the Twitter short code all together.