]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Make language merging of markup etc. config without values in the root
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 20 May 2023 09:17:43 +0000 (11:17 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 20 May 2023 10:40:32 +0000 (12:40 +0200)
Updates #10953

config/allconfig/allconfig.go
config/allconfig/load.go
hugolib/config_test.go

index 22e9f1deb4011929b0ac302672845ccfa0a4ce92..4886aa561388f580a4c21bdb6d2a1496263d9498 100644 (file)
@@ -748,8 +748,13 @@ func FromLoadConfigResult(fs afero.Fs, res config.LoadConfigResult) (*Configs, e
                                                }
                                        }
                                } else {
-                                       // Apply new values to the root.
-                                       differentRootKeys = append(differentRootKeys, "")
+                                       switch vv.(type) {
+                                       case maps.Params:
+                                               differentRootKeys = append(differentRootKeys, kk)
+                                       default:
+                                               // Apply new values to the root.
+                                               differentRootKeys = append(differentRootKeys, "")
+                                       }
                                }
                        }
                        differentRootKeys = helpers.UniqueStringsSorted(differentRootKeys)
index 51c1bf279b69188db570f08df0fd1088e540791f..6ae26d28eab31fb1b3bb900a566a5f48d3595cc1 100644 (file)
@@ -214,22 +214,6 @@ func (l configLoader) normalizeCfg(cfg config.Provider) error {
                cfg.Set("minify", maps.Params{"minifyOutput": true})
        }
 
-       // Simplify later merge.
-       languages := cfg.GetStringMap("languages")
-       for _, v := range languages {
-               switch m := v.(type) {
-               case maps.Params:
-                       // params have merge strategy deep by default.
-                       // The languages config key has strategy none by default.
-                       // This means that if these two sections does not exist on the left side,
-                       // they will not get merged in, so just create some empty maps.
-                       if _, ok := m["params"]; !ok {
-                               m["params"] = maps.Params{}
-                       }
-               }
-
-       }
-
        return nil
 }
 
index 1d4372e41f57b331581d9f7e08dcf89a0e562586..24275025ccc7e68d50995a5383ae1a91b48d2e66 100644 (file)
@@ -898,6 +898,59 @@ mainSections: []
 
 }
 
+func TestConfigMergeLanguageDeepEmptyLefSide(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+[params]
+p1 = "p1base"
+[languages.en]
+languageCode = 'en-US'
+languageName = 'English'
+weight = 1
+[languages.en.markup.goldmark.extensions.typographer]
+leftDoubleQuote = '&ldquo;'   # default &ldquo;
+rightDoubleQuote = '&rdquo;'  # default &rdquo;
+
+[languages.de]
+languageCode = 'de-DE'
+languageName = 'Deutsch'
+weight = 2
+[languages.de.params]
+p1 = "p1de"
+[languages.de.markup.goldmark.extensions.typographer]
+leftDoubleQuote = '&laquo;'   # default &ldquo;
+rightDoubleQuote = '&raquo;'  # default &rdquo;
+-- layouts/index.html --
+{{ .Content }}
+p1: {{ site.Params.p1 }}|
+-- content/_index.en.md --
+---
+title: "English Title"
+---
+A "quote" in English.
+-- content/_index.de.md --
+---
+title: "Deutsch Title"
+---
+Ein "Zitat" auf Deutsch.
+
+
+
+`
+       b := NewIntegrationTestBuilder(
+               IntegrationTestConfig{
+                       T:           t,
+                       TxtarString: files,
+               },
+       ).Build()
+
+       b.AssertFileContent("public/index.html", "p1: p1base", "<p>A &ldquo;quote&rdquo; in English.</p>")
+       b.AssertFileContent("public/de/index.html", "p1: p1de", "<p>Ein &laquo;Zitat&raquo; auf Deutsch.</p>")
+
+}
+
 func TestConfigLegacyValues(t *testing.T) {
        t.Parallel()