Use the tree for taxonomy.Pages()

This commit is contained in:
Bjørn Erik Pedersen 2020-02-18 18:49:11 +01:00
parent 36983e6189
commit b2dcd53e3c
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
3 changed files with 39 additions and 8 deletions

View file

@ -827,6 +827,20 @@ func (b *pagesMapBucket) getTaxonomies() page.Pages {
return b.sections return b.sections
} }
func (b *pagesMapBucket) getTaxonomyEntries() page.Pages {
var pas page.Pages
ref := b.owner.treeRef
viewInfo := ref.n.viewInfo
prefix := strings.ToLower("/" + viewInfo.name.plural + "/" + viewInfo.termKey + "/")
ref.m.taxonomyEntries.WalkPrefix(prefix, func(s string, v interface{}) bool {
n := v.(*contentNode)
pas = append(pas, n.viewInfo.ref.p)
return false
})
page.SortByDefault(pas)
return pas
}
type sectionAggregate struct { type sectionAggregate struct {
datesAll resource.Dates datesAll resource.Dates
datesSection resource.Dates datesSection resource.Dates

View file

@ -186,10 +186,7 @@ func (p *pageState) Pages() page.Pages {
case page.KindSection, page.KindHome: case page.KindSection, page.KindHome:
pages = p.getPagesAndSections() pages = p.getPagesAndSections()
case page.KindTaxonomy: case page.KindTaxonomy:
b := p.treeRef.n pages = p.bucket.getTaxonomyEntries()
viewInfo := b.viewInfo
taxonomy := p.s.Taxonomies()[viewInfo.name.plural].Get(viewInfo.termKey)
pages = taxonomy.Pages()
case page.KindTaxonomyTerm: case page.KindTaxonomyTerm:
pages = p.bucket.getTaxonomies() pages = p.bucket.getTaxonomies()
default: default:

View file

@ -538,14 +538,28 @@ categories.funny:|/blog/p1/|
} }
func TestTaxonomiesParent(t *testing.T) { func TestTaxonomiesPageCollections(t *testing.T) {
t.Parallel() t.Parallel()
b := newTestSitesBuilder(t) b := newTestSitesBuilder(t)
b.WithContent("p.md", `--- b.WithContent("p1.md", `---
title: "Page" title: "Page1"
categories: ["funny", "cats"]
---
`, "p2.md", `---
title: "Page2"
categories: ["funny"] categories: ["funny"]
--- ---
`)
b.WithTemplatesAdded("index.html", `
{{ $categories := site.GetPage "categories" }}
{{ $funny := site.GetPage "categories/funny" }}
{{ $cats := site.GetPage "categories/cats" }}
Categories Pages: {{ range $categories.Pages}}{{.RelPermalink }}|{{ end }}:END
Funny Pages: {{ range $funny.Pages}}{{.RelPermalink }}|{{ end }}:END
Cats Pages: {{ range $cats.Pages}}{{.RelPermalink }}|{{ end }}:END
`) `)
@ -560,7 +574,13 @@ categories: ["funny"]
b.Assert(cat.Parent().IsHome(), qt.Equals, true) b.Assert(cat.Parent().IsHome(), qt.Equals, true)
b.Assert(funny.Parent(), qt.Equals, cat) b.Assert(funny.Parent(), qt.Equals, cat)
b.AssertFileContent("public/categories/funny/index.xml", `<link>http://example.com/p/</link>`) b.AssertFileContent("public/index.html", `
Categories Pages: /categories/cats/|/categories/funny/|:END
Funny Pages: /p1/|/p2/|:END
Cats Pages: /p1/|:END
`)
b.AssertFileContent("public/categories/funny/index.xml", `<link>http://example.com/p1/</link>`)
b.AssertFileContent("public/categories/index.xml", `<link>http://example.com/categories/funny/</link>`) b.AssertFileContent("public/categories/index.xml", `<link>http://example.com/categories/funny/</link>`)
} }