2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2016-08-07 08:03:03 -04:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
package config
|
2016-09-15 03:32:52 -04:00
|
|
|
|
2018-05-04 04:18:45 -04:00
|
|
|
import (
|
2021-06-09 04:58:18 -04:00
|
|
|
"github.com/gohugoio/hugo/common/maps"
|
2019-09-10 05:26:34 -04:00
|
|
|
"github.com/gohugoio/hugo/common/types"
|
2018-05-04 04:18:45 -04:00
|
|
|
)
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
// Provider provides the configuration settings for Hugo.
|
|
|
|
type Provider interface {
|
2016-08-07 08:03:03 -04:00
|
|
|
GetString(key string) string
|
2016-09-15 03:32:52 -04:00
|
|
|
GetInt(key string) int
|
2016-10-24 07:45:30 -04:00
|
|
|
GetBool(key string) bool
|
2021-06-09 04:58:18 -04:00
|
|
|
GetParams(key string) maps.Params
|
2022-03-17 17:03:27 -04:00
|
|
|
GetStringMap(key string) map[string]any
|
2016-08-07 08:03:03 -04:00
|
|
|
GetStringMapString(key string) map[string]string
|
2018-01-25 11:03:29 -05:00
|
|
|
GetStringSlice(key string) []string
|
2022-03-17 17:03:27 -04:00
|
|
|
Get(key string) any
|
|
|
|
Set(key string, value any)
|
|
|
|
Merge(key string, value any)
|
2021-06-22 03:53:37 -04:00
|
|
|
SetDefaults(params maps.Params)
|
2021-06-09 04:58:18 -04:00
|
|
|
SetDefaultMergeStrategy()
|
|
|
|
WalkParams(walkFn func(params ...KeyParams) bool)
|
2017-02-04 22:20:06 -05:00
|
|
|
IsSet(key string) bool
|
2016-10-24 07:45:30 -04:00
|
|
|
}
|
2018-05-04 04:18:45 -04:00
|
|
|
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
// GetStringSlicePreserveString returns a string slice from the given config and key.
|
|
|
|
// It differs from the GetStringSlice method in that if the config value is a string,
|
|
|
|
// we do not attempt to split it into fields.
|
|
|
|
func GetStringSlicePreserveString(cfg Provider, key string) []string {
|
|
|
|
sd := cfg.Get(key)
|
2019-09-10 05:26:34 -04:00
|
|
|
return types.ToStringSlicePreserveString(sd)
|
2018-05-04 04:18:45 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
// SetBaseTestDefaults provides some common config defaults used in tests.
|
|
|
|
func SetBaseTestDefaults(cfg Provider) {
|
|
|
|
cfg.Set("resourceDir", "resources")
|
|
|
|
cfg.Set("contentDir", "content")
|
|
|
|
cfg.Set("dataDir", "data")
|
|
|
|
cfg.Set("i18nDir", "i18n")
|
|
|
|
cfg.Set("layoutDir", "layouts")
|
|
|
|
cfg.Set("assetDir", "assets")
|
|
|
|
cfg.Set("archetypeDir", "archetypes")
|
|
|
|
cfg.Set("publishDir", "public")
|
|
|
|
}
|