node to page: Get Rebuild up to speed
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 9 Nov 2016 08:58:18 +0000 (09:58 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 22 Nov 2016 08:57:03 +0000 (09:57 +0100)
Updates #2297

hugolib/hugo_sites.go
hugolib/hugo_sites_test.go
hugolib/site.go

index f1fe46199e2420497844fe69b1e4e3f5c03a0451..6bf2f19032fbbfd87538f35e0ad8fdff6a1c93a9 100644 (file)
@@ -194,7 +194,7 @@ func (h *HugoSites) Build(config BuildCfg) error {
                return err
        }
 
-       h.setupTranslationsForRegularPages()
+       h.setupTranslations()
 
        if len(h.Sites) > 1 {
                // Initialize the rest
@@ -289,7 +289,7 @@ func (h *HugoSites) Rebuild(config BuildCfg, events ...fsnotify.Event) error {
        }
 
        // Assign pages to sites per translation.
-       h.setupTranslationsForRegularPages()
+       h.setupTranslations()
 
        if changed.source {
                h.assembleGitInfo()
@@ -299,13 +299,21 @@ func (h *HugoSites) Rebuild(config BuildCfg, events ...fsnotify.Event) error {
                        }
                }
 
-               if err := h.createMissingNodes(); err != nil {
-                       return err
-               }
+       }
 
-               if err := h.assignMissingTranslations(); err != nil {
-                       return err
-               }
+       // TODO(bep) np consolidate the build lifecycle methods
+       // See also the regular Build() method, and check vs. the changed.source
+       if err := h.createMissingNodes(); err != nil {
+               return err
+       }
+
+       for _, s := range h.Sites {
+               s.refreshPageCaches()
+               s.setupPrevNext()
+       }
+
+       if err := h.assignMissingTranslations(); err != nil {
+               return err
        }
 
        if err := h.preRender(config, changed); err != nil {
@@ -557,13 +565,11 @@ func (s *Site) newTaxonomyTermsPage(plural string) *Page {
        return p
 }
 
-func (h *HugoSites) setupTranslationsForRegularPages() {
+func (h *HugoSites) setupTranslations() {
 
        master := h.Sites[0]
 
-       regularPages := master.rawAllPages // master.findRawAllPagesByNodeType(NodePage)
-
-       for _, p := range regularPages {
+       for _, p := range master.rawAllPages {
                if p.Lang() == "" {
                        panic("Page language missing: " + p.Title)
                }
index bdcf7d92c98e8a9013828dc9ff1929d497ae52aa..1840821fdb3efd2c0e79782055f2f9b7690bef0d 100644 (file)
@@ -51,8 +51,7 @@ func testCommonResetState() {
 func TestMultiSitesMainLangInRoot(t *testing.T) {
        //jww.SetStdoutThreshold(jww.LevelDebug)
 
-       // TODO(bep) np true false
-       for _, b := range []bool{true} {
+       for _, b := range []bool{true, false} {
                doTestMultiSitesMainLangInRoot(t, b)
        }
 }
@@ -366,8 +365,6 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
 }
 
 func TestMultiSitesRebuild(t *testing.T) {
-       // TODO(bep) np TestMultiSitesRebuild
-       t.Skip()
 
        defer leaktest.Check(t)()
        testCommonResetState()
@@ -390,14 +387,12 @@ func TestMultiSitesRebuild(t *testing.T) {
        enSite := sites.Sites[0]
        frSite := sites.Sites[1]
 
-       assert.Len(t, enSite.Pages, 3)
-       assert.Len(t, frSite.Pages, 3)
+       require.Len(t, enSite.Pages, 3)
+       require.Len(t, frSite.Pages, 3)
 
        // Verify translations
-       docEn := readDestination(t, "public/en/sect/doc1-slug/index.html")
-       assert.True(t, strings.Contains(docEn, "Hello"), "No Hello")
-       docFr := readDestination(t, "public/fr/sect/doc1/index.html")
-       assert.True(t, strings.Contains(docFr, "Bonjour"), "No Bonjour")
+       assertFileContent(t, "public/en/sect/doc1-slug/index.html", true, "Hello")
+       assertFileContent(t, "public/fr/sect/doc1/index.html", true, "Bonjour")
 
        // check single page content
        assertFileContent(t, "public/fr/sect/doc1/index.html", true, "Single", "Shortcode: Bonjour")
@@ -419,15 +414,15 @@ func TestMultiSitesRebuild(t *testing.T) {
                        nil,
                        []fsnotify.Event{{Name: "content/sect/doc2.en.md", Op: fsnotify.Remove}},
                        func(t *testing.T) {
-                               assert.Len(t, enSite.Pages, 2, "1 en removed")
+                               require.Len(t, enSite.Pages, 2, "1 en removed")
 
                                // Check build stats
-                               assert.Equal(t, 1, enSite.draftCount, "Draft")
-                               assert.Equal(t, 1, enSite.futureCount, "Future")
-                               assert.Equal(t, 1, enSite.expiredCount, "Expired")
-                               assert.Equal(t, 0, frSite.draftCount, "Draft")
-                               assert.Equal(t, 1, frSite.futureCount, "Future")
-                               assert.Equal(t, 1, frSite.expiredCount, "Expired")
+                               require.Equal(t, 1, enSite.draftCount, "Draft")
+                               require.Equal(t, 1, enSite.futureCount, "Future")
+                               require.Equal(t, 1, enSite.expiredCount, "Expired")
+                               require.Equal(t, 0, frSite.draftCount, "Draft")
+                               require.Equal(t, 1, frSite.futureCount, "Future")
+                               require.Equal(t, 1, frSite.expiredCount, "Expired")
                        },
                },
                {
@@ -442,15 +437,15 @@ func TestMultiSitesRebuild(t *testing.T) {
                                {Name: "content/new1.fr.md", Op: fsnotify.Create},
                        },
                        func(t *testing.T) {
-                               assert.Len(t, enSite.Pages, 4)
-                               assert.Len(t, enSite.AllPages, 10)
-                               assert.Len(t, frSite.Pages, 4)
-                               assert.Equal(t, "new_fr_1", frSite.Pages[3].Title)
-                               assert.Equal(t, "new_en_2", enSite.Pages[0].Title)
-                               assert.Equal(t, "new_en_1", enSite.Pages[1].Title)
+                               require.Len(t, enSite.Pages, 4)
+                               require.Len(t, enSite.AllPages, 10)
+                               require.Len(t, frSite.Pages, 4)
+                               require.Equal(t, "new_fr_1", frSite.Pages[3].Title)
+                               require.Equal(t, "new_en_2", enSite.Pages[0].Title)
+                               require.Equal(t, "new_en_1", enSite.Pages[1].Title)
 
                                rendered := readDestination(t, "public/en/new1/index.html")
-                               assert.True(t, strings.Contains(rendered, "new_en_1"), rendered)
+                               require.True(t, strings.Contains(rendered, "new_en_1"), rendered)
                        },
                },
                {
@@ -462,9 +457,9 @@ func TestMultiSitesRebuild(t *testing.T) {
                        },
                        []fsnotify.Event{{Name: "content/sect/doc1.en.md", Op: fsnotify.Write}},
                        func(t *testing.T) {
-                               assert.Len(t, enSite.Pages, 4)
+                               require.Len(t, enSite.Pages, 4)
                                doc1 := readDestination(t, "public/en/sect/doc1-slug/index.html")
-                               assert.True(t, strings.Contains(doc1, "CHANGED"), doc1)
+                               require.True(t, strings.Contains(doc1, "CHANGED"), doc1)
 
                        },
                },
@@ -480,10 +475,10 @@ func TestMultiSitesRebuild(t *testing.T) {
                                {Name: "content/new1.en.md", Op: fsnotify.Rename},
                        },
                        func(t *testing.T) {
-                               assert.Len(t, enSite.Pages, 4, "Rename")
-                               assert.Equal(t, "new_en_1", enSite.Pages[1].Title)
+                               require.Len(t, enSite.Pages, 4, "Rename")
+                               require.Equal(t, "new_en_1", enSite.Pages[1].Title)
                                rendered := readDestination(t, "public/en/new1renamed/index.html")
-                               assert.True(t, strings.Contains(rendered, "new_en_1"), rendered)
+                               require.True(t, strings.Contains(rendered, "new_en_1"), rendered)
                        }},
                {
                        // Change a template
@@ -495,11 +490,11 @@ func TestMultiSitesRebuild(t *testing.T) {
                        },
                        []fsnotify.Event{{Name: "layouts/_default/single.html", Op: fsnotify.Write}},
                        func(t *testing.T) {
-                               assert.Len(t, enSite.Pages, 4)
-                               assert.Len(t, enSite.AllPages, 10)
-                               assert.Len(t, frSite.Pages, 4)
+                               require.Len(t, enSite.Pages, 4)
+                               require.Len(t, enSite.AllPages, 10)
+                               require.Len(t, frSite.Pages, 4)
                                doc1 := readDestination(t, "public/en/sect/doc1-slug/index.html")
-                               assert.True(t, strings.Contains(doc1, "Template Changed"), doc1)
+                               require.True(t, strings.Contains(doc1, "Template Changed"), doc1)
                        },
                },
                {
@@ -512,13 +507,13 @@ func TestMultiSitesRebuild(t *testing.T) {
                        },
                        []fsnotify.Event{{Name: "i18n/fr.yaml", Op: fsnotify.Write}},
                        func(t *testing.T) {
-                               assert.Len(t, enSite.Pages, 4)
-                               assert.Len(t, enSite.AllPages, 10)
-                               assert.Len(t, frSite.Pages, 4)
+                               require.Len(t, enSite.Pages, 4)
+                               require.Len(t, enSite.AllPages, 10)
+                               require.Len(t, frSite.Pages, 4)
                                docEn := readDestination(t, "public/en/sect/doc1-slug/index.html")
-                               assert.True(t, strings.Contains(docEn, "Hello"), "No Hello")
+                               require.True(t, strings.Contains(docEn, "Hello"), "No Hello")
                                docFr := readDestination(t, "public/fr/sect/doc1/index.html")
-                               assert.True(t, strings.Contains(docFr, "Salut"), "No Salut")
+                               require.True(t, strings.Contains(docFr, "Salut"), "No Salut")
 
                                homeEn := enSite.getPage(NodeHome)
                                require.NotNil(t, homeEn)
@@ -536,9 +531,9 @@ func TestMultiSitesRebuild(t *testing.T) {
                                {Name: "layouts/shortcodes/shortcode.html", Op: fsnotify.Write},
                        },
                        func(t *testing.T) {
-                               assert.Len(t, enSite.Pages, 4)
-                               assert.Len(t, enSite.AllPages, 10)
-                               assert.Len(t, frSite.Pages, 4)
+                               require.Len(t, enSite.Pages, 4)
+                               require.Len(t, enSite.AllPages, 10)
+                               require.Len(t, frSite.Pages, 4)
                                assertFileContent(t, "public/fr/sect/doc1/index.html", true, "Single", "Modified Shortcode: Salut")
                                assertFileContent(t, "public/en/sect/doc1-slug/index.html", true, "Single", "Modified Shortcode: Hello")
                        },
index 1d4da93aad1d8249da4f9e2b119722b17ca5960b..026f292cf3c2de288b4511aa2852ef4efa40dfba 100644 (file)
@@ -1529,7 +1529,7 @@ func (s *Site) assembleTaxonomies() {
 // Prepare site for a new full build.
 func (s *Site) resetBuildState() {
 
-       s.PageCollections = newPageCollections()
+       s.PageCollections = newPageCollectionsFromPages(s.rawAllPages)
 
        s.Info.paginationPageCount = 0
        s.draftCount = 0