Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-04-13 12:40:51 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-04-13 19:52:38 +0300
commitf2795d4d2cef30170af43327f3ff7114923833b1 (patch)
tree2b48f8f3903313f9bdbb17991bcfd29e186d61bb /resources/page
parente85c057f99dc2eeb6994bf24105bc48196841b88 (diff)
Fix WeightedPages in union etc.
We introduced a callback func() to get the owner Page in 0.55.0. Sadly, funcs is not comparable type in Go. This commit replaces the func with a struct pointer that wraps the Page. Fixes #5850
Diffstat (limited to 'resources/page')
-rw-r--r--resources/page/weighted.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/resources/page/weighted.go b/resources/page/weighted.go
index 0937b3f86..3f75bcc3c 100644
--- a/resources/page/weighted.go
+++ b/resources/page/weighted.go
@@ -38,11 +38,11 @@ func (p WeightedPages) Page() Page {
first := p[0]
// TODO(bep) fix tests
- if first.getOwner == nil {
+ if first.owner == nil {
return nil
}
- return first.getOwner()
+ return first.owner.Page
}
// A WeightedPage is a Page with a weight.
@@ -50,15 +50,20 @@ type WeightedPage struct {
Weight int
Page
- // A callback used to fetch the owning Page. This avoids having to do
+ // Reference to the owning Page. This avoids having to do
// manual .Site.GetPage lookups. It is implemented in this roundabout way
// because we cannot add additional state to the WeightedPages slice
// without breaking lots of templates in the wild.
- getOwner func() Page
+ owner *PageWrapper
}
-func NewWeightedPage(weight int, p Page, getOwner func() Page) WeightedPage {
- return WeightedPage{Weight: weight, Page: p, getOwner: getOwner}
+// PageWrapper wraps a Page.
+type PageWrapper struct {
+ Page
+}
+
+func NewWeightedPage(weight int, p Page, owner *PageWrapper) WeightedPage {
+ return WeightedPage{Weight: weight, Page: p, owner: owner}
}
func (w WeightedPage) String() string {