Skip to content

Commit

Permalink
Fix regression for outputs defined in front matter for term pages
Browse files Browse the repository at this point in the history
Fixes #12275
  • Loading branch information
bep committed Mar 19, 2024
1 parent 90bc1f8 commit 0750a9e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
5 changes: 5 additions & 0 deletions hugolib/content_map_page.go
Expand Up @@ -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
}
Expand Down
12 changes: 7 additions & 5 deletions hugolib/hugo_sites_build.go
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
37 changes: 37 additions & 0 deletions hugolib/site_output_test.go
Expand Up @@ -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
}

0 comments on commit 0750a9e

Please sign in to comment.