diff --git a/commands/commandeer.go b/commands/commandeer.go index 377f675539b..8e768f045de 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -201,17 +201,37 @@ func (r *rootCommand) ConfigFromProvider(key int32, cfg config.Provider) (*commo if cfg == nil { cfg = config.New() } - if !cfg.IsSet("publishDir") { - cfg.Set("publishDir", "public") - } + if !cfg.IsSet("renderToDisk") { cfg.Set("renderToDisk", true) } if !cfg.IsSet("workingDir") { cfg.Set("workingDir", dir) + } else { + if err := os.MkdirAll(cfg.GetString("workingDir"), 0777); err != nil { + return nil, fmt.Errorf("failed to create workingDir: %w", err) + } + } + + // Load the config first to allow publishDir to be configured in config file. + configs, err := allconfig.LoadConfig( + allconfig.ConfigSourceDescriptor{ + Flags: cfg, + Fs: hugofs.Os, + Filename: r.cfgFile, + ConfigDir: r.cfgDir, + Environment: r.environment, + }, + ) + if err != nil { + return nil, err } - cfg.Set("publishDirStatic", cfg.Get("publishDir")) - cfg.Set("publishDirDynamic", cfg.Get("publishDir")) + + base := configs.Base + + cfg.Set("publishDir", base.PublishDir) + cfg.Set("publishDirStatic", base.PublishDir) + cfg.Set("publishDirDynamic", base.PublishDir) renderStaticToDisk := cfg.GetBool("renderStaticToDisk") @@ -257,21 +277,6 @@ func (r *rootCommand) ConfigFromProvider(key int32, cfg config.Provider) (*commo } - configs, err := allconfig.LoadConfig( - allconfig.ConfigSourceDescriptor{ - Flags: cfg, - Fs: fs.Source, - Filename: r.cfgFile, - ConfigDir: r.cfgDir, - Environment: r.environment, - }, - ) - if err != nil { - return nil, err - } - - base := configs.Base - if !base.C.Clock.IsZero() { // TODO(bep) find a better place for this. htime.Clock = clock.Start(configs.Base.C.Clock) @@ -300,6 +305,7 @@ func (r *rootCommand) HugFromConfig(conf *commonConfig) (*hugolib.HugoSites, err h, _, err := r.hugoSites.GetOrCreate(r.configVersionID.Load(), func(key int32) (*hugolib.HugoSites, error) { conf.mu.Lock() defer conf.mu.Unlock() + depsCfg := deps.DepsCfg{Configs: conf.configs, Fs: conf.fs, Logger: r.logger} return hugolib.NewHugoSites(depsCfg) }) diff --git a/commands/hugobuilder.go b/commands/hugobuilder.go index 5db0b3eff85..28c21a9a7eb 100644 --- a/commands/hugobuilder.go +++ b/commands/hugobuilder.go @@ -954,6 +954,7 @@ func (c *hugoBuilder) loadConfig(cd *simplecobra.Commandeer, running bool) error if err != nil { return err } + c.setConf(conf) if c.onConfigLoaded != nil { if err := c.onConfigLoaded(false); err != nil { diff --git a/config/allconfig/load.go b/config/allconfig/load.go index 2d1a84423ac..51c1bf279b6 100644 --- a/config/allconfig/load.go +++ b/config/allconfig/load.go @@ -208,8 +208,9 @@ func (l configLoader) applyDefaultConfig() error { } func (l configLoader) normalizeCfg(cfg config.Provider) error { - minify := cfg.Get("minify") - if b, ok := minify.(bool); ok && b { + if b, ok := cfg.Get("minifyOutput").(bool); ok && b { + cfg.Set("minify.minifyOutput", true) + } else if b, ok := cfg.Get("minify").(bool); ok && b { cfg.Set("minify", maps.Params{"minifyOutput": true}) } diff --git a/modules/collect.go b/modules/collect.go index c69e7e7ee7f..3340b332778 100644 --- a/modules/collect.go +++ b/modules/collect.go @@ -347,7 +347,7 @@ func (c *collector) addAndRecurse(owner *moduleAdapter, disabled bool) error { moduleConfig := owner.Config() if owner.projectMod { if err := c.applyMounts(Import{}, owner); err != nil { - return fmt.Errorf("failed to apply mounts for project module: %w", err) + return fmt.Errorf("failed to apply mounts for project: %w", err) } } diff --git a/testscripts/commands/hugo__flags.txt b/testscripts/commands/hugo__flags.txt index 46243f8a954..c2ea92c9564 100644 --- a/testscripts/commands/hugo__flags.txt +++ b/testscripts/commands/hugo__flags.txt @@ -1,10 +1,12 @@ # Test the hugo command. -hugo --baseURL http://example.com/ --destination ${WORK}/newpublic --clock 2021-11-06T22:30:00.00+09:00 -e staging --config ${WORK}/myconfig --configDir ${WORK}/myconfigdir -s mysource +hugo --baseURL http://example.com/ --minify --destination ${WORK}/newpublic --clock 2021-11-06T22:30:00.00+09:00 -e staging --config ${WORK}/myconfig --configDir ${WORK}/myconfigdir -s mysource stdout 'Pages.*|1' stdout 'Total in' grep 'Home: http://example.com/, Time: 2021-11-06' newpublic/index.html grep 'Environment: staging, foo: bar, bar: baz' newpublic/index.html +# Verify that it's minified. +grep 'Home' newpublic/index.html hugo --quiet ! stdout . @@ -17,7 +19,9 @@ foo = "bar" -- myconfigdir/_default/params.toml -- bar = "baz" -- mysource/layouts/index.html -- + Home: {{ .Permalink }}, Time: {{ now }} + Environment: {{ hugo.Environment }}, foo: {{ .Site.Params.foo }}, bar: {{ .Site.Params.bar }} -- mysource/layouts/_default/single.html -- Title: {{ .Title }} diff --git a/testscripts/commands/hugo__publishdir_in_config.txt b/testscripts/commands/hugo__publishdir_in_config.txt new file mode 100644 index 00000000000..e57d4ad2fe1 --- /dev/null +++ b/testscripts/commands/hugo__publishdir_in_config.txt @@ -0,0 +1,12 @@ +# Test the hugo command. + +hugo + +grep 'Home' newpublic/index.html + +-- hugo.toml -- +baseURL = "http://example.org/" +disableKinds = ["RSS", "sitemap", "robotsTXT", "404", "taxonomy", "term"] +publishDir = "newpublic" +-- layouts/index.html -- +Home.