mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
@@ -21,6 +21,7 @@ import (
|
||||
"runtime/debug"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gohugoio/hugo/hugofs/files"
|
||||
|
||||
@@ -57,6 +58,8 @@ type Info struct {
|
||||
// This can also be set by the user.
|
||||
// It can be any string, but it will be all lower case.
|
||||
Environment string
|
||||
|
||||
deps []*Dependency
|
||||
}
|
||||
|
||||
// Version returns the current version as a comparable version string.
|
||||
@@ -77,8 +80,13 @@ func (i Info) IsExtended() bool {
|
||||
return IsExtended
|
||||
}
|
||||
|
||||
// Deps gets a list of dependencies for this Hugo build.
|
||||
func (i Info) Deps() []*Dependency {
|
||||
return i.deps
|
||||
}
|
||||
|
||||
// NewInfo creates a new Hugo Info object.
|
||||
func NewInfo(environment string) Info {
|
||||
func NewInfo(environment string, deps []*Dependency) Info {
|
||||
if environment == "" {
|
||||
environment = EnvironmentProduction
|
||||
}
|
||||
@@ -86,6 +94,7 @@ func NewInfo(environment string) Info {
|
||||
CommitHash: commitHash,
|
||||
BuildDate: buildDate,
|
||||
Environment: environment,
|
||||
deps: deps,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,3 +165,27 @@ func IsRunningAsTest() bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Dependency is a single dependency, which can be either a Hugo Module or a local theme.
|
||||
type Dependency struct {
|
||||
// Returns the path to this module.
|
||||
// This will either be the module path, e.g. "github.com/gohugoio/myshortcodes",
|
||||
// or the path below your /theme folder, e.g. "mytheme".
|
||||
Path string
|
||||
|
||||
// The module version.
|
||||
Version string
|
||||
|
||||
// Whether this dependency is vendored.
|
||||
Vendor bool
|
||||
|
||||
// Time version was created.
|
||||
Time time.Time
|
||||
|
||||
// In the dependency tree, this is the first module that defines this module
|
||||
// as a dependency.
|
||||
Owner *Dependency
|
||||
|
||||
// Replaced by this dependency.
|
||||
Replace *Dependency
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ import (
|
||||
func TestHugoInfo(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
hugoInfo := NewInfo("")
|
||||
hugoInfo := NewInfo("", nil)
|
||||
|
||||
c.Assert(hugoInfo.Version(), qt.Equals, CurrentVersion.Version())
|
||||
c.Assert(fmt.Sprintf("%T", VersionString("")), qt.Equals, fmt.Sprintf("%T", hugoInfo.Version()))
|
||||
@@ -34,6 +34,6 @@ func TestHugoInfo(t *testing.T) {
|
||||
c.Assert(hugoInfo.IsProduction(), qt.Equals, true)
|
||||
c.Assert(hugoInfo.IsExtended(), qt.Equals, IsExtended)
|
||||
|
||||
devHugoInfo := NewInfo("development")
|
||||
devHugoInfo := NewInfo("development", nil)
|
||||
c.Assert(devHugoInfo.IsProduction(), qt.Equals, false)
|
||||
}
|
||||
|
Reference in New Issue
Block a user