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 config dir support #5501

Merged
merged 1 commit into from Dec 11, 2018

Conversation

Projects
None yet
1 participant
@bep
Copy link
Member

bep commented Dec 5, 2018

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).

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.

@bep bep force-pushed the bep:config-dir branch 15 times, most recently from 9a5c1a7 to 431fdbe Dec 5, 2018

@bep bep changed the title WORK IN PROGRESS: Add config dir support Add config dir support Dec 10, 2018

@bep bep force-pushed the bep:config-dir branch from 431fdbe to e69c70e Dec 11, 2018

@bep bep force-pushed the bep:config-dir branch from e69c70e to 27cca4c Dec 11, 2018

Add /config dir support
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 #5422

@bep bep force-pushed the bep:config-dir branch from 27cca4c to 7829474 Dec 11, 2018

@bep bep merged commit 7829474 into gohugoio:master Dec 11, 2018

1 of 3 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/travis-ci/push The Travis CI build is in progress
Details
license/cla Contributor License Agreement is signed.
Details

@gcushen gcushen referenced this pull request Jan 5, 2019

Open

Restructure config into more manageable chunks #867

0 of 4 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment