summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorJoe Mooring <joe.mooring@veriphor.com>2023-09-29 10:23:08 -0700
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-10-06 16:26:51 +0200
commitd1b4458536372a4f8b60395bf867702571169362 (patch)
tree0529b2a206254412e47dcbadaf97e427d5e696ee /common
parent274852bcf254230fae30bed4883049ec94462e85 (diff)
common/hugo: Add hugo.IsServer and hugo.IsDevelopment
And deprecate site.IsServer. Closes #11510
Diffstat (limited to 'common')
-rw-r--r--common/hugo/hugo.go13
-rw-r--r--common/hugo/hugo_test.go13
2 files changed, 24 insertions, 2 deletions
diff --git a/common/hugo/hugo.go b/common/hugo/hugo.go
index c28dd0b53..1138cf2ac 100644
--- a/common/hugo/hugo.go
+++ b/common/hugo/hugo.go
@@ -78,10 +78,22 @@ func (i HugoInfo) Generator() template.HTML {
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
}
@@ -99,6 +111,7 @@ func (i HugoInfo) Deps() []*Dependency {
// ConfigProvider represents the config options that are relevant for HugoInfo.
type ConfigProvider interface {
Environment() string
+ Running() bool
WorkingDir() string
}
diff --git a/common/hugo/hugo_test.go b/common/hugo/hugo_test.go
index b0279f111..5b4a6f9ad 100644
--- a/common/hugo/hugo_test.go
+++ b/common/hugo/hugo_test.go
@@ -23,7 +23,7 @@ import (
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())
@@ -38,15 +38,20 @@ func TestHugoInfo(t *testing.T) {
}
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
}
@@ -54,6 +59,10 @@ func (c testConfig) Environment() string {
return c.environment
}
+func (c testConfig) Running() bool {
+ return c.running
+}
+
func (c testConfig) WorkingDir() string {
return c.workingDir
}