mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
a8f91ace11
commit
be29c0bfbd
2 changed files with 68 additions and 0 deletions
|
@ -251,6 +251,12 @@ func InitializeConfig() {
|
|||
}
|
||||
|
||||
jww.INFO.Println("Using config file:", viper.ConfigFileUsed())
|
||||
|
||||
themeVersionMismatch, minVersion := helpers.IsThemeVsHugoVersionMismatch()
|
||||
if themeVersionMismatch {
|
||||
jww.ERROR.Printf("Current theme does not support Hugo version %s. Minimum version required is %s\n",
|
||||
helpers.HugoReleaseVersion(), minVersion)
|
||||
}
|
||||
}
|
||||
|
||||
func build(watches ...bool) {
|
||||
|
|
|
@ -15,6 +15,10 @@ package helpers
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/hugo/hugofs"
|
||||
"github.com/spf13/hugo/parser"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// this should be the only one
|
||||
|
@ -44,3 +48,61 @@ 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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue