Make sure there are only one HugoInfo instance

See #570
This commit is contained in:
bep 2015-01-19 02:53:07 +01:00
parent 109e6f95fd
commit 724357a242
2 changed files with 12 additions and 11 deletions

View file

@ -7,6 +7,8 @@ var (
BuildDate string BuildDate string
) )
var hugoInfo *HugoInfo
// HugoInfo contains information about the current Hugo environment // HugoInfo contains information about the current Hugo environment
type HugoInfo struct { type HugoInfo struct {
Version string Version string
@ -15,11 +17,14 @@ type HugoInfo struct {
BuildDate string BuildDate string
} }
func newHugoInfo() *HugoInfo { func getHugoInfo() *HugoInfo {
return &HugoInfo{ if hugoInfo == nil {
hugoInfo = &HugoInfo{
Version: Version, Version: Version,
CommitHash: CommitHash, CommitHash: CommitHash,
BuildDate: BuildDate, BuildDate: BuildDate,
Generator: `<meta name="generator" content="Hugo ` + Version + `" />`, Generator: `<meta name="generator" content="Hugo ` + Version + `" />`,
} }
} }
return hugoInfo
}

View file

@ -29,7 +29,6 @@ type Node struct {
Params map[string]interface{} Params map[string]interface{}
Date time.Time Date time.Time
Sitemap Sitemap Sitemap Sitemap
hugo *HugoInfo
UrlPath UrlPath
} }
@ -79,10 +78,7 @@ func (n *Node) IsMenuCurrent(menuId string, inme *MenuEntry) bool {
} }
func (n *Node) Hugo() *HugoInfo { func (n *Node) Hugo() *HugoInfo {
if n.hugo == nil { return getHugoInfo()
n.hugo = newHugoInfo()
}
return n.hugo
} }
func (n *Node) isSameAsDescendantMenu(inme *MenuEntry, parent *MenuEntry) bool { func (n *Node) isSameAsDescendantMenu(inme *MenuEntry, parent *MenuEntry) bool {