diff options
author | Bjørn Erik Pedersen <[email protected]> | 2023-07-08 16:16:06 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-07-08 16:51:48 +0200 |
commit | a481942532c9e9acd841f566291d17db4858cea3 (patch) | |
tree | 4f1d749e6b0df71638d585f17b5ba51066537e60 | |
parent | 0f921ace6f897ba63cdcce7a0ef59c9c615920bd (diff) | |
download | hugo-a481942532c9e9acd841f566291d17db4858cea3.tar.gz hugo-a481942532c9e9acd841f566291d17db4858cea3.zip |
Restore language.disabled config
Fixes #11219
-rw-r--r-- | config/allconfig/allconfig.go | 8 | ||||
-rw-r--r-- | hugolib/config_test.go | 27 | ||||
-rw-r--r-- | langs/config.go | 3 |
3 files changed, 38 insertions, 0 deletions
diff --git a/config/allconfig/allconfig.go b/config/allconfig/allconfig.go index bab15501b..86a887155 100644 --- a/config/allconfig/allconfig.go +++ b/config/allconfig/allconfig.go @@ -274,6 +274,14 @@ func (c *Config) CompileConfig(logger loggers.Logger) error { } disabledLangs[lang] = true } + for lang, language := range c.Languages { + if language.Disabled { + disabledLangs[lang] = true + if lang == c.DefaultContentLanguage { + return fmt.Errorf("cannot disable default content language %q", lang) + } + } + } ignoredErrors := make(map[string]bool) for _, err := range c.IgnoreErrors { diff --git a/hugolib/config_test.go b/hugolib/config_test.go index 567059e68..cdac0fbab 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -1384,3 +1384,30 @@ Home. }) } + +func TestLanguagesDisabled(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +[languages] +[languages.en] +title = "English Title" +[languages.sv] +title = "Swedish Title" +disabled = true +-- layouts/index.html -- +Home. + + +` + b := NewIntegrationTestBuilder( + IntegrationTestConfig{ + T: t, + TxtarString: files, + }, + ).Build() + + b.Assert(len(b.H.Sites), qt.Equals, 1) + +} diff --git a/langs/config.go b/langs/config.go index f60ea94a4..7cca0f5e7 100644 --- a/langs/config.go +++ b/langs/config.go @@ -39,6 +39,9 @@ type LanguageConfig struct { // The language weight. When set to a non-zero value, this will // be the main sort criteria for the language. Weight int + + // Set to true to disable this language. + Disabled bool } func DecodeConfig(m map[string]any) (map[string]LanguageConfig, error) { |