diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-11-13 11:07:32 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-11-13 12:41:16 +0100 |
commit | a7df536a52912f34d7d20c970c38590bf5e0c513 (patch) | |
tree | 2773e4660f458f32d19784cfb5f557f3b7ffb6e2 /common | |
parent | 3477d9fcec39d17f99cbc891e337658e8660f5db (diff) | |
download | hugo-a7df536a52912f34d7d20c970c38590bf5e0c513.tar.gz hugo-a7df536a52912f34d7d20c970c38590bf5e0c513.zip |
Add site.Store and hugo.Store and Shortcode.Store
Closes #13021
Diffstat (limited to 'common')
-rw-r--r-- | common/hugo/hugo.go | 10 | ||||
-rw-r--r-- | common/maps/scratch.go | 8 |
2 files changed, 17 insertions, 1 deletions
diff --git a/common/hugo/hugo.go b/common/hugo/hugo.go index f21103940..dd43cf7b6 100644 --- a/common/hugo/hugo.go +++ b/common/hugo/hugo.go @@ -33,6 +33,7 @@ import ( "github.com/gohugoio/hugo/common/hcontext" "github.com/gohugoio/hugo/common/hexec" "github.com/gohugoio/hugo/common/loggers" + "github.com/gohugoio/hugo/common/maps" "github.com/gohugoio/hugo/hugofs/files" "github.com/spf13/afero" @@ -55,6 +56,8 @@ var ( vendorInfo string ) +var _ maps.StoreProvider = (*HugoInfo)(nil) + // HugoInfo contains information about the current Hugo environment type HugoInfo struct { CommitHash string @@ -72,6 +75,8 @@ type HugoInfo struct { conf ConfigProvider deps []*Dependency + store *maps.Scratch + // Context gives access to some of the context scoped variables. Context Context } @@ -116,6 +121,10 @@ func (i HugoInfo) Deps() []*Dependency { return i.deps } +func (i HugoInfo) Store() *maps.Scratch { + return i.store +} + // Deprecated: Use hugo.IsMultihost instead. func (i HugoInfo) IsMultiHost() bool { Deprecate("hugo.IsMultiHost", "Use hugo.IsMultihost instead.", "v0.124.0") @@ -185,6 +194,7 @@ func NewInfo(conf ConfigProvider, deps []*Dependency) HugoInfo { Environment: conf.Environment(), conf: conf, deps: deps, + store: maps.NewScratch(), GoVersion: goVersion, } } diff --git a/common/maps/scratch.go b/common/maps/scratch.go index 638377216..cf5231783 100644 --- a/common/maps/scratch.go +++ b/common/maps/scratch.go @@ -22,7 +22,13 @@ import ( "github.com/gohugoio/hugo/common/math" ) -// Scratch is a writable context used for stateful operations in Page/Node rendering. +type StoreProvider interface { + // Store returns a Scratch that can be used to store temporary state. + // Store is not reset on server rebuilds. + Store() *Scratch +} + +// Scratch is a writable context used for stateful build operations type Scratch struct { values map[string]any mu sync.RWMutex |