]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
commands: Add --lang to hugo config
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 1 Jun 2023 07:53:40 +0000 (09:53 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 1 Jun 2023 08:49:21 +0000 (10:49 +0200)
Fixes #11057

commands/config.go
config/allconfig/allconfig.go
config/allconfig/integration_test.go
hugolib/config_test.go

index 44c5a1c32eba76b4eba8784a4c47f67c88769bc5..fe20196aace1ab3292160cec69d387ddb72c72f8 100644 (file)
@@ -23,6 +23,7 @@ import (
        "time"
 
        "github.com/bep/simplecobra"
+       "github.com/gohugoio/hugo/config/allconfig"
        "github.com/gohugoio/hugo/modules"
        "github.com/gohugoio/hugo/parser"
        "github.com/gohugoio/hugo/parser/metadecoders"
@@ -42,6 +43,7 @@ type configCommand struct {
        r *rootCommand
 
        format string
+       lang   string
 
        commands []simplecobra.Commander
 }
@@ -59,7 +61,16 @@ func (c *configCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
        if err != nil {
                return err
        }
-       config := conf.configs.Base
+       var config *allconfig.Config
+       if c.lang != "" {
+               var found bool
+               config, found = conf.configs.LanguageConfigMap[c.lang]
+               if !found {
+                       return fmt.Errorf("language %q not found", c.lang)
+               }
+       } else {
+               config = conf.configs.LanguageConfigSlice[0]
+       }
 
        var buf bytes.Buffer
        dec := json.NewEncoder(&buf)
@@ -100,6 +111,7 @@ func (c *configCommand) Init(cd *simplecobra.Commandeer) error {
        cmd.Short = "Print the site configuration"
        cmd.Long = `Print the site configuration, both default and custom settings.`
        cmd.Flags().StringVar(&c.format, "format", "toml", "preferred file format (toml, yaml or json)")
+       cmd.Flags().StringVar(&c.lang, "lang", "", "the language to display config for. Defaults to the first language defined.")
        applyLocalFlagsBuildConfig(cmd, c.r)
 
        return nil
index 40bb2221d472d0287bf95014f08997b1a77098fe..ade9607ddedebbbb414b41ce38d6c93801c88f56 100644 (file)
@@ -664,6 +664,11 @@ func (c *Configs) Init() error {
                }
        }
 
+       // Transfer the changed mounts to the language versions (all share the same mount set, but can be displayed in different languages).
+       for _, l := range c.LanguageConfigSlice {
+               l.Module.Mounts = c.Base.Module.Mounts
+       }
+
        return nil
 }
 
index e96dbd296894ef30998538ee08f4dde100f59c07..2de83eaa4cc33f80fdcabcee18693f9f6bb2ae14 100644 (file)
@@ -60,7 +60,7 @@ Title: {{ .Title }}
 
        b.Assert(enConcp.BaseURL().String(), qt.Equals, "https://example.com")
        modConf := enConf.Module
-       b.Assert(modConf.Mounts, qt.HasLen, 2)
+       b.Assert(modConf.Mounts, qt.HasLen, 8)
        b.Assert(modConf.Mounts[0].Source, qt.Equals, filepath.FromSlash("content/en"))
        b.Assert(modConf.Mounts[0].Target, qt.Equals, "content")
        b.Assert(modConf.Mounts[0].Lang, qt.Equals, "en")
index 245180e12852a3711299a9f68d9a70bdeb978a21..3b137d8d67358f47857a70e43a288540a2e41996 100644 (file)
@@ -1172,8 +1172,7 @@ Home.
                },
        ).Build()
 
-       modConf := b.H.Configs.Base.Module
-
-       b.Assert(modConf.Mounts, qt.HasLen, 7)
+       b.Assert(b.H.Configs.Base.Module.Mounts, qt.HasLen, 7)
+       b.Assert(b.H.Configs.LanguageConfigSlice[0].Module.Mounts, qt.HasLen, 7)
 
 }