diff options
author | Joshua Wong <joshwonghc@gmail.com> | 2020-02-25 19:58:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-25 19:58:07 +0300 |
commit | 1352bc880df4cd25eff65843973fcc0dd21b6304 (patch) | |
tree | 691d52ed2bd5971be3190a8f282e84c05a974917 /common | |
parent | d184e5059c72c15df055192b01da0fd8c5b0fc5c (diff) |
Add hugo.IsProduction function
Fixes #6873
Diffstat (limited to 'common')
-rw-r--r-- | common/hugo/hugo.go | 4 | ||||
-rw-r--r-- | common/hugo/hugo_test.go | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/common/hugo/hugo.go b/common/hugo/hugo.go index 62d923bf0..037880836 100644 --- a/common/hugo/hugo.go +++ b/common/hugo/hugo.go @@ -54,6 +54,10 @@ func (i Info) Generator() template.HTML { return template.HTML(fmt.Sprintf(`<meta name="generator" content="Hugo %s" />`, CurrentVersion.String())) } +func (i Info) IsProduction() bool { + return i.Environment == EnvironmentProduction +} + // NewInfo creates a new Hugo Info object. func NewInfo(environment string) Info { if environment == "" { diff --git a/common/hugo/hugo_test.go b/common/hugo/hugo_test.go index 5be575b62..8840a9e9e 100644 --- a/common/hugo/hugo_test.go +++ b/common/hugo/hugo_test.go @@ -31,5 +31,9 @@ func TestHugoInfo(t *testing.T) { c.Assert(hugoInfo.BuildDate, qt.Equals, buildDate) c.Assert(hugoInfo.Environment, qt.Equals, "production") c.Assert(string(hugoInfo.Generator()), qt.Contains, fmt.Sprintf("Hugo %s", hugoInfo.Version())) + c.Assert(hugoInfo.IsProduction(), qt.Equals, true) + + devHugoInfo := NewInfo("development") + c.Assert(devHugoInfo.IsProduction(), qt.Equals, false) } |