mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-26 22:42:05 +00:00
Refactor Hugo version
Put version handling into the helpers package so it can be used by many, and split version and suffix to make it possible to calculate the next Hugo version.
This commit is contained in:
parent
49f20bbc9b
commit
3273fce044
4 changed files with 64 additions and 6 deletions
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
"github.com/kardianos/osext"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/hugo/helpers"
|
||||
"github.com/spf13/hugo/hugolib"
|
||||
)
|
||||
|
||||
|
@ -38,9 +39,9 @@ var version = &cobra.Command{
|
|||
formatBuildDate() // format the compile time
|
||||
}
|
||||
if hugolib.CommitHash == "" {
|
||||
fmt.Printf("Hugo Static Site Generator v%s BuildDate: %s\n", hugolib.Version, hugolib.BuildDate)
|
||||
fmt.Printf("Hugo Static Site Generator v%s BuildDate: %s\n", helpers.HugoVersion(), hugolib.BuildDate)
|
||||
} else {
|
||||
fmt.Printf("Hugo Static Site Generator v%s-%s BuildDate: %s\n", hugolib.Version, strings.ToUpper(hugolib.CommitHash), hugolib.BuildDate)
|
||||
fmt.Printf("Hugo Static Site Generator v%s-%s BuildDate: %s\n", helpers.HugoVersion(), strings.ToUpper(hugolib.CommitHash), hugolib.BuildDate)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
46
helpers/hugo.go
Normal file
46
helpers/hugo.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Copyright © 2015 Steve Francia <spf@spf13.com>.
|
||||
//
|
||||
// Licensed under the Simple Public 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://opensource.org/licenses/Simple-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 helpers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// this should be the only one
|
||||
const hugoVersionMain = 0.14
|
||||
const hugoVersionSuffix = "-DEV" // blank this when doing a release
|
||||
|
||||
// HugoVersion returns the current Hugo version. It will include
|
||||
// a suffix, typically '-DEV', if it's development version.
|
||||
func HugoVersion() string {
|
||||
return hugoVersion(hugoVersionMain, hugoVersionSuffix)
|
||||
}
|
||||
|
||||
// HugoReleaseVersion is same as HugoVersion, but no suffix.
|
||||
func HugoReleaseVersion() string {
|
||||
return hugoVersionNoSuffix(hugoVersionMain)
|
||||
}
|
||||
|
||||
// NextHugoReleaseVersion returns the next Hugo release version.
|
||||
func NextHugoReleaseVersion() string {
|
||||
return hugoVersionNoSuffix(hugoVersionMain + 0.01)
|
||||
}
|
||||
|
||||
func hugoVersion(version float32, suffix string) string {
|
||||
return fmt.Sprintf("%.2g%s", version, suffix)
|
||||
}
|
||||
|
||||
func hugoVersionNoSuffix(version float32) string {
|
||||
return fmt.Sprintf("%.2g", version)
|
||||
}
|
11
helpers/hugo_test.go
Normal file
11
helpers/hugo_test.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHugoVersion(t *testing.T) {
|
||||
assert.Equal(t, "0.15-DEV", hugoVersion(0.15, "-DEV"))
|
||||
assert.Equal(t, "0.17", hugoVersionNoSuffix(0.16+0.01))
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package hugolib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/hugo/helpers"
|
||||
"html/template"
|
||||
)
|
||||
|
||||
const Version = "0.14-DEV"
|
||||
|
||||
var (
|
||||
CommitHash string
|
||||
BuildDate string
|
||||
|
@ -23,9 +23,9 @@ type HugoInfo struct {
|
|||
|
||||
func init() {
|
||||
hugoInfo = &HugoInfo{
|
||||
Version: Version,
|
||||
Version: helpers.HugoVersion(),
|
||||
CommitHash: CommitHash,
|
||||
BuildDate: BuildDate,
|
||||
Generator: `<meta name="generator" content="Hugo ` + Version + `" />`,
|
||||
Generator: template.HTML(fmt.Sprintf(`<meta name="generator" content="Hugo %s" />`, helpers.HugoVersion())),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue