Repository: gohugoio/hugo (language: go)

Issue:
config/allconfig: Slice of language configs has double the expected elements
Found while addressing #13199.

`(allconfig.Configs).Init` builds `(allconfig.Configs).LanguageConfigSlice` by appending one element per language in an indeterminate order. Then it appends to the slice again, one element per language sorted by language weight.

So this site configuration:

```text
[languages.en]
title = 'TITLE_EN'
weight = 2

[languages.de]
title = 'TITLE_DE'
weight = 1

[languages.fr]
title = 'TITLE_FR'
weight = 3
```

...results in a slice with too many elements, ordered like this:

```text
[en de fr de en fr]
 --------
 indeterminate order
```

We only want the last three so that `(allconfig.Configs).LanguageConfigSlice[0]` returns the config with the lowest weight. 

I looked at our usage of this slice, and from a practical standpoint I think it only affects the output from the `hugo config` command, and even then only under certain conditions.

But we should fix this anyway.

<https://github.com/gohugoio/hugo/blob/master/config/allconfig/allconfig.go#L750-L775>




Discussion / hints:

Fix patch:
diff --git a/config/allconfig/allconfig.go b/config/allconfig/allconfig.go
index 5fe6edcd16f..4d65d5f2bab 100644
--- a/config/allconfig/allconfig.go
+++ b/config/allconfig/allconfig.go
@@ -751,7 +751,6 @@ func (c *Configs) Init() error {
 	var languages langs.Languages
 	defaultContentLanguage := c.Base.DefaultContentLanguage
 	for k, v := range c.LanguageConfigMap {
-		c.LanguageConfigSlice = append(c.LanguageConfigSlice, v)
 		languageConf := v.Languages[k]
 		language, err := langs.NewLanguage(k, defaultContentLanguage, v.TimeZone, languageConf)
 		if err != nil {


Test patch:
diff --git a/config/allconfig/allconfig_integration_test.go b/config/allconfig/allconfig_integration_test.go
index 43d5261d098..162a36cdb89 100644
--- a/config/allconfig/allconfig_integration_test.go
+++ b/config/allconfig/allconfig_integration_test.go
@@ -193,3 +193,25 @@ x
 	b.Assert(err, qt.IsNotNil)
 	b.Assert(err.Error(), qt.Contains, `failed to create config: unknown output format "foo" for kind "home"`)
 }
+
+// Issue 13201
+func TestLanguageConfigSlice(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+disableKinds = ['page','rss','section','sitemap','taxonomy','term']
+[languages.en]
+title = 'TITLE_EN'
+weight = 2
+[languages.de]
+title = 'TITLE_DE'
+weight = 1
+[languages.fr]
+title = 'TITLE_FR'
+weight = 3
+`
+
+	b := hugolib.Test(t, files)
+	b.Assert(b.H.Configs.LanguageConfigSlice[0].Title, qt.Equals, `TITLE_DE`)
+}