diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-02-22 09:15:12 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-02-22 09:15:12 +0100 |
commit | 0602135fd44b0cfa0a51b0ec6e451ae58ac95666 (patch) | |
tree | bb045df0360b26dbacf682fa227d5d4e18d57bdc /hugolib | |
parent | 55bd46a633d68f62e131457631ba839d6f876a55 (diff) |
Make ge, le etc. work with the Hugo Version number
This means that you can do something ala:
```html
{{ if ge .Hugo.Version "0.36" }}Reasonable new Hugo version!{{ end }}
```
The intented use is feature toggling, but please note that it will take some time and Hugo versions until this can be trusted. It does not work in older Hugo versions.
Fixes #4443
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/hugo_info.go | 6 | ||||
-rw-r--r-- | hugolib/hugo_info_test.go | 33 |
2 files changed, 36 insertions, 3 deletions
diff --git a/hugolib/hugo_info.go b/hugolib/hugo_info.go index 1e0c192e5..303231edb 100644 --- a/hugolib/hugo_info.go +++ b/hugolib/hugo_info.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Hugo Authors. All rights reserved. +// Copyright 2018 The Hugo Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ var hugoInfo *HugoInfo // HugoInfo contains information about the current Hugo environment type HugoInfo struct { - Version string + Version helpers.HugoVersionString Generator template.HTML CommitHash string BuildDate string @@ -41,7 +41,7 @@ type HugoInfo struct { func init() { hugoInfo = &HugoInfo{ - Version: helpers.CurrentHugoVersion.String(), + Version: helpers.CurrentHugoVersion.Version(), CommitHash: CommitHash, BuildDate: BuildDate, Generator: template.HTML(fmt.Sprintf(`<meta name="generator" content="Hugo %s" />`, helpers.CurrentHugoVersion.String())), diff --git a/hugolib/hugo_info_test.go b/hugolib/hugo_info_test.go new file mode 100644 index 000000000..0a34330ac --- /dev/null +++ b/hugolib/hugo_info_test.go @@ -0,0 +1,33 @@ +// Copyright 2018 The Hugo Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package hugolib + +import ( + "fmt" + "testing" + + "github.com/gohugoio/hugo/helpers" + "github.com/stretchr/testify/require" +) + +func TestHugoInfo(t *testing.T) { + assert := require.New(t) + + assert.Equal(helpers.CurrentHugoVersion.Version(), hugoInfo.Version) + assert.IsType(helpers.HugoVersionString(""), hugoInfo.Version) + assert.Equal(CommitHash, hugoInfo.CommitHash) + assert.Equal(BuildDate, hugoInfo.BuildDate) + assert.Contains(hugoInfo.Generator, fmt.Sprintf("Hugo %s", hugoInfo.Version)) + +} |