Fix translationKey handling for term pages

Fixes #12261
This commit is contained in:
Bjørn Erik Pedersen 2024-03-15 16:21:25 +01:00
parent b40f3c7df6
commit 68d92ef9dd
2 changed files with 52 additions and 7 deletions

View file

@ -1500,13 +1500,6 @@ func (sa *sitePagesAssembler) assembleTermsAndTranslations() error {
return false, nil return false, nil
} }
// This is a little out of place, but is conveniently put here.
// Check if translationKey is set by user.
// This is to support the manual way of setting the translationKey in front matter.
if ps.m.pageConfig.TranslationKey != "" {
sa.s.h.translationKeyPages.Append(ps.m.pageConfig.TranslationKey, ps)
}
if sa.pageMap.cfg.taxonomyTermDisabled { if sa.pageMap.cfg.taxonomyTermDisabled {
return false, nil return false, nil
} }
@ -1587,6 +1580,13 @@ func (sa *sitePagesAssembler) assembleResources() error {
Handle: func(s string, n contentNodeI, match doctree.DimensionFlag) (bool, error) { Handle: func(s string, n contentNodeI, match doctree.DimensionFlag) (bool, error) {
ps := n.(*pageState) ps := n.(*pageState)
// This is a little out of place, but is conveniently put here.
// Check if translationKey is set by user.
// This is to support the manual way of setting the translationKey in front matter.
if ps.m.pageConfig.TranslationKey != "" {
sa.s.h.translationKeyPages.Append(ps.m.pageConfig.TranslationKey, ps)
}
// Prepare resources for this page. // Prepare resources for this page.
ps.shiftToOutputFormat(true, 0) ps.shiftToOutputFormat(true, 0)
targetPaths := ps.targetPaths() targetPaths := ps.targetPaths()

View file

@ -1350,6 +1350,51 @@ AllTranslations: {{ range .AllTranslations }}{{ .Language.Lang }}|{{ end }}|
) )
} }
func TestTranslationKeyTermPages(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
disableKinds = ['home','rss','section','sitemap','taxonomy']
defaultContentLanguage = 'en'
defaultContentLanguageInSubdir = true
[languages.en]
weight = 1
[languages.pt]
weight = 2
[taxonomies]
category = 'categories'
-- layouts/_default/list.html --
{{ .IsTranslated }}|{{ range .Translations }}{{ .RelPermalink }}|{{ end }}
-- layouts/_default/single.html --
{{ .Title }}|
-- content/p1.en.md --
---
title: p1 (en)
categories: [music]
---
-- content/p1.pt.md --
---
title: p1 (pt)
categories: [música]
---
-- content/categories/music/_index.en.md --
---
title: music
translationKey: foo
---
-- content/categories/música/_index.pt.md --
---
title: música
translationKey: foo
---
`
b := Test(t, files)
b.AssertFileContent("public/en/categories/music/index.html", "true|/pt/categories/m%C3%BAsica/|")
b.AssertFileContent("public/pt/categories/música/index.html", "true|/en/categories/music/|")
}
// Issue #11540. // Issue #11540.
func TestTranslationKeyResourceSharing(t *testing.T) { func TestTranslationKeyResourceSharing(t *testing.T) {
files := ` files := `