URI: 
       Fix multiple languages in HUGO_DISABLELANGUAGES - hugo - [fork] hugo port for 9front
  HTML git clone git@git.drkhsh.at/hugo.git
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
   DIR commit 7f058b8bab947db98939ed27a7c2a08468323d08
   DIR parent 575d7f8068082bf75ee4939fafa186c796a06a0c
  HTML Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
       Date:   Thu, 27 Jul 2023 13:00:01 +0200
       
       Fix multiple languages in HUGO_DISABLELANGUAGES
       
       Fixes #11278
       
       Diffstat:
         M config/allconfig/load.go            |      30 +++++++++++++++++++++++++-----
         M hugolib/config_test.go              |      41 +++++++++++++++++++++++++++++++
       
       2 files changed, 66 insertions(+), 5 deletions(-)
       ---
   DIR diff --git a/config/allconfig/load.go b/config/allconfig/load.go
       @@ -297,14 +297,20 @@ func (l configLoader) applyOsEnvOverrides(environ []string) error {
                                if nestedKey != "" {
                                        owner[nestedKey] = env.Value
                                } else {
       -                                var val any = env.Value
       -                                if _, ok := allDecoderSetups[env.Key]; ok {
       +                                var val any
       +                                key := strings.ReplaceAll(env.Key, delim, ".")
       +                                _, ok := allDecoderSetups[key]
       +                                if ok {
                                                // A map.
       -                                        val, err = metadecoders.Default.UnmarshalStringTo(env.Value, map[string]interface{}{})
       +                                        if v, err := metadecoders.Default.UnmarshalStringTo(env.Value, map[string]interface{}{}); err == nil {
       +                                                val = v
       +                                        }
                                        }
       -                                if err == nil {
       -                                        l.cfg.Set(strings.ReplaceAll(env.Key, delim, "."), val)
       +                                if val == nil {
       +                                        // A string.
       +                                        val = l.envStringToVal(key, env.Value)
                                        }
       +                                l.cfg.Set(key, val)
                                }
                        }
                }
       @@ -312,6 +318,20 @@ func (l configLoader) applyOsEnvOverrides(environ []string) error {
                return nil
        }
        
       +func (l *configLoader) envStringToVal(k, v string) any {
       +        switch k {
       +        case "disablekinds", "disablelanguages":
       +                if strings.Contains(v, ",") {
       +                        return strings.Split(v, ",")
       +                } else {
       +                        return strings.Fields(v)
       +                }
       +        default:
       +                return v
       +        }
       +
       +}
       +
        func (l *configLoader) loadConfigMain(d ConfigSourceDescriptor) (config.LoadConfigResult, modules.ModulesConfig, error) {
                var res config.LoadConfigResult
        
   DIR diff --git a/hugolib/config_test.go b/hugolib/config_test.go
       @@ -259,6 +259,47 @@ sub: map[sub1:sub1en]
        
        }
        
       +func TestDisableRootSlicesFromEnv(t *testing.T) {
       +        t.Parallel()
       +
       +        files := `
       +-- hugo.toml --
       +baseURL = "https://example.com"
       +defaultContentLanguage = "en"
       +defaultContentLanguageInSubdir = true
       +[languages]
       +[languages.en]
       +weight = 1
       +[languages.sv]
       +weight = 2
       +[languages.no]
       +weight = 3
       +
       +-- layouts/index.html --
       +Home.
       +`
       +
       +        for _, delim := range []string{" ", ","} {
       +                environ := []string{"HUGO_DISABLELANGUAGES=sv no", "HUGO_DISABLEKINDS=taxonomy term"}
       +                for i, v := range environ {
       +                        environ[i] = strings.ReplaceAll(v, " ", delim)
       +                }
       +                b := NewIntegrationTestBuilder(
       +                        IntegrationTestConfig{
       +                                T:           t,
       +                                TxtarString: files,
       +                                Environ:     environ,
       +                                BuildCfg:    BuildCfg{SkipRender: true},
       +                        },
       +                ).Build()
       +
       +                conf := b.H.Configs.Base
       +                b.Assert(conf.DisableLanguages, qt.DeepEquals, []string{"sv", "no"})
       +                b.Assert(conf.DisableKinds, qt.DeepEquals, []string{"taxonomy", "term"})
       +        }
       +
       +}
       +
        func TestLoadMultiConfig(t *testing.T) {
                t.Parallel()