summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-02-18 18:49:11 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-02-18 19:47:45 +0100
commitb2dcd53e3c0240c4afd21d1818fd180c2d1b9d34 (patch)
treee3a7a7717d37cb44b6c9bb0b1dcf64be702129ce /hugolib
parent36983e6189a717f1d4d1da6652621d7f8fe186ad (diff)
Use the tree for taxonomy.Pages()
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/content_map_page.go14
-rw-r--r--hugolib/page.go5
-rw-r--r--hugolib/taxonomy_test.go28
3 files changed, 39 insertions, 8 deletions
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go
index 3269abe12..06d1310ec 100644
--- a/hugolib/content_map_page.go
+++ b/hugolib/content_map_page.go
@@ -827,6 +827,20 @@ func (b *pagesMapBucket) getTaxonomies() page.Pages {
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 {
datesAll resource.Dates
datesSection resource.Dates
diff --git a/hugolib/page.go b/hugolib/page.go
index fa6c84d87..1384d7293 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -186,10 +186,7 @@ func (p *pageState) Pages() page.Pages {
case page.KindSection, page.KindHome:
pages = p.getPagesAndSections()
case page.KindTaxonomy:
- b := p.treeRef.n
- viewInfo := b.viewInfo
- taxonomy := p.s.Taxonomies()[viewInfo.name.plural].Get(viewInfo.termKey)
- pages = taxonomy.Pages()
+ pages = p.bucket.getTaxonomyEntries()
case page.KindTaxonomyTerm:
pages = p.bucket.getTaxonomies()
default:
diff --git a/hugolib/taxonomy_test.go b/hugolib/taxonomy_test.go
index 6d049a0c3..d91e7699f 100644
--- a/hugolib/taxonomy_test.go
+++ b/hugolib/taxonomy_test.go
@@ -538,14 +538,28 @@ categories.funny:|/blog/p1/|
}
-func TestTaxonomiesParent(t *testing.T) {
+func TestTaxonomiesPageCollections(t *testing.T) {
t.Parallel()
b := newTestSitesBuilder(t)
- b.WithContent("p.md", `---
-title: "Page"
+ b.WithContent("p1.md", `---
+title: "Page1"
+categories: ["funny", "cats"]
+---
+`, "p2.md", `---
+title: "Page2"
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(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>`)
}