gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.76k stars 7.53k forks source link

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

Open gcushen opened 2 years ago

gcushen commented 2 years ago

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

bep commented 2 years ago

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.

istr commented 1 year ago

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?