diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-06-15 17:33:09 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-06-15 23:23:02 +0300 |
commit | 522ba1cd98ac67482061448c3a7528e68a720f0d (patch) | |
tree | 527560bfa89b66683c1118d132c8270b42812777 /hugolib | |
parent | 889dc47ceba9cf5cbd6e61a9222a5e54cd562332 (diff) |
Fix order of GetTerms
Preserve the order from front matter, which would be behaviour when doing this manually (before GetTerms).
Fixes #7213
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/content_map.go | 1 | ||||
-rw-r--r-- | hugolib/content_map_page.go | 4 | ||||
-rw-r--r-- | hugolib/page.go | 25 | ||||
-rw-r--r-- | hugolib/taxonomy_test.go | 8 |
4 files changed, 30 insertions, 8 deletions
diff --git a/hugolib/content_map.go b/hugolib/content_map.go index ddcc70707..8af553478 100644 --- a/hugolib/content_map.go +++ b/hugolib/content_map.go @@ -264,6 +264,7 @@ func (b *cmInsertKeyBuilder) newTopLevel() { } type contentBundleViewInfo struct { + ordinal int name viewName termKey string termOrigin string diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index 7516a7029..8c7ecc341 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -579,7 +579,6 @@ func (m *pageMap) attachPageToViews(s string, b *contentNode) { if vals == nil { continue } - w := getParamToLower(b.p, viewName.plural+"_weight") weight, err := cast.ToIntE(w) if err != nil { @@ -587,11 +586,12 @@ func (m *pageMap) attachPageToViews(s string, b *contentNode) { // weight will equal zero, so let the flow continue } - for _, v := range vals { + for i, v := range vals { termKey := m.s.getTaxonomyKey(v) bv := &contentNode{ viewInfo: &contentBundleViewInfo{ + ordinal: i, name: viewName, termKey: termKey, termOrigin: v, diff --git a/hugolib/page.go b/hugolib/page.go index 083e702ed..baf5e7f69 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -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 +} diff --git a/hugolib/taxonomy_test.go b/hugolib/taxonomy_test.go index 97058dd19..64f560d25 100644 --- a/hugolib/taxonomy_test.go +++ b/hugolib/taxonomy_test.go @@ -644,12 +644,12 @@ Cats Paginator {{ range $cats.Paginator.Pages }}{{ .RelPermalink }}|{{ end }}:EN Categories Pages: /categories/birds/|/categories/cats/|/categories/dogs/|/categories/funny/|/categories/gorillas/|:END Funny Pages: /section/p1/|/section/p2/|:END Cats Pages: /section/p1/|/section/|:END -P1 Terms: /categories/cats/|/categories/funny/|:END -Section Terms: /categories/birds/|/categories/cats/|/categories/dogs/|:END +P1 Terms: /categories/funny/|/categories/cats/|:END +Section Terms: /categories/cats/|/categories/dogs/|/categories/birds/|:END Home Terms: /categories/dogs/|/categories/gorillas/|:END Cats Paginator /section/p1/|/section/|:END -Category Paginator /categories/birds/|/categories/cats/|/categories/dogs/|/categories/funny/|/categories/gorillas/|:END -`) +Category Paginator /categories/birds/|/categories/cats/|/categories/dogs/|/categories/funny/|/categories/gorillas/|:END`, + ) b.AssertFileContent("public/404.html", "\n404 Terms: :END\n\t") b.AssertFileContent("public/categories/funny/index.xml", `<link>http://example.com/section/p1/</link>`) b.AssertFileContent("public/categories/index.xml", `<link>http://example.com/categories/funny/</link>`) |