Fix bug in Site.assembleSections method
authorVas Sudanagunta <vas@commonkarma.org>
Sun, 25 Feb 2018 06:15:03 +0000 (01:15 -0500)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 25 Feb 2018 09:34:24 +0000 (10:34 +0100)
Site.assembleSections logic assumes that the the home page would always be the first in the Site's list of pages. This is not in fact guaranteed to be true. When it is not, the method can fail to set the parent for some or all root-level pages. 

Fixes #4447

hugolib/site_sections.go

index 1a42f78081ee6e4ce57d466e7216eb015037b03b..5de350b2fce30d842ef17e5eb88b2a1b6d902893 100644 (file)
@@ -167,11 +167,15 @@ func (s *Site) assembleSections() Pages {
                undecided  Pages
        )
 
+       homes := s.findPagesByKind(KindHome)
+       if len(homes) == 1 {
+               home = homes[0]
+       } else if len(homes) > 1 {
+               panic("Too many homes")
+       }
+
        for i, p := range s.Pages {
                if p.Kind != KindPage {
-                       if p.Kind == KindHome {
-                               home = p
-                       }
                        continue
                }