ref: 3273fce044f06f90ae296f9b42431958d2b06e7f
parent: 49f20bbc9bf4eb9ecedfa0fd9dde484256ae91d1
author: bep <[email protected]>
date: Wed Mar 18 08:23:13 EDT 2015
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.
--- a/commands/version.go
+++ b/commands/version.go
@@ -22,6 +22,7 @@
"github.com/kardianos/osext"
"github.com/spf13/cobra"
+ "github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/hugolib"
)
@@ -38,9 +39,9 @@
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)
}
},
}
--- /dev/null
+++ b/helpers/hugo.go
@@ -1,0 +1,46 @@
+// Copyright © 2015 Steve Francia <[email protected]>.
+//
+// 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)
+}
--- /dev/null
+++ b/helpers/hugo_test.go
@@ -1,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))
+}
--- a/hugolib/hugo.go
+++ b/hugolib/hugo.go
@@ -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 @@
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())),
}
}