hugolib: Add terms' pages to .Data.Pages
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 22 Feb 2017 20:13:21 +0000 (21:13 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 22 Feb 2017 20:13:21 +0000 (21:13 +0100)
Fixes #2826

hugolib/page.go
hugolib/taxonomy_test.go

index 455efd7828b33460a6aba2fda049b0eab2599a89..e06fa76b4eefbbb2fdfb8c8dd49473c4e63cd3ed 100644 (file)
@@ -1595,10 +1595,17 @@ func (p *Page) prepareData(s *Site) error {
        case KindTaxonomyTerm:
                plural := p.sections[0]
                singular := s.taxonomiesPluralSingular[plural]
+               terms := s.Taxonomies[plural]
+
+               for _, tax := range terms {
+                       pages = append(pages, tax.Pages()...)
+               }
+
+               pages = pages.ByWeight()
 
                p.Data["Singular"] = singular
                p.Data["Plural"] = plural
-               p.Data["Terms"] = s.Taxonomies[plural]
+               p.Data["Terms"] = terms
                // keep the following just for legacy reasons
                p.Data["OrderedIndex"] = p.Data["Terms"]
                p.Data["Index"] = p.Data["Terms"]
index 209d8d2fe18e34fbe4950d48c902051fb52a7d12..bafb2c3611a7d7a380f987eb976be84d3074c8a1 100644 (file)
@@ -84,6 +84,7 @@ others:
 
        writeSource(t, fs, "content/p1.md", fmt.Sprintf(pageTemplate, "t1/c1", "- tag1", "- cat1", "- o1"))
        writeSource(t, fs, "content/p2.md", fmt.Sprintf(pageTemplate, "t2/c1", "- tag2", "- cat1", "- o1"))
+       writeSource(t, fs, "content/p3.md", fmt.Sprintf(pageTemplate, "t2/c12", "- tag2", "- cat2", "- o1"))
 
        writeNewContentFile(t, fs, "Category Terms", "2017-01-01", "content/categories/_index.md", 10)
        writeNewContentFile(t, fs, "Tag1 List", "2017-01-01", "content/tags/tag1/_index.md", 10)
@@ -110,4 +111,15 @@ others:
        th.assertFileContent("public/others/o1/index.html", "List", "O1")
        th.assertFileContent("public/others/index.html", "Terms List", "Others")
 
+       s := h.Sites[0]
+       cat1 := s.getPage(KindTaxonomy, "categories", "cat1")
+       require.NotNil(t, cat1)
+       require.Len(t, cat1.Pages, 2)
+
+       cat := s.getPage(KindTaxonomyTerm, "categories")
+       require.NotNil(t, cat)
+       require.Len(t, cat.Pages, 3)
+       require.Len(t, cat.Data["Pages"], 3)
+       require.Equal(t, "t1/c1", cat.Pages[0].Title)
+
 }