Is there a way to make a reusable partial/component that could be shared easily?

I’m about to add schema.org support for Breadcrumbs to my site. Is there a way to package up something like to make it easy for other people to use? I’ve only found people sharing code snippets.

I’ve done schema.org support in Ruby, and so to me, it’s natural for this to exist as its own component, somehow.

I’m just not too familiar with the options we have for distributing reusable “components” for Hugo. I imagine that a reusable Breadcrumb function would accept a list of Breadcrumb maps, each with the required attributes.

I’m using generic terms here, because I don’t know if it’d be possible (or desirable) to code this in Go, Template, or something else.

Thanks!

“Theme components” may be what you are searching for.

1 Like

That’s not bad. So if I understand this, I could publish a repo with a “theme” containing e.g. just layouts/partials. And then, people could use it by adding it to a theme list.

Yes, that is the way to go for re-usable partials. And you need to initialize your repository as a Hugo module.

1 Like

In fact you have two ways to add theme components:

  • as Hugo module (I find this way a bit complicated)
  • as a Git submodule (this is the method I recommend, especially to start with theme components)
1 Like

@dogweather

See this simple example of components shared as a Hugo Module.

If you elect to share your work, either make a commitment to its long term maintenance and support, or advise users to the contrary in your README.

1 Like