mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-28 22:19:59 +02:00
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
This commit is contained in:
@@ -87,6 +87,37 @@ tags_weight: %d
|
||||
`weightedPages:2::page.WeightedPages:[WeightedPage(10,"Page") WeightedPage(20,"Page")]`)
|
||||
}
|
||||
|
||||
func TestUnionFunc(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
|
||||
pageContent := `
|
||||
---
|
||||
title: "Page"
|
||||
tags: ["blue", "green"]
|
||||
tags_weight: %d
|
||||
---
|
||||
|
||||
`
|
||||
b := newTestSitesBuilder(t)
|
||||
b.WithSimpleConfigFile().
|
||||
WithContent("page1.md", fmt.Sprintf(pageContent, 10), "page2.md", fmt.Sprintf(pageContent, 20),
|
||||
"page3.md", fmt.Sprintf(pageContent, 30)).
|
||||
WithTemplatesAdded("index.html", `
|
||||
{{ $unionPages := first 2 .Site.RegularPages | union .Site.RegularPages }}
|
||||
{{ $unionWeightedPages := .Site.Taxonomies.tags.blue | union .Site.Taxonomies.tags.green }}
|
||||
{{ printf "unionPages: %T %d" $unionPages (len $unionPages) }}
|
||||
{{ printf "unionWeightedPages: %T %d" $unionWeightedPages (len $unionWeightedPages) }}
|
||||
`)
|
||||
b.CreateSites().Build(BuildCfg{})
|
||||
|
||||
assert.Equal(1, len(b.H.Sites))
|
||||
require.Len(t, b.H.Sites[0].RegularPages(), 3)
|
||||
|
||||
b.AssertFileContent("public/index.html",
|
||||
"unionPages: page.Pages 3",
|
||||
"unionWeightedPages: page.WeightedPages 6")
|
||||
}
|
||||
|
||||
func TestAppendFunc(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
|
||||
|
Reference in New Issue
Block a user