@@ -154,13 +154,25 @@ func (s *Site) assembleSections() Pages {
154154 sect = s .newSectionPage (p .sections [0 ])
155155 sectionPages [sectionKey ] = sect
156156 newPages = append (newPages , sect )
157- } else if ! found {
158- // We don't know what to do with this section yet.
159- undecided = append (undecided , p )
157+ found = true
160158 }
161159
162- pagePath := path .Join (sectionKey , sectPageKey , strconv .Itoa (i ))
163- inPages .Insert ([]byte (pagePath ), p )
160+ if len (p .sections ) > 1 {
161+ // Create the root section if not found.
162+ _ , rootFound := sectionPages [p .sections [0 ]]
163+ if ! rootFound {
164+ sect = s .newSectionPage (p .sections [0 ])
165+ sectionPages [p .sections [0 ]] = sect
166+ newPages = append (newPages , sect )
167+ }
168+ }
169+
170+ if found {
171+ pagePath := path .Join (sectionKey , sectPageKey , strconv .Itoa (i ))
172+ inPages .Insert ([]byte (pagePath ), p )
173+ } else {
174+ undecided = append (undecided , p )
175+ }
164176 }
165177
166178 // Create any missing sections in the tree.
@@ -181,17 +193,6 @@ func (s *Site) assembleSections() Pages {
181193 }
182194 }
183195
184- // Create any missing root sections.
185- for _ , p := range undecided {
186- sectionKey := p .sections [0 ]
187- sect , found := sectionPages [sectionKey ]
188- if ! found {
189- sect = s .newSectionPage (sectionKey )
190- sectionPages [sectionKey ] = sect
191- newPages = append (newPages , sect )
192- }
193- }
194-
195196 for k , sect := range sectionPages {
196197 inPages .Insert ([]byte (path .Join (k , sectSectKey )), sect )
197198 inSections .Insert ([]byte (k ), sect )
@@ -200,10 +201,20 @@ func (s *Site) assembleSections() Pages {
200201 var (
201202 currentSection * Page
202203 children Pages
203- rootPages = inPages .Commit ().Root ()
204204 rootSections = inSections .Commit ().Root ()
205205 )
206206
207+ for i , p := range undecided {
208+ // Now we can decide where to put this page into the tree.
209+ sectionKey := path .Join (p .sections ... )
210+ _ , v , _ := rootSections .LongestPrefix ([]byte (sectionKey ))
211+ sect := v .(* Page )
212+ pagePath := path .Join (path .Join (sect .sections ... ), sectSectKey , "u" , strconv .Itoa (i ))
213+ inPages .Insert ([]byte (pagePath ), p )
214+ }
215+
216+ var rootPages = inPages .Commit ().Root ()
217+
207218 rootPages .Walk (func (path []byte , v interface {}) bool {
208219 p := v .(* Page )
209220
0 commit comments