Repository: gohugoio/hugo (language: go)

Issue:
Empty section pages created when using nested taxonomies
Not sure if this is a bug, but the result is different (undesirable) when comparing v0.123.7 to v0.122.0.

#### Scenario

- Multilingual single-host site
- English site has content, Japanese site **has no content**
- Site has a language switcher to switch between langs on each page
- Taxonomies are "nested' by content type (support  for this is not documented, but I've seen it used on several sites):

```text
[taxonomies]
'papers/category' = 'papers/category'
'blog/category' = 'blog/category'
```

#### Expected (v0.122.0)

```text
public/ja/
├── blog/
│   └── category/
│       └── index.html
├── papers/
│   └── category/
│       └── index.html
└── index.html
```

#### Actual (v0.123.6)

```text
public/ja/
├── blog/
│   ├── category/
│   │   └── index.html
│   └── index.html     <-- problem: has section page despite lack of content
├── papers/
│   ├── category/
│   │   └── index.html
│   └── index.html     <-- problem: has section page despite lack of content
└── index.html 
```

#### Why  is this a problem?

When visiting the "blog" section page on the English site, the language switcher indicates that there is a Japanese translation, which is (obviously) just an empty page.

#### Test case

<details>
<summary>test case</summary>

```go
func TestFoo(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
disableKinds = ['rss','sitemap']
defaultContentLanguage = 'en'
defaultContentLanguageInSubdir = true
[languages.en]
weight = 1
[languages.ja]
weight = 2
[taxonomies]
's1/category' = 's1/category'
-- layouts/_default/single.html --
{{ .Title }}|
-- layouts/_default/list.html --
{{ .Title }}|
-- content/s1/p1.en.md --
---
title: p1
---
`

	b := hugolib.Test(t, files)

	b.AssertFileExists("public/en/s1/index.html", true)
	b.AssertFileExists("public/en/s1/p1/index.html", true)
	b.AssertFileExists("public/en/s1/category/index.html", true)

	b.AssertFileExists("public/ja/s1/index.html", false) // failing test
	b.AssertFileExists("public/ja/s1/category/index.html", true)
}
```
</details>
<br>

Reference: <https://discourse.gohugo.io/t/hugo-attempting-to-build-pages-on-multilingual-site-for-languages-with-no-content/48561/4>


Discussion / hints:
Another way in which this causes problems is that templates can fail due to missing data on pages that weren't intended to build, nor have content.

For instance, I discovered this due to a template rendering data from the frontmatter, but since it was attempting to build for all defined languages, it was throwing errors. This is resolvable by wrapping in a `with` or `if` block, but if for some reason I wanted it to fail in the absence of data for actual content pages, this would be undesirable.

Fix patch:
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go
index ddc22bb6652..76407862368 100644
--- a/hugolib/content_map_page.go
+++ b/hugolib/content_map_page.go
@@ -485,7 +485,7 @@ func (m *pageMap) forEachResourceInPage(
 	rw.Handle = func(resourceKey string, n contentNodeI, match doctree.DimensionFlag) (bool, error) {
 		if isBranch {
 			ownerKey, _ := m.treePages.LongestPrefixAll(resourceKey)
-			if ownerKey != keyPage {
+			if ownerKey != keyPage && path.Dir(ownerKey) != path.Dir(resourceKey) {
 				// Stop walking downwards, someone else owns this resource.
 				rw.SkipPrefix(ownerKey + "/")
 				return false, nil
@@ -1814,6 +1814,14 @@ func (sa *sitePagesAssembler) addMissingRootSections() error {
 				return false, nil
 			}
 
+			switch ps.Kind() {
+			case kinds.KindPage, kinds.KindSection:
+				// OK
+			default:
+				// Skip taxonomy nodes etc.
+				return false, nil
+			}
+
 			p := ps.m.pathInfo
 			section := p.Section()
 			if section == "" || seen[section] {
diff --git a/hugolib/page__new.go b/hugolib/page__new.go
index 9dd2f2cdfa9..e14de692549 100644
--- a/hugolib/page__new.go
+++ b/hugolib/page__new.go
@@ -145,9 +145,11 @@ func (h *HugoSites) newPage(m *pageMeta) (*pageState, *paths.Path, error) {
 					// Either a taxonomy or a term.
 					if tc.pluralTreeKey == m.Path() {
 						m.pageConfig.Kind = kinds.KindTaxonomy
+						m.singular = tc.singular
 					} else {
 						m.pageConfig.Kind = kinds.KindTerm
 						m.term = m.pathInfo.Unnormalized().BaseNameNoIdentifier()
+						m.singular = tc.singular
 					}
 				}
 			} else if m.f != nil {
diff --git a/resources/resource_factories/create/create.go b/resources/resource_factories/create/create.go
index ac1a2af0777..1ecc4652d03 100644
--- a/resources/resource_factories/create/create.go
+++ b/resources/resource_factories/create/create.go
@@ -128,13 +128,16 @@ func (c *Client) match(name, pattern string, matchFunc func(r resource.Resource)
 
 		handle := func(info hugofs.FileMetaInfo) (bool, error) {
 			meta := info.Meta()
+
 			r, err := c.rs.NewResource(resources.ResourceSourceDescriptor{
 				LazyPublish: true,
 				OpenReadSeekCloser: func() (hugio.ReadSeekCloser, error) {
 					return meta.Open()
 				},
-				GroupIdentity: meta.PathInfo,
-				TargetPath:    meta.PathInfo.Unnormalized().Path(),
+				NameNormalized: meta.PathInfo.Name(),
+				NameOriginal:   meta.PathInfo.Unnormalized().Name(),
+				GroupIdentity:  meta.PathInfo,
+				TargetPath:     meta.PathInfo.Unnormalized().Path(),
 			})
 			if err != nil {
 				return true, err


Test patch:
diff --git a/hugolib/content_map_test.go b/hugolib/content_map_test.go
index e043d936385..85e2c60560c 100644
--- a/hugolib/content_map_test.go
+++ b/hugolib/content_map_test.go
@@ -326,3 +326,35 @@ R: {{ with $r }}{{ .Content }}{{ end }}|Len: {{ len $bundle.Resources }}|$
 		b.AssertFileContent("public/index.html", "R: Data 1.txt|", "Len: 1|")
 	}
 }
+
+func TestBundleResourcesNoPublishedIssue12198(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+disableKinds = ['home','rss','sitemap','taxonomy','term']
+-- content/s1/p1.md --
+---
+title: p1
+---
+-- content/s1/foo.txt --
+foo.txt
+-- content/s1/p1.txt --
+p1.txt
+-- content/s1/p1-foo.txt --
+p1-foo.txt
+-- layouts/_default/list.html --
+{{.Title }}|
+-- layouts/_default/single.html --
+{{.Title }}|
+	`
+
+	b := Test(t, files)
+	b.Build()
+
+	b.AssertFileExists("public/s1/index.html", true)
+	b.AssertFileExists("public/s1/foo.txt", true)
+	b.AssertFileExists("public/s1/p1.txt", true)     // failing test
+	b.AssertFileExists("public/s1/p1-foo.txt", true) // failing test
+	b.AssertFileExists("public/s1/p1/index.html", true)
+}
diff --git a/hugolib/mount_filters_test.go b/hugolib/mount_filters_test.go
index 16b062ec6cc..eec2e713d2d 100644
--- a/hugolib/mount_filters_test.go
+++ b/hugolib/mount_filters_test.go
@@ -112,6 +112,6 @@ Template: false
 Resource1: /js/include.js:END
 Resource2: :END
 Resource3: :END
