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:
Bjørn Erik Pedersen
2019-04-13 11:40:51 +02:00
parent e85c057f99
commit f2795d4d2c
4 changed files with 46 additions and 14 deletions

View File

@@ -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)