mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-24 21:56:05 +02:00
Fix order of GetTerms
Preserve the order from front matter, which would be behaviour when doing this manually (before GetTerms). Fixes #7213
This commit is contained in:
@@ -132,6 +132,7 @@ func (p *pageState) GitInfo() *gitmap.GitInfo {
|
||||
}
|
||||
|
||||
// GetTerms gets the terms defined on this page in the given taxonomy.
|
||||
// The pages returned will be ordered according to the front matter.
|
||||
func (p *pageState) GetTerms(taxonomy string) page.Pages {
|
||||
if p.treeRef == nil {
|
||||
return nil
|
||||
@@ -147,8 +148,9 @@ func (p *pageState) GetTerms(taxonomy string) page.Pages {
|
||||
|
||||
m.taxonomies.WalkQuery(pageMapQuery{Prefix: prefix}, func(s string, n *contentNode) bool {
|
||||
key := s + self
|
||||
if _, found := m.taxonomyEntries.Get(key); found {
|
||||
pas = append(pas, n.p)
|
||||
if tn, found := m.taxonomyEntries.Get(key); found {
|
||||
vi := tn.(*contentNode).viewInfo
|
||||
pas = append(pas, pageWithOrdinal{pageState: n.p, ordinal: vi.ordinal})
|
||||
}
|
||||
return false
|
||||
})
|
||||
@@ -1006,3 +1008,22 @@ func (s *Site) sectionsFromFile(fi source.File) []string {
|
||||
|
||||
return parts
|
||||
}
|
||||
|
||||
var (
|
||||
_ page.Page = (*pageWithOrdinal)(nil)
|
||||
_ collections.Order = (*pageWithOrdinal)(nil)
|
||||
_ pageWrapper = (*pageWithOrdinal)(nil)
|
||||
)
|
||||
|
||||
type pageWithOrdinal struct {
|
||||
ordinal int
|
||||
*pageState
|
||||
}
|
||||
|
||||
func (p pageWithOrdinal) Ordinal() int {
|
||||
return p.ordinal
|
||||
}
|
||||
|
||||
func (p pageWithOrdinal) page() page.Page {
|
||||
return p.pageState
|
||||
}
|
||||
|
Reference in New Issue
Block a user