@@ -32,6 +32,7 @@ import (
3232 "github.com/gohugoio/hugo/common/hexec"
3333 "github.com/gohugoio/hugo/common/loggers"
3434 "github.com/gohugoio/hugo/common/maps"
35+ "github.com/gohugoio/hugo/common/version"
3536 "github.com/gohugoio/hugo/hugofs/files"
3637
3738 "github.com/spf13/afero"
@@ -80,7 +81,7 @@ type HugoInfo struct {
8081}
8182
8283// Version returns the current version as a comparable version string.
83- func (i HugoInfo ) Version () VersionString {
84+ func (i HugoInfo ) Version () version. VersionString {
8485 return CurrentVersion .Version ()
8586}
8687
@@ -451,7 +452,7 @@ func deprecateLevelWithLogger(item, alternative, version string, level logg.Leve
451452// We want people to run at least the current and previous version without any warnings.
452453// We want people who don't update Hugo that often to see the warnings and errors before we remove the feature.
453454func deprecationLogLevelFromVersion (ver string ) logg.Level {
454- from := MustParseVersion (ver )
455+ from := version . MustParseVersion (ver )
455456 to := CurrentVersion
456457 minorDiff := to .Minor - from .Minor
457458 switch {
@@ -465,3 +466,46 @@ func deprecationLogLevelFromVersion(ver string) logg.Level {
465466 return logg .LevelInfo
466467 }
467468}
469+
470+ // BuildVersionString creates a version string. This is what you see when
471+ // running "hugo version".
472+ func BuildVersionString () string {
473+ // program := "Hugo Static Site Generator"
474+ program := "hugo"
475+
476+ version := "v" + CurrentVersion .String ()
477+
478+ bi := getBuildInfo ()
479+ if bi == nil {
480+ return version
481+ }
482+ if bi .Revision != "" {
483+ version += "-" + bi .Revision
484+ }
485+ if IsExtended {
486+ version += "+extended"
487+ }
488+ if IsWithdeploy {
489+ version += "+withdeploy"
490+ }
491+
492+ osArch := bi .GoOS + "/" + bi .GoArch
493+
494+ date := bi .RevisionTime
495+ if date == "" {
496+ // Accept vendor-specified build date if .git/ is unavailable.
497+ date = buildDate
498+ }
499+ if date == "" {
500+ date = "unknown"
501+ }
502+
503+ versionString := fmt .Sprintf ("%s %s %s BuildDate=%s" ,
504+ program , version , osArch , date )
505+
506+ if vendorInfo != "" {
507+ versionString += " VendorInfo=" + vendorInfo
508+ }
509+
510+ return versionString
511+ }
0 commit comments