Hey there,
Recently I have faced the challenge of a larger multi-site project in our company to be realized with Hugo. There we thought about a feature we have missed in Hugo called extends
. Similar to other programming languages extends
should extend another configuration/theme/whatever with the current set to reduce redundancies and keep the source more maintainable.
To make it more clear what I am talking about I try to make some example drafts::
root/config.toml
baseurl = "https://example.com/"
languageCode = "en-us"
title = "Project Default"
theme = "base-theme"
enableRobotsTXT = true
root/site_a/config.toml
extends = "../config.toml"
baseurl = "https://site-a.example"
title = "Site A's Title"
would result in:
baseurl = "https://site-a.example"
languageCode = "en-us"
title = "Site A's Title"
theme = "base-theme"
enableRobotsTXT = true
Having extends
available for configuration files would be very nice for multi site projects realized with Hugo.
Further it would be awesome to have a similar approach for themes, so one theme can extend another one. So you could create extensive basic starter themes with a lot of default partials, layouts maybe making special themes for certain output types and maintain them centralized. Although you can override your theme with in the root/layout
folder its often not enough flexibility in my eyes.
As an example:
themes/base-theme
|-- theme.toml
|-- layouts /
|--|--partials /
|--|--|--partial-a.html
|--|--|--partial-b.html
|--|--sitemap.xml
|--|--index.html
|--|--404.html
A simplified version of theme.toml
for base-theme
(example)
name = "base-theme"
min_version = 0.20
themes/theme-a
|-- theme.toml
|-- layouts /
|--|-- example-section /
|--|--|--single.html
|--|--|--list.html
A simplified version of theme.toml
for theme-a
(example)
name = "theme-a"
min_version = 0.20
extends = "base-theme"
Would result in something like:
|-- theme.toml
|-- layouts /
|--|-- example-section /
|--|--|--single.html
|--|--|--list.html
|--|--partials /
|--|--|--partial-a.html
|--|--|--partial-b.html
|--|--sitemap.xml
|--|--index.html
|--|--404.html
Obviously both themes have to exist in the themes folder.
Happy to hear your thoughts about the approach above