]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Alias Page.Scratch to Page.Store (note)
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 5 Nov 2024 15:32:57 +0000 (16:32 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 6 Nov 2024 08:49:23 +0000 (09:49 +0100)
Fixes #13016

common/maps/scratch.go
hugolib/page.go
hugolib/page__common.go
hugolib/page__new.go
hugolib/page_test.go
resources/page/page.go

index e9f412540b29e30979a1b860377707071f953166..6383772164a6db39cae6aa477fc82b4f17bad437 100644 (file)
@@ -28,25 +28,6 @@ type Scratch struct {
        mu     sync.RWMutex
 }
 
-// Scratcher provides a scratching service.
-type Scratcher interface {
-       // Scratch returns a "scratch pad" that can be used to store state.
-       Scratch() *Scratch
-}
-
-type scratcher struct {
-       s *Scratch
-}
-
-func (s scratcher) Scratch() *Scratch {
-       return s.s
-}
-
-// NewScratcher creates a new Scratcher.
-func NewScratcher() Scratcher {
-       return scratcher{s: NewScratch()}
-}
-
 // Add will, for single values, add (using the + operator) the addend to the existing addend (if found).
 // Supports numeric values and strings.
 //
index 2bc1da044b443d705f139614bd50e2332a404189..e4c841966b2bccdbf05d91021d9ba62ead32ffd9 100644 (file)
@@ -38,7 +38,6 @@ import (
        "github.com/gohugoio/hugo/tpl"
 
        "github.com/gohugoio/hugo/common/herrors"
-       "github.com/gohugoio/hugo/common/maps"
        "github.com/gohugoio/hugo/common/types"
 
        "github.com/gohugoio/hugo/source"
@@ -149,7 +148,7 @@ func (p *pageState) Key() string {
 }
 
 func (p *pageState) resetBuildState() {
-       p.Scratcher = maps.NewScratcher()
+       // Nothing to do for now.
 }
 
 func (p *pageState) reusePageOutputContent() bool {
index d3b0bd112ddd8ea38c34c1f9f647b911ee3c091b..55465e214ecb9882d092dd80a2cd2943fb8e0a11 100644 (file)
@@ -56,7 +56,6 @@ type pageCommon struct {
        store *maps.Scratch
 
        // All of these represents the common parts of a page.Page
-       maps.Scratcher
        navigation.PageMenusProvider
        page.AuthorProvider
        page.AlternativeOutputFormatsProvider
@@ -113,3 +112,8 @@ type pageCommon struct {
 func (p *pageCommon) Store() *maps.Scratch {
        return p.store
 }
+
+// See issue 13016.
+func (p *pageCommon) Scratch() *maps.Scratch {
+       return p.Store()
+}
index 9a4972d07fdb03987ae11557a3f43afd700f3406..9a11fa8892bdc7a4f89688161299c5734acbde00 100644 (file)
@@ -184,7 +184,6 @@ func (h *HugoSites) doNewPage(m *pageMeta) (*pageState, *paths.Path, error) {
                        pageCommon: &pageCommon{
                                FileProvider:              m,
                                AuthorProvider:            m,
-                               Scratcher:                 maps.NewScratcher(),
                                store:                     maps.NewScratch(),
                                Positioner:                page.NopPage,
                                InSectionPositioner:       page.NopPage,
index 429ab26599af36ea2487b388cdf497258f8f9c34..bdd1be6f713073c02858f33f4eee3b181ab739d7 100644 (file)
@@ -1688,6 +1688,32 @@ title: Scratch Me!
        b.AssertFileContent("public/scratchme/index.html", "C: cv")
 }
 
+// Issue 13016.
+func TestScratchAliasToStore(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+disableKinds = ["taxonomy", "term", "page", "section"]
+disableLiveReload = true
+-- layouts/index.html --
+{{ .Scratch.Set "a" "b" }}
+{{ .Store.Set "c" "d" }}
+.Scratch eq .Store: {{ eq .Scratch .Store }}
+a: {{ .Store.Get "a" }}
+c: {{ .Scratch.Get "c" }}
+
+`
+
+       b := Test(t, files)
+
+       b.AssertFileContent("public/index.html",
+               ".Scratch eq .Store: true",
+               "a: b",
+               "c: d",
+       )
+}
+
 func TestPageParam(t *testing.T) {
        t.Parallel()
 
index 20525669c1e052b354f3c6facd571feac5b8a315..ea7f4bf1bd70e21b756f11e38d225753d799fd55 100644 (file)
@@ -327,7 +327,9 @@ type PageWithoutContent interface {
 
        // Scratch returns a Scratch that can be used to store temporary state.
        // Note that this Scratch gets reset on server rebuilds. See Store() for a variant that survives.
-       maps.Scratcher
+       // Scratch returns a "scratch pad" that can be used to store state.
+       // Deprecated: From Hugo v0.138.0 this is just an alias for Store.
+       Scratch() *maps.Scratch
 
        // Store returns a Scratch that can be used to store temporary state.
        // In contrast to Scratch(), this Scratch is not reset on server rebuilds.