1
0
mirror of https://github.com/gohugoio/hugo.git synced 2024-05-11 05:54:58 +00:00

Add Node.ID

Fixes #2071
This commit is contained in:
Bjørn Erik Pedersen
2016-04-11 11:49:02 +02:00
parent 37fb2d43e5
commit 5ef52294f9
2 changed files with 49 additions and 1 deletions

View File

@@ -14,10 +14,12 @@
package hugolib
import (
"github.com/spf13/cast"
"html/template"
"sync"
"sync/atomic"
"time"
"github.com/spf13/cast"
)
type Node struct {
@@ -37,6 +39,24 @@ type Node struct {
paginator *Pager
paginatorInit sync.Once
scratch *Scratch
id int
idInit sync.Once
}
// This should probably be owned by Site and new ids assigned on creation,
// but that would lead to massive changes; do it simple for now.
var nodeIDCounter uint64
func nextNodeID() int {
return int(atomic.AddUint64(&nodeIDCounter, 1))
}
// ID returns an integer that identifies this Node.
// This is unique for a given Hugo build, but must not be considered stable.
// See UniqueID on Page for an identify that is stable for repeated builds.
func (n *Node) ID() int {
n.idInit.Do(func() { n.id = nextNodeID() })
return n.id
}
func (n *Node) Now() time.Time {