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
This commit is contained in:
Bjørn Erik Pedersen
2016-12-23 09:52:05 +01:00
parent d1b89f5c7c
commit 88b5bbd532
3 changed files with 48 additions and 8 deletions

View File

@@ -1626,7 +1626,8 @@ func (p *Page) Lang() string {
}
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 @@ func (p *Page) isNewTranslation(candidate *Page) bool {
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 @@ func (p *Page) isNewTranslation(candidate *Page) bool {
}
// 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
}
}