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.
This commit is contained in:
Khayyam Saleem
2022-05-30 09:12:41 -04:00
committed by Bjørn Erik Pedersen
parent 66da1b7b2f
commit 09ac733381
3 changed files with 10 additions and 4 deletions

View File

@@ -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,
}
}

View File

@@ -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()))