Repository: gohugoio/hugo (language: go)

Issue:
Terms with backing content file is not handled correctly in 0.123
Example [site](https://github.com/TiGR/hugo-testing/tree/missing-taxonomies-issue). I try to list taxonomy terms, according to the docs (it is not changed for 0.123) I can do it like this:

```html
<ul>
  {{ range .Site.Taxonomies.tags }}
    <li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
  {{ end }}
</ul>
```

With the example site, when I run it in 0.122, I get this result in the console:

```
WARN  Listing tags:
WARN  --------------------
WARN  Tag "tag1" "Tag One"
WARN  Tag "tag2" "Tag Two"
WARN  Tag "tag3" "Tag Three"
WARN  
WARN  Listing tags in alphabetical order:
WARN  -----------------------------------
WARN  Tag "Tag One"
WARN  Tag "Tag Three"
WARN  Tag "Tag Two"
```

But when I run it with 0.123, I get this:

```
WARN  Listing tags:
WARN  --------------------
WARN  Tag "tag1" "Tag One"
WARN  
WARN  Listing tags in alphabetical order:
WARN  -----------------------------------
WARN  Tag "Tag One"
```


Discussion / hints:

Fix patch:
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go
index 43c67ce738a..6273870b73f 100644
--- a/hugolib/content_map_page.go
+++ b/hugolib/content_map_page.go
@@ -1511,6 +1511,8 @@ func (sa *sitePagesAssembler) assembleTermsAndTranslations() error {
 						}
 						pages.InsertIntoValuesDimension(pi.Base(), n)
 						term = pages.Get(pi.Base())
+					} else if term.(*pageState).m.term != v {
+						term.(*pageState).m.term = v
 					}
 
 					if s == "" {
@@ -1882,11 +1884,15 @@ func (m *pageMap) CreateSiteTaxonomies(ctx context.Context) error {
 					if taxonomy == nil {
 						return true, fmt.Errorf("missing taxonomy: %s", viewName.plural)
 					}
+					if p.m.term == "" {
+						panic("term is empty")
+					}
 					k := strings.ToLower(p.m.term)
+
 					err := m.treeTaxonomyEntries.WalkPrefix(
 						doctree.LockTypeRead,
 						paths.AddTrailingSlash(s),
-						func(s string, wn *weightedContentNode) (bool, error) {
+						func(ss string, wn *weightedContentNode) (bool, error) {
 							taxonomy[k] = append(taxonomy[k], page.NewWeightedPage(wn.weight, wn.n.(page.Page), wn.term.Page()))
 							return false, nil
 						},
diff --git a/hugolib/page__new.go b/hugolib/page__new.go
index 818cbb5db2b..2c2d92ab83e 100644
--- a/hugolib/page__new.go
+++ b/hugolib/page__new.go
@@ -148,6 +148,7 @@ func (h *HugoSites) newPage(m *pageMeta) (*pageState, *paths.Path, error) {
 						m.pageConfig.Kind = kinds.KindTaxonomy
 					} else {
 						m.pageConfig.Kind = kinds.KindTerm
+						m.term = m.pathInfo.Unnormalized().BaseNameNoIdentifier()
 					}
 				}
 			} else if m.f != nil {


Test patch:
diff --git a/hugolib/taxonomy_test.go b/hugolib/taxonomy_test.go
index 913f4c21daf..ffcb8fb15c7 100644
--- a/hugolib/taxonomy_test.go
+++ b/hugolib/taxonomy_test.go
@@ -776,3 +776,42 @@ Len Book Authors: {{ len (index .Site.Taxonomies $taxonomy) }}
 
 	b.AssertFileContent("public/index.html", "Len Book Authors: 2")
 }
+
+func TestTaxonomiesListTermsHome(t *testing.T) {
+	files := `
+-- hugo.toml --
+baseURL = "https://example.com"
+[taxonomies]
+tag = "tags"
+-- content/_index.md --
+---
+title: "Home"
+tags: ["a", "b", "c", "hello world"]
+---
+-- content/tags/a/_index.md --
+---
+title: "A"
+---
+-- content/tags/b/_index.md --
+---
+title: "B"
+---
+-- content/tags/c/_index.md --
+---
+title: "C"
+---
+-- content/tags/d/_index.md --
+---
+title: "D"
+---
+-- content/tags/hello-world/_index.md --
+---
+title: "Hello World!"
+---
+-- layouts/home.html --
+Terms: {{ range site.Taxonomies.tags }}{{ .Page.Title }}: {{ .Count }}|{{ end }}$
+`
+	b := Test(t, files)
+
+	b.AssertFileContent("public/index.html", "Terms: A: 1|B: 1|C: 1|Hello World!: 1|$")
+}