summaryrefslogtreecommitdiffstats
path: root/config/configProvider.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-01-04 18:24:36 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-05-16 18:01:29 +0200
commit241b21b0fd34d91fccb2ce69874110dceae6f926 (patch)
treed4e0118eac7e9c42f065815447a70805f8d6ad3e /config/configProvider.go
parent6aededf6b42011c3039f5f66487a89a8dd65e0e7 (diff)
Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code. Also, * Lower case the default output format names; this is in line with the custom ones (map keys) and how it's treated all the places. This avoids doing `stringds.EqualFold` everywhere. Closes #10896 Closes #10620
Diffstat (limited to 'config/configProvider.go')
-rw-r--r--config/configProvider.go67
1 files changed, 50 insertions, 17 deletions
diff --git a/config/configProvider.go b/config/configProvider.go
index 01a2e8c54..ac00c7476 100644
--- a/config/configProvider.go
+++ b/config/configProvider.go
@@ -14,10 +14,58 @@
package config
import (
+ "time"
+
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/common/types"
+ "github.com/gohugoio/hugo/common/urls"
+ "github.com/gohugoio/hugo/langs"
)
+// AllProvider is a sub set of all config settings.
+type AllProvider interface {
+ Language() *langs.Language
+ Languages() langs.Languages
+ LanguagesDefaultFirst() langs.Languages
+ BaseURL() urls.BaseURL
+ BaseURLLiveReload() urls.BaseURL
+ Environment() string
+ IsMultihost() bool
+ IsMultiLingual() bool
+ NoBuildLock() bool
+ BaseConfig() BaseConfig
+ Dirs() CommonDirs
+ Quiet() bool
+ DirsBase() CommonDirs
+ GetConfigSection(string) any
+ GetConfig() any
+ CanonifyURLs() bool
+ DisablePathToLower() bool
+ RemovePathAccents() bool
+ IsUglyURLs(section string) bool
+ DefaultContentLanguage() string
+ DefaultContentLanguageInSubdir() bool
+ IsLangDisabled(string) bool
+ SummaryLength() int
+ Paginate() int
+ PaginatePath() string
+ BuildExpired() bool
+ BuildFuture() bool
+ BuildDrafts() bool
+ Running() bool
+ PrintUnusedTemplates() bool
+ EnableMissingTranslationPlaceholders() bool
+ TemplateMetrics() bool
+ TemplateMetricsHints() bool
+ LogI18nWarnings() bool
+ CreateTitle(s string) string
+ IgnoreFile(s string) bool
+ NewContentEditor() string
+ Timeout() time.Duration
+ StaticDirs() []string
+ IgnoredErrors() map[string]bool
+}
+
// Provider provides the configuration settings for Hugo.
type Provider interface {
GetString(key string) string
@@ -29,10 +77,11 @@ type Provider interface {
GetStringSlice(key string) []string
Get(key string) any
Set(key string, value any)
+ Keys() []string
Merge(key string, value any)
SetDefaults(params maps.Params)
SetDefaultMergeStrategy()
- WalkParams(walkFn func(params ...KeyParams) bool)
+ WalkParams(walkFn func(params ...maps.KeyParams) bool)
IsSet(key string) bool
}
@@ -44,22 +93,6 @@ func GetStringSlicePreserveString(cfg Provider, key string) []string {
return types.ToStringSlicePreserveString(sd)
}
-// SetBaseTestDefaults provides some common config defaults used in tests.
-func SetBaseTestDefaults(cfg Provider) Provider {
- setIfNotSet(cfg, "baseURL", "https://example.org")
- setIfNotSet(cfg, "resourceDir", "resources")
- setIfNotSet(cfg, "contentDir", "content")
- setIfNotSet(cfg, "dataDir", "data")
- setIfNotSet(cfg, "i18nDir", "i18n")
- setIfNotSet(cfg, "layoutDir", "layouts")
- setIfNotSet(cfg, "assetDir", "assets")
- setIfNotSet(cfg, "archetypeDir", "archetypes")
- setIfNotSet(cfg, "publishDir", "public")
- setIfNotSet(cfg, "workingDir", "")
- setIfNotSet(cfg, "defaultContentLanguage", "en")
- return cfg
-}
-
func setIfNotSet(cfg Provider, key string, value any) {
if !cfg.IsSet(key) {
cfg.Set(key, value)