Repository: gohugoio/hugo (language: go)

Issue:
Draft term pages not handled correctly
hugo v0.123.0-DEV-9cc65757a



This test fails:

```go
func TestFoo(t *testing.T) {
	t.Parallel()

	files := `
-- layouts/_default/list.html --
|{{ .Title }}|
-- content/p1.md --
---
title: p1
tags: [a]
---
-- content/tags/a/_index.md --
---
title: tag-a-title-override
draft: true
---
  `

	b := hugolib.Test(t, files)

	b.AssertFileContent("public/tags/a/index.html", "|a|")
}
```

Want:

```
|a|
```

Got:

```text
|tag-a-title-override|
```


Discussion / hints:
I'm waiting on some new eye glasses. Just made a couple of edits to the above.
Although the page title rendered above looks wrong to me, I have also lost/forgotten whether we should render the term page at all. Per [this discussion](https://github.com/gohugoio/hugo/issues/11809#issuecomment-1859251239), it seems like we should not render the term page if draft is true, but things may have changed since then.

Fix patch:
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go
index 70e8a0bb6b3..d9cbddfba62 100644
--- a/hugolib/content_map_page.go
+++ b/hugolib/content_map_page.go
@@ -1415,8 +1415,10 @@ func (sa *sitePagesAssembler) applyAggregatesToTaxonomiesAndTerms() error {
 					if err := p.setMetaPost(cascade); err != nil {
 						return false, err
 					}
-
-					if err := sa.pageMap.treeTaxonomyEntries.WalkPrefix(
+					if !p.s.shouldBuild(p) {
+						sa.pageMap.treePages.Delete(s)
+						sa.pageMap.treeTaxonomyEntries.DeletePrefix(paths.AddTrailingSlash(s))
+					} else if err := sa.pageMap.treeTaxonomyEntries.WalkPrefix(
 						doctree.LockTypeRead,
 						paths.AddTrailingSlash(s),
 						func(ss string, wn *weightedContentNode) (bool, error) {


Test patch:
diff --git a/hugolib/taxonomy_test.go b/hugolib/taxonomy_test.go
index 17e1b6cd406..8c29b781e48 100644
--- a/hugolib/taxonomy_test.go
+++ b/hugolib/taxonomy_test.go
@@ -835,3 +835,26 @@ tags: ["hellO world"]
 
 	b.AssertFileContent("public/tags/hello-world/index.html", "HellO World|term|tag|tags|hellO world|")
 }
+
+func TestTermDraft(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- layouts/_default/list.html --
+|{{ .Title }}|
+-- content/p1.md --
+---
+title: p1
+tags: [a]
+---
+-- content/tags/a/_index.md --
+---
+title: tag-a-title-override
+draft: true
+---
+  `
+
+	b := Test(t, files)
+
+	b.AssertFileExists("public/tags/a/index.html", false)
+}