diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-11-26 10:11:22 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-12-06 14:37:25 +0100 |
commit | 831d23cb4d1ca99cdc15ed31c8ee1f981497be8f (patch) | |
tree | 8fe47b1b1b9233448297f8015ce61bbb7da13fc7 /commands | |
parent | 514e18dc27ce37a0e9a231741d616cf29d50d610 (diff) |
Add tpl/site and tpl/hugo
This means that the current `.Site` and ´.Hugo` is available as a globals, so you can do `site.IsServer`, `hugo.Version` etc.
Fixes #5470
Fixes #5467
Fixes #5503
Diffstat (limited to 'commands')
-rw-r--r-- | commands/commandeer.go | 9 | ||||
-rw-r--r-- | commands/genman.go | 3 | ||||
-rw-r--r-- | commands/hugo.go | 3 | ||||
-rw-r--r-- | commands/version.go | 37 |
4 files changed, 12 insertions, 40 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go index cd2866a27..b722991ab 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -17,10 +17,11 @@ import ( "bytes" "errors" - "github.com/gohugoio/hugo/common/herrors" - "io/ioutil" + "github.com/gohugoio/hugo/common/herrors" + "github.com/gohugoio/hugo/common/hugo" + jww "github.com/spf13/jwalterweatherman" "os" @@ -105,7 +106,7 @@ func (c *commandeer) getErrorWithContext() interface{} { m := make(map[string]interface{}) m["Error"] = errors.New(removeErrorPrefixFromLog(c.logger.Errors())) - m["Version"] = hugoVersionString() + m["Version"] = hugo.BuildVersionString() fe := herrors.UnwrapErrorWithFileContext(c.buildErr) if fe != nil { @@ -379,7 +380,7 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { if themeVersionMismatch { name := filepath.Base(dir) cfg.Logger.ERROR.Printf("%s theme does not support Hugo version %s. Minimum version required is %s\n", - strings.ToUpper(name), helpers.CurrentHugoVersion.ReleaseVersion(), minVersion) + strings.ToUpper(name), hugo.CurrentVersion.ReleaseVersion(), minVersion) } return nil diff --git a/commands/genman.go b/commands/genman.go index ac4eaf8d1..720046289 100644 --- a/commands/genman.go +++ b/commands/genman.go @@ -17,6 +17,7 @@ import ( "fmt" "strings" + "github.com/gohugoio/hugo/common/hugo" "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/hugofs" "github.com/spf13/cobra" @@ -45,7 +46,7 @@ in the "man" directory under the current directory.`, header := &doc.GenManHeader{ Section: "1", Manual: "Hugo Manual", - Source: fmt.Sprintf("Hugo %s", helpers.CurrentHugoVersion), + Source: fmt.Sprintf("Hugo %s", hugo.CurrentVersion), } if !strings.HasSuffix(cc.genmandir, helpers.FilePathSeparator) { cc.genmandir += helpers.FilePathSeparator diff --git a/commands/hugo.go b/commands/hugo.go index 0bb15c3d1..759efc17b 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -23,6 +23,7 @@ import ( "sort" "sync/atomic" + "github.com/gohugoio/hugo/common/hugo" "github.com/pkg/errors" "github.com/gohugoio/hugo/common/herrors" @@ -1041,7 +1042,7 @@ func (c *commandeer) isThemeVsHugoVersionMismatch(fs afero.Fs) (dir string, mism } if minVersion, ok := tomlMeta["min_version"]; ok { - if helpers.CompareVersion(minVersion) > 0 { + if hugo.CompareVersion(minVersion) > 0 { return absThemeDir, true, fmt.Sprint(minVersion) } } diff --git a/commands/version.go b/commands/version.go index b85f53725..287950a2d 100644 --- a/commands/version.go +++ b/commands/version.go @@ -14,16 +14,9 @@ package commands import ( - "fmt" - "runtime" - "strings" - - jww "github.com/spf13/jwalterweatherman" - - "github.com/gohugoio/hugo/helpers" - "github.com/gohugoio/hugo/hugolib" - "github.com/gohugoio/hugo/resource/tocss/scss" + "github.com/gohugoio/hugo/common/hugo" "github.com/spf13/cobra" + jww "github.com/spf13/jwalterweatherman" ) var _ cmder = (*versionCmd)(nil) @@ -47,29 +40,5 @@ func newVersionCmd() *versionCmd { } func printHugoVersion() { - jww.FEEDBACK.Println(hugoVersionString()) -} - -func hugoVersionString() string { - program := "Hugo Static Site Generator" - - version := "v" + helpers.CurrentHugoVersion.String() - if hugolib.CommitHash != "" { - version += "-" + strings.ToUpper(hugolib.CommitHash) - } - if scss.Supports() { - version += "/extended" - } - - osArch := runtime.GOOS + "/" + runtime.GOARCH - - var buildDate string - if hugolib.BuildDate != "" { - buildDate = hugolib.BuildDate - } else { - buildDate = "unknown" - } - - return fmt.Sprintf("%s %s %s BuildDate: %s", program, version, osArch, buildDate) - + jww.FEEDBACK.Println(hugo.BuildVersionString()) } |