diff options
author | Khayyam Saleem <hello@khayyam.me> | 2022-05-30 09:12:41 -0400 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-06-14 09:48:45 +0200 |
commit | 09ac73338198ceb143c1e5edc5859ab735cd80bb (patch) | |
tree | f099b8fa2f555362fa2e5450a2f5fc51da397504 /common | |
parent | 66da1b7b2f8a8bd26ed4a50a54f64489f116f484 (diff) |
common: Add hugo.GoVersion
Closes #9849. This enables `hugo.GoVersion` in templates to access the
version of Go that the Hugo binary was built with.
Diffstat (limited to 'common')
-rw-r--r-- | common/hugo/hugo.go | 6 | ||||
-rw-r--r-- | common/hugo/hugo_test.go | 1 |
2 files changed, 7 insertions, 0 deletions
diff --git a/common/hugo/hugo.go b/common/hugo/hugo.go index 2c6e5f2a0..d78564a67 100644 --- a/common/hugo/hugo.go +++ b/common/hugo/hugo.go @@ -53,6 +53,9 @@ type Info struct { // It can be any string, but it will be all lower case. Environment string + // version of go that the Hugo binary was built with + GoVersion string + deps []*Dependency } @@ -87,12 +90,14 @@ func NewInfo(environment string, deps []*Dependency) Info { var ( commitHash string buildDate string + goVersion string ) bi := getBuildInfo() if bi != nil { commitHash = bi.Revision buildDate = bi.RevisionTime + goVersion = bi.GoVersion } return Info{ @@ -100,6 +105,7 @@ func NewInfo(environment string, deps []*Dependency) Info { BuildDate: buildDate, Environment: environment, deps: deps, + GoVersion: goVersion, } } diff --git a/common/hugo/hugo_test.go b/common/hugo/hugo_test.go index 3bc95684b..f2ad0f5c1 100644 --- a/common/hugo/hugo_test.go +++ b/common/hugo/hugo_test.go @@ -32,6 +32,7 @@ func TestHugoInfo(t *testing.T) { if bi != nil { c.Assert(hugoInfo.CommitHash, qt.Equals, bi.Revision) c.Assert(hugoInfo.BuildDate, qt.Equals, bi.RevisionTime) + c.Assert(hugoInfo.GoVersion, qt.Equals, bi.GoVersion) } c.Assert(hugoInfo.Environment, qt.Equals, "production") c.Assert(string(hugoInfo.Generator()), qt.Contains, fmt.Sprintf("Hugo %s", hugoInfo.Version())) |