HUGO

Go Plugins to extend Hugo

We are building an extensive documentation centre that requires loading static files from the disk in particular programming languages, parsing those files and pick up bits of comments and parse them in YML to pick apart fields.

We’ve been fighting with Hugo to get Shortcode to provide that functionality but the closest we’ve got to is brittle regexes and they aren’t very good at this point.

So we are exploring writing these custom processors in Go. From various threads that I’ve seen, we can’t just create Go functions and expose them to Go Template or Markdown, and the general advise is to clone Hugo to add our custom functions;

Now a couple of questions;

  • Is cloning Hugo what’s needed here? Do people generally do that, who have advanced(?) use cases like above? Can you provide example repos that we can use as inspiration?
  • Does Hugo support Go Plugins (like Nakama) that we can write our custom Go functions as a plugin and not have to fork Hugo?
  • Any other advise/comments/directions?

Thanks!

There is no support for external plugins.

Support was not implemented for security reasons as per Add exec shortcode · Issue #796 · gohugoio/hugo · GitHub

Your only option is to fork Hugo.

Also see External plugin from template · Issue #8511 · gohugoio/hugo · GitHub for a more recent proposal.

Thanks so much for the prompt reply @onedrawingperday.

Do you have best practices on how one would go about adding/changing Hugo source such that comes upgrade time it’s not too painful? Are there examples repos you recommend to take inspiration from?

Thanks!

I am not aware of customized Hugo forks.
Perhaps someone else can offer advice.