Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'helpers/hugo.go')
-rw-r--r--helpers/hugo.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/helpers/hugo.go b/helpers/hugo.go
index c4c3f4a76..b9b42e6cf 100644
--- a/helpers/hugo.go
+++ b/helpers/hugo.go
@@ -18,6 +18,7 @@ import (
"fmt"
"strings"
+ "github.com/gohugoio/hugo/compare"
"github.com/spf13/cast"
)
@@ -34,10 +35,40 @@ type HugoVersion struct {
Suffix string
}
+var (
+ _ compare.Eqer = (*HugoVersionString)(nil)
+ _ compare.Comparer = (*HugoVersionString)(nil)
+)
+
+type HugoVersionString string
+
func (v HugoVersion) String() string {
return hugoVersion(v.Number, v.PatchLevel, v.Suffix)
}
+func (v HugoVersion) Version() HugoVersionString {
+ return HugoVersionString(v.String())
+}
+
+func (h HugoVersionString) String() string {
+ return string(h)
+}
+
+// Implements compare.Comparer
+func (h HugoVersionString) Compare(other interface{}) int {
+ v := MustParseHugoVersion(h.String())
+ return compareVersions(v.Number, v.PatchLevel, other)
+}
+
+// Implements compare.Eqer
+func (h HugoVersionString) Eq(other interface{}) bool {
+ s, err := cast.ToStringE(other)
+ if err != nil {
+ return false
+ }
+ return s == h.String()
+}
+
// ParseHugoVersion parses a version string.
func ParseHugoVersion(s string) (HugoVersion, error) {
var vv HugoVersion