From a6e84391760ca3786bf580344e2a013ac54b4b4a Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Thu, 11 Apr 2024 12:42:57 -0700 Subject: resources/page: Add taxonomies Page method Closes #12316 --- resources/page/taxonomy.go | 8 ++++++++ resources/page/taxonomy_integration_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/resources/page/taxonomy.go b/resources/page/taxonomy.go index 7258ec197..2732c8040 100644 --- a/resources/page/taxonomy.go +++ b/resources/page/taxonomy.go @@ -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() diff --git a/resources/page/taxonomy_integration_test.go b/resources/page/taxonomy_integration_test.go index a028857cb..70e204dd1 100644 --- a/resources/page/taxonomy_integration_test.go +++ b/resources/page/taxonomy_integration_test.go @@ -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/||") +} -- cgit v1.2.3