Repository: gohugoio/hugo (language: go)

Issue:
Taxonomic weights not honored when ranging through .Pages
Ref: <https://gohugo.io/content-management/taxonomies/#order-taxonomies>

When ranging through `.Pages` in a term template, the content pages were ordered by taxonomic weight in v0.64.1. This stopped working in v0.65.0. 

Git bisect says b2dcd53e3c0240c4afd21d1818fd180c2d1b9d34 is the first bad commit.

Work-arounds (in a term template): 

```text
{{ range index site.Taxonomies .Data.Plural (urlize .Data.Term) }}
  <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}

OR

{{ range sort .Pages (printf "Params.%s_weight" .Data.Plural) }}
  <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}
```

Minimal example:

```bash
git clone --single-branch -b hugo-github-issue-10406 https://github.com/jmooring/hugo-testing hugo-github-issue-10406
cd hugo-github-issue-10406
hugo
```



Discussion / hints:

Fix patch:
diff --git a/hugolib/page.go b/hugolib/page.go
index 9f0d08ca351..ec7b8227771 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -268,7 +268,10 @@ func (p *pageState) Pages() page.Pages {
 		case page.KindSection, page.KindHome:
 			pages = p.getPagesAndSections()
 		case page.KindTerm:
-			pages = p.bucket.getTaxonomyEntries()
+			b := p.treeRef.n
+			viewInfo := b.viewInfo
+			taxonomy := p.s.Taxonomies()[viewInfo.name.plural].Get(viewInfo.termKey)
+			pages = taxonomy.Pages()
 		case page.KindTaxonomy:
 			pages = p.bucket.getTaxonomies()
 		default:


Test patch:
diff --git a/hugolib/taxonomy_test.go b/hugolib/taxonomy_test.go
index b2603217402..b6b696ed3bd 100644
--- a/hugolib/taxonomy_test.go
+++ b/hugolib/taxonomy_test.go
@@ -60,7 +60,6 @@ YAML frontmatter with tags and categories taxonomy.`
 	}
 }
 
-//
 func TestTaxonomiesWithAndWithoutContentFile(t *testing.T) {
 	for _, uglyURLs := range []bool{false, true} {
 		uglyURLs := uglyURLs
@@ -521,7 +520,7 @@ Funny:|/p1/|
 Funny:|/p2/|`)
 }
 
-//https://github.com/gohugoio/hugo/issues/6590
+// https://github.com/gohugoio/hugo/issues/6590
 func TestTaxonomiesListPages(t *testing.T) {
 	b := newTestSitesBuilder(t)
 	b.WithTemplates("_default/list.html", `
@@ -694,3 +693,42 @@ abcdefgs: {{ template "print-page" $abcdefgs }}|IsAncestor: {{ $abcdefgs.IsAnces
     abcdefgs: /abcdefgs/|Abcdefgs|taxonomy|Parent: /|CurrentSection: /|FirstSection: /|IsAncestor: true|IsDescendant: false
 `)
 }
+
+func TestTaxonomiesWeightSort(t *testing.T) {
+
+	files := `
+-- layouts/index.html --
+{{ $a := site.GetPage "tags/a"}}
+:{{ range $a.Pages }}{{ .RelPermalink }}|{{ end }}:
+-- content/p1.md --
+---
+title: P1
+weight: 100
+tags: ['a']
+tags_weight: 20
+---
+-- content/p3.md --
+---
+title: P2
+weight: 200
+tags: ['a']
+tags_weight: 30
+---
+-- content/p2.md --
+---
+title: P3
+weight: 50
+tags: ['a']
+tags_weight: 40
+---
+	`
+
+	b := NewIntegrationTestBuilder(
+		IntegrationTestConfig{
+			T:           t,
+			TxtarString: files,
+		},
+	).Build()
+
+	b.AssertFileContent("public/index.html", `:/p1/|/p3/|/p2/|:`)
+}