-Resources: [/js/include.js]
+Resources: [include.js]
 `)
 }
diff --git a/hugolib/taxonomy_test.go b/hugolib/taxonomy_test.go
index 5a48df3b7cf..bfdfd8dfdc2 100644
--- a/hugolib/taxonomy_test.go
+++ b/hugolib/taxonomy_test.go
@@ -911,3 +911,62 @@ title: tag-a-title-override
 
 	b.AssertFileContent("public/tags/a/index.html", "Tag: tag-a-title-override|")
 }
+
+func TestTaxonomyLookupIssue12193(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+disableKinds = ['page','rss','section','sitemap']
+[taxonomies]
+author = 'authors'
+-- layouts/_default/list.html --
+{{ .Title }}|
+-- layouts/_default/author.terms.html --
+layouts/_default/author.terms.html
+-- content/authors/_index.md --
+---
+title: Authors Page
+---
+`
+
+	b := Test(t, files)
+
+	b.AssertFileExists("public/index.html", true)
+	b.AssertFileExists("public/authors/index.html", true)
+	b.AssertFileContent("public/authors/index.html", "layouts/_default/author.terms.html") // failing test
+}
+
+func TestTaxonomyNestedEmptySectionsIssue12188(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+disableKinds = ['rss','sitemap']
+defaultContentLanguage = 'en'
+defaultContentLanguageInSubdir = true
+[languages.en]
+weight = 1
+[languages.ja]
+weight = 2
+[taxonomies]
+'s1/category' = 's1/category'
+-- layouts/_default/single.html --
+{{ .Title }}|
+-- layouts/_default/list.html --
+{{ .Title }}|
+-- content/s1/p1.en.md --
+---
+title: p1
+---
+`
+
+	b := Test(t, files)
+
+	b.AssertFileExists("public/en/s1/index.html", true)
+	b.AssertFileExists("public/en/s1/p1/index.html", true)
+	b.AssertFileExists("public/en/s1/category/index.html", true)
+
+	b.AssertFileExists("public/ja/s1/index.html", false) // failing test
+	b.AssertFileExists("public/ja/s1/category/index.html", true)
+}
diff --git a/tpl/resources/resources_integration_test.go b/tpl/resources/resources_integration_test.go
index d72b1350729..b4630b6a237 100644
--- a/tpl/resources/resources_integration_test.go
+++ b/tpl/resources/resources_integration_test.go
@@ -143,3 +143,31 @@ ByType: /401K%20Prospectus.txt|http://example.com/401K%20Prospectus.txt|
 
 		`)
 }
+
+func TestGlobalResourcesNotPublishedRegressionIssue12190(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+disableKinds = ['page','rss','section','sitemap','taxonomy','term']
+-- assets/a.txt --
+I am a.txt
+-- assets/b.txt --
+I am b.txt
+-- layouts/index.html --
+Home.
+{{ with resources.ByType "text" }}
+  {{ with .Get "a.txt" }}
+    {{ .Publish }}
+  {{ end }}
+  {{ with .GetMatch "*b*" }}
+    {{ .Publish }}
+  {{ end }}
+{{ end }}
+`
+
+	b := hugolib.Test(t, files)
+
+	b.AssertFileExists("public/a.txt", true) // failing test
+	b.AssertFileExists("public/b.txt", true) // failing test
+}