ref: 88b5bbd5329a87046979e222a9ccf74eda59df3c
parent: d1b89f5c7cb3d1031d74014b4b2150a434bf557e
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Fri Dec 23 04:52:05 EST 2016
hugolib: Fix IsTranslated for "old" node types The new logic for creating Page objects from old node types didn't include itself in the translation logic, so `IsTranslated` returned falsely false for sites with only two languages. The `AllTranslations` method also returned too few pages in that case. This commit fixes that. Fixes #2812
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -180,7 +180,7 @@
// Assign translations
for _, t1 := range nodes {
for _, t2 := range nodes {
- if t2.isNewTranslation(t1) {
+ if t1.isNewTranslation(t2) {
t1.translations = append(t1.translations, t2)
}
}
--- a/hugolib/hugo_sites_build_test.go
+++ b/hugolib/hugo_sites_build_test.go
@@ -186,6 +186,49 @@
}
}
+func TestMultiSitesWithTwoLanguages(t *testing.T) {
+ testCommonResetState()
+
+ viper.Set("defaultContentLanguage", "nn")
+
+ writeSource(t, "config.toml", `
+[languages]
+[languages.nn]
+languageName = "Nynorsk"
+weight = 1
+title = "Tittel på Nynorsk"
+
+[languages.en]
+title = "Title in English"
+languageName = "English"
+weight = 2
+`,
+ )
+
+ if err := LoadGlobalConfig("", "config.toml"); err != nil {
+ t.Fatalf("Failed to load config: %s", err)
+ }
+
+ // Add some data
+ writeSource(t, "data/hugo.toml", "slogan = \"Hugo Rocks!\"")
+
+ sites, err := NewHugoSitesFromConfiguration()
+
+ if err != nil {
+ t.Fatalf("Failed to create sites: %s", err)
+ }
+
+ require.NoError(t, sites.Build(BuildCfg{}))
+ require.Len(t, sites.Sites, 2)
+
+ nnSite := sites.Sites[0]
+ nnSiteHome := nnSite.getPage(KindHome)
+ require.Len(t, nnSiteHome.AllTranslations(), 2)
+ require.Len(t, nnSiteHome.Translations(), 1)
+ require.True(t, nnSiteHome.IsTranslated())
+
+}
+
//
func TestMultiSitesBuild(t *testing.T) {
for _, config := range []struct {
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -1626,7 +1626,8 @@
}
func (p *Page) isNewTranslation(candidate *Page) bool {
- if p == candidate || p.Kind != candidate.Kind {
+
+ if p.Kind != candidate.Kind {
return false
}
@@ -1634,10 +1635,6 @@
panic("Node type not currently supported for this op")
}
- if p.language.Lang == candidate.language.Lang {
- return false
- }
-
// At this point, we know that this is a traditional Node (home page, section, taxonomy)
// It represents the same node, but different language, if the sections is the same.
if len(p.sections) != len(candidate.sections) {
@@ -1651,8 +1648,8 @@
}
// Finally check that it is not already added.
- for _, translation := range candidate.translations {
- if p == translation {
+ for _, translation := range p.translations {
+ if candidate == translation {
return false
}
}
--
⑨