]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
resources/page: Add taxonomies Page method
authorJoe Mooring <joe.mooring@veriphor.com>
Thu, 11 Apr 2024 19:42:57 +0000 (12:42 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 12 Apr 2024 14:26:02 +0000 (16:26 +0200)
Closes #12316

resources/page/taxonomy.go
resources/page/taxonomy_integration_test.go

index 7258ec197c0378d71cb9e000520e0930f1ee2e33..2732c80402f09ee52fb1271935dbeb945a72f76b 100644 (file)
@@ -112,6 +112,14 @@ func (i Taxonomy) ByCount() OrderedTaxonomy {
        return ia
 }
 
+// Page returns the taxonomy page or nil if the taxonomy has no terms.
+func (i Taxonomy) Page() Page {
+       for _, v := range i {
+               return v.Page().Parent()
+       }
+       return nil
+}
+
 // Pages returns the Pages for this taxonomy.
 func (ie OrderedTaxonomyEntry) Pages() Pages {
        return ie.WeightedPages.Pages()
index a028857cb7f9cc4a38f207baab4c83cf3d06ffd1..70e204dd19a8468da9a5570703ef94b4b871ec1a 100644 (file)
@@ -53,3 +53,29 @@ authors: [John Smith]
                "Robert Jones count: 1",
        )
 }
+
+func TestTaxonomiesPage(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+disableKinds = ['rss','section','sitemap']
+[taxonomies]
+tag = 'tags'
+category = 'categories'
+-- content/p1.md --
+---
+title: p1
+tags: [tag-a]
+---
+-- layouts/_default/list.html --
+{{- with site.Taxonomies.tags.Page }}{{ .RelPermalink }}{{ end }}|
+{{- with site.Taxonomies.categories.Page }}{{ .RelPermalink }}{{ end }}|
+-- layouts/_default/single.html --
+{{ .Title }}
+`
+
+       b := hugolib.Test(t, files)
+
+       b.AssertFileContent("public/index.html", "/tags/||")
+}