-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a /config dir #5422
Comments
Was just thinking about it yesterday having to manage many menu items from the I assume we can add as many files as we want in order to create a config objects. This is not limited to the one you mentioned?
What do you mean by clever ? I just wish the |
No, the scope is endless.
I should be more clear (and less clever):
|
Love this. Slightly uncomfortable with environment variable defaults, but I suppose that if one went to the trouble of using them at all, they'd be aware of the defaults. Question (hopefully not too off topic). Would it be possible to do a build with no config at all? Right now I believe Hugo looks for a config file, no matter how minimal (even empty). Would be cool to be zero config with nothing required other than a minimal layouts/index.html file. Then Hugo could be "The world’s fastest ZERO CONFIG framework for building websites" :) |
You mean the development/production logic? Yes, it's strictly a little outside the scope of this issue, but doing it at the same time is considerably cheaper. And the number of overrides should be very small (my example is bad) -- and I think this makes it more explicit than the |
Yes I suspect environment only key/value pair will be limited to This will be an awesome improvements on the way Hugo currently deals with config! 🤩 |
Yes, I meant that I explicitly set environment variables and that control is predictable to me. Not a big deal though. |
Note that if we add |
An important addendum to the above, having thought about this a little. One of the big benefactors of this feature is sites with many languages (and with that really a long So, for the config
├── _default
│ ├── config.toml
│ ├── languages.en.toml
│ ├── languages.toml
│ └── mediaTypes.toml
└── production
├── config.toml
├── mediaTypes.toml
└── related.toml So in the above, |
But could we still have "standalone file" config for each languages ( |
I think it helps to think about this issue as "very technical". |
@regisphilibert I've dived into this issue now, and it does not look too hard. There is one issue that you can help me with. I will think out loud a little. It is related to your last comment; I think we need to be a little more clever when it comes to language handling. Taken from the Hugo docs site:
(I have made a note to create I have put the above to wrap my head around and make sure we can represent this in all the config formats. So, only JSON allows arrays without a root, so we need to avoid (or work around) that. With that, I was thinking that the 2 above examples could look like:
[[main]]
name = "函数"
weight = 30
[[main]]
name = "变量"
weight = 35
[[sidebar]]
name = "变量"
weight = 35 This means that if you have several menus, you need to put them in the same file for that language.
description = "A description in that language" The above makes sense to me ...? |
Of course. The important part here is that multilingual projects will not loose this "file isolation" feature by having to dump all their config objets into one "language config" file.
Agree! Current key is counter-intuitive (I always forget it's supposed to be singular).
Not sure how I can help beside supporting this logic ( |
That's the help I needed. |
@budparr and @regisphilibert -- given the "config tree" below: config
├── _default
│ ├── config.toml
│ ├── languages.toml
│ ├── menus
│ │ ├── menu.en.toml
│ │ └── menu.zh.toml
│ ├── params.1.toml
│ └── params.2.toml
└── development
└── params.2.toml Do you understand the meaning of The thing is, the main rule has to be that if Also note that the |
I'm guessing this is a way of defining a group of params to be merged vs another group to be left as is. Let me share a personal yet very common (I think) use case to make sure I'm following. Using the CLI command By what I understand this is how I would replicate this behaviour using the new config directory feature:
Am I following? |
Yes. The main motivation here is that if you have 120 generic params + 1 environment specific param, you don't want to repeat the 121 params in every environment. Also note that this is a general pattern; you could also do |
So still with the previous use case I could not do the following:
And expect the params common to both env to be set in the production env. as well. If this is a technical decision then I'm happy to trade this very light complexification to be able to manage configuration with directories and filenames. If this is a usability decision on the other hand, I'd like to understand the logic behind it as it presently escapes me. |
Your last example will not work. This is merged on "file level": We pick the most specific file, e.g. Note that it would be technically possible to implement it so your particular example would work. But that would break other examples/use cases, examples being that I would want a different set of languages, output formats, whatever, in the different environments, so we cannot merge blindly. |
But I think this could be solved differently by having Hugo merge blindly while having the user exercise a much expected discipline of never putting in Again my suggestion may not be sustainable, but as I cannot think of a use case for which this basic discipline would not suffice, I must insist on asking you or other users if this "blind merging" could not be OK, providing it does not complicate your task of course. This would avoid introducing and documenting the file numbering system and make the new config management all the more intuitive by matching the behaviour of |
Here's the use case I can think of to defend the numbering file implementation: I have 5 environments, I need a certain output format in all of them but one. This means with blind merging, I cannot put it in I'm suspecting this use case will be rare and I'm afraid we may complexify a feature for the vast majority of use cases only to benefit a very few. |
I will sleep on it. |
@regisphilibert I have slept, and you are right. I was thinking too hard about this. If we for some really good reason need "my variant" we could add some naming standard for that case later. Thanks for the input, always appreciated. |
Anytime, glad I could help. |
This commit adds support for a configuration directory (default `config`). The different pieces in this puzzle are: * A new `--environment` (or `-e`) flag. This can also be set with the `HUGO_ENVIRONMENT` OS environment variable. The value for `environment` defaults to `production` when running `hugo` and `development` when running `hugo server`. You can set it to any value you want (e.g. `hugo server -e "Sensible Environment"`), but as it is used to load configuration from the file system, the letter case may be important. You can get this value in your templates with `{{ hugo.Environment }}`. * A new `--configDir` flag (defaults to `config` below your project). This can also be set with `HUGO_CONFIGDIR` OS environment variable. If the `configDir` exists, the configuration files will be read and merged on top of each other from left to right; the right-most value will win on duplicates. Given the example tree below: If `environment` is `production`, the left-most `config.toml` would be the one directly below the project (this can now be omitted if you want), and then `_default/config.toml` and finally `production/config.toml`. And since these will be merged, you can just provide the environment specific configuration setting in you production config, e.g. `enableGitInfo = true`. The order within the directories will be lexical (`config.toml` and then `params.toml`). ```bash config ├── _default │ ├── config.toml │ ├── languages.toml │ ├── menus │ │ ├── menus.en.toml │ │ └── menus.zh.toml │ └── params.toml ├── development │ └── params.toml └── production ├── config.toml └── params.toml ``` Some configuration maps support the language code in the filename (e.g. `menus.en.toml`): `menus` (`menu` also works) and `params`. Also note that the only folders with "a meaning" in the above listing is the top level directories below `config`. The `menus` sub folder is just added for better organization. We use `TOML` in the example above, but Hugo also supports `JSON` and `YAML` as configuration formats. These can be mixed. Fixes gohugoio#5422
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This is issue is vaguely described other places but is long over due. This description should be concrete enough to implement:
configDir
setting, default/config
.--environment
flag (and setting), which defaults toproduction
forhugo
anddevelopment
forhugo server
config.toml
A sample tree could look like this:
config.toml
allows top level keys (baseURL
) etc. to be set per environment.languages.toml
could look like this:There are no clever merging inside /config -- we pick the most specific file (for production and mediaTypes in the example above, we pick the file below /production).
This will (in its first iteration) be a project only thing.
/cc @regisphilibert @budparr @kaushalmodi
The text was updated successfully, but these errors were encountered: