Skip to content

Commit

Permalink
common: Add hugo.GoVersion
Browse files Browse the repository at this point in the history
Closes #9849. This enables `hugo.GoVersion` in templates to access the
version of Go that the Hugo binary was built with.
  • Loading branch information
khayyamsaleem authored and bep committed Jun 14, 2022
1 parent 66da1b7 commit 09ac733
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions common/hugo/hugo.go
Expand Up @@ -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
}

Expand Down Expand Up @@ -87,19 +90,22 @@ 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{
CommitHash: commitHash,
BuildDate: buildDate,
Environment: environment,
deps: deps,
GoVersion: goVersion,
}
}

Expand Down
1 change: 1 addition & 0 deletions common/hugo/hugo_test.go
Expand Up @@ -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()))
Expand Down
7 changes: 3 additions & 4 deletions docs/content/en/functions/hugo.md
Expand Up @@ -27,8 +27,8 @@ hugo.Generator
hugo.Version
: the current version of the Hugo binary you are using e.g. `0.63.2`


`hugo` returns an instance that contains the following functions:
hugo.GoVersion
: returns the version of Go that the Hugo binary was built with. {{< new-in "0.101.0" >}}

hugo.Environment
: the current running environment as defined through the `--environment` cli tag
Expand All @@ -52,7 +52,6 @@ We highly recommend using `hugo.Generator` in your website's `<head>`. `hugo.Gen
hugo.Deps
: See [hugo.Deps](#hugodeps)


## hugo.Deps

{{< new-in "0.92.0" >}}
Expand Down Expand Up @@ -112,4 +111,4 @@ An example table listing the dependencies:
{{ end }}
</tbody>
</table>
```
```

0 comments on commit 09ac733

Please sign in to comment.