hugo icon indicating copy to clipboard operation
hugo copied to clipboard

Enable config `outputs` to be merged like other config sections

Open gcushen opened this issue 2 years ago • 1 comments

Users expect that when they load a module, its output is added to the site, and conversely when a module is unloaded, that its output is removed from the site (without also having to manually add or remove it from their outputs too).

For example, when users load a Netlify module they expect it to automatically output a headers file for Netlify, whereas when the module is unloaded, they expect it to automatically remove its headers output from the outputs config: https://github.com/wowchemy/wowchemy-hugo-themes/discussions/2800

However, currently Hugo does not allow outputs to be merged like other config sections: https://gohugo.io/getting-started/configuration/#merge-configuration-from-themes

gcushen avatar Aug 25 '22 18:08 gcushen

So, that the outputs is missing from that list is a misconfiguration, not sure why that happened, and we should certainly fix that, but even with that I'm not totally sure what we do with slices.

[outputs]
  home = ['HTML']
  page = ['HTML']

I don't think (for good reason) there are any way to add values to those slices from a theme (even if we got the config in order), but it should at least serve as a good default for people with nothing.

bep avatar Aug 25 '22 20:08 bep

I don't think (for good reason) there are any way to add values to those slices from a theme (even if we got the config in order)

@bep Could you elaborate on this good reason? That might help to prepare a PR to resolve this issue.

It seems that both mediaTypes and outputFormats are merged explicitly in https://github.com/gohugoio/hugo/blob/c4f3a46ce6a4ce1890a26be31267838c6a065516/hugolib/site.go#L434 to https://github.com/gohugoio/hugo/blob/c4f3a46ce6a4ce1890a26be31267838c6a065516/hugolib/site.go#L461 using https://github.com/gohugoio/hugo/blob/c4f3a46ce6a4ce1890a26be31267838c6a065516/media/mediaType.go#L457 and https://github.com/gohugoio/hugo/blob/c4f3a46ce6a4ce1890a26be31267838c6a065516/output/outputFormat.go#L303

So my first idea would be to merge outputs just like these in the same place as well. Do you have something in mind that would invalidate this approach?

istr avatar Jan 15 '23 18:01 istr