summaryrefslogtreecommitdiffstats
path: root/helpers
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2015-09-14 17:31:39 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2015-09-14 17:31:39 +0200
commitf5308da32013279664379111d84fb8fa50d7e5f3 (patch)
tree9ba2f69bdf2e654fb5b4f36fa1d062d9ec103a25 /helpers
parente71bef79e504f8a016652380ad4c0ca89a2b8898 (diff)
Move isThemeVsHugoVersionMismatch to /commands
To prevent potential package cycles in /helpers.
Diffstat (limited to 'helpers')
-rw-r--r--helpers/hugo.go73
1 files changed, 5 insertions, 68 deletions
diff --git a/helpers/hugo.go b/helpers/hugo.go
index 35466a7dc..2e48ff5c9 100644
--- a/helpers/hugo.go
+++ b/helpers/hugo.go
@@ -15,31 +15,26 @@ package helpers
import (
"fmt"
- "io/ioutil"
- "path/filepath"
-
- "github.com/spf13/hugo/hugofs"
- "github.com/spf13/hugo/parser"
)
// this should be the only one
-const hugoVersionMain = 0.15
-const hugoVersionSuffix = "-DEV" // blank this when doing a release
+const HugoVersionNumber = 0.15
+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)
+ return hugoVersion(HugoVersionNumber, HugoVersionSuffix)
}
// HugoReleaseVersion is same as HugoVersion, but no suffix.
func HugoReleaseVersion() string {
- return hugoVersionNoSuffix(hugoVersionMain)
+ return hugoVersionNoSuffix(HugoVersionNumber)
}
// NextHugoReleaseVersion returns the next Hugo release version.
func NextHugoReleaseVersion() string {
- return hugoVersionNoSuffix(hugoVersionMain + 0.01)
+ return hugoVersionNoSuffix(HugoVersionNumber + 0.01)
}
func hugoVersion(version float32, suffix string) string {
@@ -49,61 +44,3 @@ func hugoVersion(version float32, suffix string) string {
func hugoVersionNoSuffix(version float32) string {
return fmt.Sprintf("%.2g", version)
}
-
-// IsThemeVsHugoVersionMismatch returns whether the current Hugo version is < theme's min_version
-func IsThemeVsHugoVersionMismatch() (mismatch bool, requiredMinVersion string) {
- if !ThemeSet() {
- return
- }
-
- themeDir, err := getThemeDirPath("")
-
- if err != nil {
- return
- }
-
- fs := hugofs.SourceFs
- path := filepath.Join(themeDir, "theme.toml")
-
- exists, err := Exists(path, fs)
-
- if err != nil || !exists {
- return
- }
-
- f, err := fs.Open(path)
-
- if err != nil {
- return
- }
-
- defer f.Close()
-
- b, err := ioutil.ReadAll(f)
-
- if err != nil {
- return
- }
-
- c, err := parser.HandleTOMLMetaData(b)
-
- if err != nil {
- return
- }
-
- config := c.(map[string]interface{})
-
- if minVersion, ok := config["min_version"]; ok {
- switch minVersion.(type) {
- case float32:
- return hugoVersionMain < minVersion.(float32), fmt.Sprint(minVersion)
- case float64:
- return hugoVersionMain < minVersion.(float64), fmt.Sprint(minVersion)
- default:
- return
- }
-
- }
-
- return
-}