Repository: gohugoio/hugo (language: go)

Issue:
Front matter output formats ignored for term page
This worked with v0.122.0.

Reference: <https://discourse.gohugo.io/t/per-page-output-format-setting-for-a-taxonomy-term-isnt-considered/48911>

Failing test:

```go
func TestFoo(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
disableKinds = ['home','page','rss','section','sitemap','taxonomy']
-- content/p1.md --
---
title: p1
tags:
  - tag-a
  - tag-b
---
-- content/tags/tag-a/_index.md --
---
title: tag-a
outputs:
  - html
  - json
---
-- content/tags/tag-b/_index.md --
---
title: tag-b
---
-- layouts/_default/term.html --
{{ .Title }}
-- layouts/_default/term.json --
{{ jsonify (dict "title" .Title) }}
`

	b := hugolib.Test(t, files)

	b.AssertFileContent("public/tags/tag-a/index.html", "tag-a")
	b.AssertFileContent("public/tags/tag-b/index.html", "tag-b")
	b.AssertFileContent("public/tags/tag-a/index.json", `{"title":"tag-a"}`) // failing test
}
```


Discussion / hints:

Fix patch:
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go
index 64a15a59a33..f4ff2a9ee28 100644
--- a/hugolib/content_map_page.go
+++ b/hugolib/content_map_page.go
@@ -1678,6 +1678,11 @@ func (sa *sitePagesAssembler) assemblePagesStep2() error {
 	if err := sa.applyAggregatesToTaxonomiesAndTerms(); err != nil {
 		return err
 	}
+
+	return nil
+}
+
+func (sa *sitePagesAssembler) assemblePagesStepFinal() error {
 	if err := sa.assembleResources(); err != nil {
 		return err
 	}
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index c33f06bd5ae..cc8847f5591 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -282,11 +282,6 @@ func (h *HugoSites) assemble(ctx context.Context, l logg.LevelLogger, bcfg *Buil
 			return err
 		}
 	}
-	h.renderFormats = output.Formats{}
-	for _, s := range h.Sites {
-		s.s.initRenderFormats()
-		h.renderFormats = append(h.renderFormats, s.renderFormats...)
-	}
 
 	for _, s := range assemblers {
 		if err := s.assemblePagesStep2(); err != nil {
@@ -296,9 +291,16 @@ func (h *HugoSites) assemble(ctx context.Context, l logg.LevelLogger, bcfg *Buil
 
 	h.renderFormats = output.Formats{}
 	for _, s := range h.Sites {
+		s.s.initRenderFormats()
 		h.renderFormats = append(h.renderFormats, s.renderFormats...)
 	}
 
+	for _, s := range assemblers {
+		if err := s.assemblePagesStepFinal(); err != nil {
+			return err
+		}
+	}
+
 	return nil
 }
 


Test patch:
diff --git a/hugolib/site_output_test.go b/hugolib/site_output_test.go
index a68555574c0..3d95709c50e 100644
--- a/hugolib/site_output_test.go
+++ b/hugolib/site_output_test.go
@@ -646,3 +646,40 @@ WordCount: {{ .WordCount }}
 	b.AssertFileContent("public/outputs-empty/index.html", "HTML:", "Word1. Word2.")
 	b.AssertFileContent("public/outputs-string/index.html", "O1:", "Word1. Word2.")
 }
+
+func TestOuputFormatFrontMatterTermIssue12275(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+disableKinds = ['home','page','rss','section','sitemap','taxonomy']
+-- content/p1.md --
+---
+title: p1
+tags:
+  - tag-a
+  - tag-b
+---
+-- content/tags/tag-a/_index.md --
+---
+title: tag-a
+outputs:
+  - html
+  - json
+---
+-- content/tags/tag-b/_index.md --
+---
+title: tag-b
+---
+-- layouts/_default/term.html --
+{{ .Title }}
+-- layouts/_default/term.json --
+{{ jsonify (dict "title" .Title) }}
+`
+
+	b := Test(t, files)
+
+	b.AssertFileContent("public/tags/tag-a/index.html", "tag-a")
+	b.AssertFileContent("public/tags/tag-b/index.html", "tag-b")
+	b.AssertFileContent("public/tags/tag-a/index.json", `{"title":"tag-a"}`) // failing test
+}