node to page: Fixe index page translation issues

Updates #2297
This commit is contained in:
Bjørn Erik Pedersen
2016-11-21 10:11:34 +01:00
parent aafbd3b4bf
commit 976f8f84bf
4 changed files with 79 additions and 17 deletions

View File

@@ -1608,19 +1608,19 @@ func (p *Page) Lang() string {
return p.lang
}
func (p *Page) isTranslation(candidate *Page) bool {
func (p *Page) isNewTranslation(candidate *Page) bool {
if p == candidate || p.Kind != candidate.Kind {
return false
}
if p.lang != candidate.lang || p.language != p.language {
return false
}
if p.Kind == KindPage || p.Kind == kindUnknown {
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) {
@@ -1633,6 +1633,13 @@ func (p *Page) isTranslation(candidate *Page) bool {
}
}
// Finally check that it is not already added.
for _, translation := range candidate.translations {
if p == translation {
return false
}
}
return true
}
@@ -1717,9 +1724,13 @@ func (p *Page) addLangFilepathPrefix(outfile string) string {
}
func sectionsFromFilename(filename string) []string {
var sections []string
dir, _ := filepath.Split(filename)
dir = strings.TrimSuffix(dir, helpers.FilePathSeparator)
sections := strings.Split(dir, helpers.FilePathSeparator)
if dir == "" {
return sections
}
sections = strings.Split(dir, helpers.FilePathSeparator)
return sections
}