]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix translationKey handling for term pages
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 15 Mar 2024 15:21:25 +0000 (16:21 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 15 Mar 2024 15:54:18 +0000 (16:54 +0100)
Fixes #12261

hugolib/content_map_page.go
hugolib/page_test.go

index 906fced77d4148f32a9b11055b3b8cc31dc6a47d..64a15a59a33338244a2c7ae5065f9028e2cbc622 100644 (file)
@@ -1500,13 +1500,6 @@ func (sa *sitePagesAssembler) assembleTermsAndTranslations() error {
                                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 {
                                return false, nil
                        }
@@ -1587,6 +1580,13 @@ func (sa *sitePagesAssembler) assembleResources() error {
                Handle: func(s string, n contentNodeI, match doctree.DimensionFlag) (bool, error) {
                        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.
                        ps.shiftToOutputFormat(true, 0)
                        targetPaths := ps.targetPaths()
index b0ab7f09c597a6fcf656a83ae1bc82177a4d2e76..f22a4d07cd7b2271400c17216a16fffeddb1e6eb 100644 (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.
 func TestTranslationKeyResourceSharing(t *testing.T) {
        files := `