summaryrefslogtreecommitdiffstats
path: root/hugolib/site_sections.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-06-13 11:26:17 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-06-13 12:41:50 +0200
commita30023f5cbafd06034807255181a5b7b17f3c25f (patch)
tree9ac02e1132df8dffabe22adf054a7e04a3c8e0d6 /hugolib/site_sections.go
parent1f26420d392a5ab4c7b7fe1911c0268b45d01ab8 (diff)
hugolib: Fix section logic for root folders with subfolders
This commit fixes an issue introduced in the recently released Hugo 0.22. This logic did not handle the case with root sections with non-section subfolders very well. Fixes #3586
Diffstat (limited to 'hugolib/site_sections.go')
-rw-r--r--hugolib/site_sections.go45
1 files changed, 28 insertions, 17 deletions
diff --git a/hugolib/site_sections.go b/hugolib/site_sections.go
index 151baac84..891980be2 100644
--- a/hugolib/site_sections.go
+++ b/hugolib/site_sections.go
@@ -154,13 +154,25 @@ func (s *Site) assembleSections() Pages {
sect = s.newSectionPage(p.sections[0])
sectionPages[sectionKey] = sect
newPages = append(newPages, sect)
- } else if !found {
- // We don't know what to do with this section yet.
- undecided = append(undecided, p)
+ found = true
}
- pagePath := path.Join(sectionKey, sectPageKey, strconv.Itoa(i))
- inPages.Insert([]byte(pagePath), p)
+ if len(p.sections) > 1 {
+ // Create the root section if not found.
+ _, rootFound := sectionPages[p.sections[0]]
+ if !rootFound {
+ sect = s.newSectionPage(p.sections[0])
+ sectionPages[p.sections[0]] = sect
+ newPages = append(newPages, sect)
+ }
+ }
+
+ if found {
+ pagePath := path.Join(sectionKey, sectPageKey, strconv.Itoa(i))
+ inPages.Insert([]byte(pagePath), p)
+ } else {
+ undecided = append(undecided, p)
+ }
}
// Create any missing sections in the tree.
@@ -181,17 +193,6 @@ func (s *Site) assembleSections() Pages {
}
}
- // Create any missing root sections.
- for _, p := range undecided {
- sectionKey := p.sections[0]
- sect, found := sectionPages[sectionKey]
- if !found {
- sect = s.newSectionPage(sectionKey)
- sectionPages[sectionKey] = sect
- newPages = append(newPages, sect)
- }
- }
-
for k, sect := range sectionPages {
inPages.Insert([]byte(path.Join(k, sectSectKey)), sect)
inSections.Insert([]byte(k), sect)
@@ -200,10 +201,20 @@ func (s *Site) assembleSections() Pages {
var (
currentSection *Page
children Pages
- rootPages = inPages.Commit().Root()
rootSections = inSections.Commit().Root()
)
+ for i, p := range undecided {
+ // Now we can decide where to put this page into the tree.
+ sectionKey := path.Join(p.sections...)
+ _, v, _ := rootSections.LongestPrefix([]byte(sectionKey))
+ sect := v.(*Page)
+ pagePath := path.Join(path.Join(sect.sections...), sectSectKey, "u", strconv.Itoa(i))
+ inPages.Insert([]byte(pagePath), p)
+ }
+
+ var rootPages = inPages.Commit().Root()
+
rootPages.Walk(func(path []byte, v interface{}) bool {
p := v.(*Page)