mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
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:
parent
66da1b7b2f
commit
09ac733381
3 changed files with 10 additions and 4 deletions
|
@ -53,6 +53,9 @@ type Info struct {
|
||||||
// It can be any string, but it will be all lower case.
|
// It can be any string, but it will be all lower case.
|
||||||
Environment string
|
Environment string
|
||||||
|
|
||||||
|
// version of go that the Hugo binary was built with
|
||||||
|
GoVersion string
|
||||||
|
|
||||||
deps []*Dependency
|
deps []*Dependency
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,12 +90,14 @@ func NewInfo(environment string, deps []*Dependency) Info {
|
||||||
var (
|
var (
|
||||||
commitHash string
|
commitHash string
|
||||||
buildDate string
|
buildDate string
|
||||||
|
goVersion string
|
||||||
)
|
)
|
||||||
|
|
||||||
bi := getBuildInfo()
|
bi := getBuildInfo()
|
||||||
if bi != nil {
|
if bi != nil {
|
||||||
commitHash = bi.Revision
|
commitHash = bi.Revision
|
||||||
buildDate = bi.RevisionTime
|
buildDate = bi.RevisionTime
|
||||||
|
goVersion = bi.GoVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
return Info{
|
return Info{
|
||||||
|
@ -100,6 +105,7 @@ func NewInfo(environment string, deps []*Dependency) Info {
|
||||||
BuildDate: buildDate,
|
BuildDate: buildDate,
|
||||||
Environment: environment,
|
Environment: environment,
|
||||||
deps: deps,
|
deps: deps,
|
||||||
|
GoVersion: goVersion,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ func TestHugoInfo(t *testing.T) {
|
||||||
if bi != nil {
|
if bi != nil {
|
||||||
c.Assert(hugoInfo.CommitHash, qt.Equals, bi.Revision)
|
c.Assert(hugoInfo.CommitHash, qt.Equals, bi.Revision)
|
||||||
c.Assert(hugoInfo.BuildDate, qt.Equals, bi.RevisionTime)
|
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(hugoInfo.Environment, qt.Equals, "production")
|
||||||
c.Assert(string(hugoInfo.Generator()), qt.Contains, fmt.Sprintf("Hugo %s", hugoInfo.Version()))
|
c.Assert(string(hugoInfo.Generator()), qt.Contains, fmt.Sprintf("Hugo %s", hugoInfo.Version()))
|
||||||
|
|
|
@ -27,8 +27,8 @@ hugo.Generator
|
||||||
hugo.Version
|
hugo.Version
|
||||||
: the current version of the Hugo binary you are using e.g. `0.63.2`
|
: the current version of the Hugo binary you are using e.g. `0.63.2`
|
||||||
|
|
||||||
|
hugo.GoVersion
|
||||||
`hugo` returns an instance that contains the following functions:
|
: returns the version of Go that the Hugo binary was built with. {{< new-in "0.101.0" >}}
|
||||||
|
|
||||||
hugo.Environment
|
hugo.Environment
|
||||||
: the current running environment as defined through the `--environment` cli tag
|
: the current running environment as defined through the `--environment` cli tag
|
||||||
|
@ -52,7 +52,6 @@ We highly recommend using `hugo.Generator` in your website's `<head>`. `hugo.Gen
|
||||||
hugo.Deps
|
hugo.Deps
|
||||||
: See [hugo.Deps](#hugodeps)
|
: See [hugo.Deps](#hugodeps)
|
||||||
|
|
||||||
|
|
||||||
## hugo.Deps
|
## hugo.Deps
|
||||||
|
|
||||||
{{< new-in "0.92.0" >}}
|
{{< new-in "0.92.0" >}}
|
||||||
|
|
Loading…
Reference in a new issue