And deprecate site.IsServer.
Closes #11510
return template.HTML(fmt.Sprintf(`<meta name="generator" content="Hugo %s">`, CurrentVersion.String()))
}
+// IsDevelopment reports whether the current running environment is "development".
+func (i HugoInfo) IsDevelopment() bool {
+ return i.Environment == EnvironmentDevelopment
+}
+
+// IsProduction reports whether the current running environment is "production".
func (i HugoInfo) IsProduction() bool {
return i.Environment == EnvironmentProduction
}
+// IsServer reports whether the built-in server is running.
+func (i HugoInfo) IsServer() bool {
+ return i.conf.Running()
+}
+
+// IsExtended reports whether the Hugo binary is the extended version.
func (i HugoInfo) IsExtended() bool {
return IsExtended
}
// ConfigProvider represents the config options that are relevant for HugoInfo.
type ConfigProvider interface {
Environment() string
+ Running() bool
WorkingDir() string
}
func TestHugoInfo(t *testing.T) {
c := qt.New(t)
- conf := testConfig{environment: "production", workingDir: "/mywork"}
+ conf := testConfig{environment: "production", workingDir: "/mywork", running: false}
hugoInfo := NewInfo(conf, nil)
c.Assert(hugoInfo.Version(), qt.Equals, CurrentVersion.Version())
}
c.Assert(hugoInfo.Environment, qt.Equals, "production")
c.Assert(string(hugoInfo.Generator()), qt.Contains, fmt.Sprintf("Hugo %s", hugoInfo.Version()))
+ c.Assert(hugoInfo.IsDevelopment(), qt.Equals, false)
c.Assert(hugoInfo.IsProduction(), qt.Equals, true)
c.Assert(hugoInfo.IsExtended(), qt.Equals, IsExtended)
+ c.Assert(hugoInfo.IsServer(), qt.Equals, false)
- devHugoInfo := NewInfo(testConfig{environment: "development"}, nil)
+ devHugoInfo := NewInfo(testConfig{environment: "development", running: true}, nil)
+ c.Assert(devHugoInfo.IsDevelopment(), qt.Equals, true)
c.Assert(devHugoInfo.IsProduction(), qt.Equals, false)
+ c.Assert(devHugoInfo.IsServer(), qt.Equals, true)
}
type testConfig struct {
environment string
+ running bool
workingDir string
}
return c.environment
}
+func (c testConfig) Running() bool {
+ return c.running
+}
+
func (c testConfig) WorkingDir() string {
return c.workingDir
}
`hugo.GoVersion`
: (`string`) The Go version used to compile the Hugo binary (e.g., `go1.20.4`). {{< new-in "0.101.0" >}}
+`hugo.IsDevelopment`
+: (`bool`) Returns `true` if `hugo.Environment` is "development".
+
`hugo.IsExtended`
: (`bool`) Returns `true` if the Hugo binary is the extended version.
`hugo.IsProduction`
-: (`bool`) Returns `true` if `hugo.Environment` is set to the production environment.
+: (`bool`) Returns `true` if `hugo.Environment` is "production".
+
+`hugo.IsServer`
+: (`bool`) Returns `true` if the site is being served with Hugo's built-in server.
`hugo.Version`
: (`hugo.VersionString`) The current version of the Hugo binary (e.g., `0.112.1`).
.Site.IsMultiLingual
: whether there are more than one language in this site. See [Multilingual](/content-management/multilingual/) for more information.
-.Site.IsServer
-: a boolean to indicate if the site is being served with Hugo's built-in server. See [`hugo server`](/commands/hugo_server/) for more information.
-
.Site.Language.Lang
: the language code of the current locale (e.g., `en`).
}
// Returns true if we're running in a server.
+// Deprecated: use hugo.IsServer instead
func (s *Site) IsServer() bool {
+ helpers.Deprecated(".Site.IsServer", "Use hugo.IsServer instead.", false)
return s.conf.Internal.Running
}
type testConfig struct {
environment string
+ running bool
workingDir string
}
return c.environment
}
+func (c testConfig) Running() bool {
+ return c.running
+}
+
func (c testConfig) WorkingDir() string {
return c.workingDir
}
Home() Page
// Returns true if we're running in a server.
+ // Deprecated: use hugo.IsServer instead
IsServer() bool
// Returns the server port.
return s.s.Home()
}
+// Deprecated: use hugo.IsServer instead
func (s *siteWrapper) IsServer() bool {
return s.s.IsServer()
}
return identity.KeyValueIdentity{Key: "site", Value: t.l.Lang}
}
+// Deprecated: use hugo.IsServer instead
func (t testSite) IsServer() bool {
return false
}