cfgDir string
}
+// resolveEnvironment sets r.environment if not already set.
+// server indicates whether the server command is running (defaults to development).
+func (r *rootCommand) resolveEnvironment(server bool) {
+ if r.environment != "" {
+ return
+ }
+ if env := os.Getenv("HUGO_ENVIRONMENT"); env != "" {
+ r.environment = env
+ } else if env := os.Getenv("HUGO_ENV"); env != "" {
+ r.environment = env
+ } else if server {
+ r.environment = hugo.EnvironmentDevelopment
+ } else {
+ r.environment = hugo.EnvironmentProduction
+ }
+}
+
func (r *rootCommand) isVerbose() bool {
return r.logger.Level() <= logg.LevelInfo
}
if cfg == nil {
panic("cfg must be set")
}
+ r.resolveEnvironment(false)
cc, _, err := r.commonConfigs.GetOrCreate(key, func(key configKey) (*commonConfig, error) {
var dir string
if r.source != "" {
cfg := config.New()
cfg.Set("renderToMemory", c.r.renderToMemory)
watch := c.r.buildWatch || (c.s != nil && c.s.serverWatch)
- if c.r.environment == "" {
- // We need to set the environment as early as possible because we need it to load the correct config.
- // Check if the user has set it in env.
- if env := os.Getenv("HUGO_ENVIRONMENT"); env != "" {
- c.r.environment = env
- } else if env := os.Getenv("HUGO_ENV"); env != "" {
- c.r.environment = env
- } else {
- if c.s != nil {
- // The server defaults to development.
- c.r.environment = hugo.EnvironmentDevelopment
- } else {
- c.r.environment = hugo.EnvironmentProduction
- }
- }
- }
+ // We need to set the environment as early as possible because we need it to load the correct config.
+ c.r.resolveEnvironment(c.s != nil)
cfg.Set("environment", c.r.environment)
cfg.Set("internal", hmaps.Params{
--- /dev/null
+# Issue 14763
+
+# The staging config should not apply.
+hugo config
+! stdout 'myparam'
+mkdir content
+hugo new content foo.md
+hugo -DF
+! grep 'foo' public/foo/index.html
+
+# The staging config should apply.
+hugo config -e staging
+stdout 'myparam'
+hugo new content bar.md -e staging
+hugo -DF -e staging
+grep 'myparam: foo|' public/bar/index.html
+
+-- config/_default/hugo.toml --
+baseURL = "https://example.com"
+-- config/staging/params.toml --
+myparam = "foo"
+-- layouts/single.html --
+myparam: {{ site.Params.myparam }}|