aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib/page.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2020-02-19 09:16:27 +0100
committerBjørn Erik Pedersen <[email protected]>2020-02-19 14:52:23 +0100
commitfa520a2d983b982394ad10088393fb303e48980a (patch)
treef545a33ef8de2eccc6fe781281126a5daf90a4c0 /hugolib/page.go
parent82029c1ec975bc2173bd5a454aee6c800924035d (diff)
downloadhugo-fa520a2d983b982394ad10088393fb303e48980a.tar.gz
hugo-fa520a2d983b982394ad10088393fb303e48980a.zip
Add Page.GetTerms
Fixes #6905
Diffstat (limited to 'hugolib/page.go')
-rw-r--r--hugolib/page.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/hugolib/page.go b/hugolib/page.go
index 1384d7293..12129d4ad 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -131,6 +131,34 @@ func (p *pageState) GitInfo() *gitmap.GitInfo {
return p.gitInfo
}
+// GetTerms gets the terms defined on this page in the given taxonomy.
+func (p *pageState) GetTerms(taxonomy string) page.Pages {
+ taxonomy = strings.ToLower(taxonomy)
+ m := p.s.pageMap
+ prefix := cleanTreeKey(taxonomy)
+
+ var self string
+ if p.IsHome() {
+ // TODO(bep) make this less magical, see taxonomyEntries.Insert.
+ self = "/" + page.KindHome
+ } else {
+ self = p.treeRef.key
+ }
+
+ var pas page.Pages
+
+ m.taxonomies.WalkPrefixListable(prefix, func(s string, n *contentNode) bool {
+ if _, found := m.taxonomyEntries.Get(s + self); found {
+ pas = append(pas, n.p)
+ }
+ return false
+ })
+
+ page.SortByDefault(pas)
+
+ return pas
+}
+
func (p *pageState) MarshalJSON() ([]byte, error) {
return page.MarshalPageToJSON(p)
}