]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
common: Add hugo.GoVersion
authorKhayyam Saleem <hello@khayyam.me>
Mon, 30 May 2022 13:12:41 +0000 (09:12 -0400)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 14 Jun 2022 07:48:45 +0000 (09:48 +0200)
Closes #9849. This enables `hugo.GoVersion` in templates to access the
version of Go that the Hugo binary was built with.

common/hugo/hugo.go
common/hugo/hugo_test.go
docs/content/en/functions/hugo.md

index 2c6e5f2a0e39d324becb3d7fe063c0c8d0f57f7b..d78564a67db35e37f28bcb3749d4172c929049d7 100644 (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,
        }
 }
 
index 3bc95684b8d1248d7f90fffb02b25fad8eed6955..f2ad0f5c1ef4057203b7fe3eaa5d26fad1f132d5 100644 (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()))
index a495eae0ad56a57a816678ba8fe7e593cdf4fdea..1792f5a8d764827d02517cb7866b76863cba1b14 100644 (file)
@@ -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
@@ -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" >}}
@@ -112,4 +111,4 @@ An example table listing the dependencies:
     {{ end }}
   </tbody>
 </table>
-```
\ No newline at end of file
+```