node to page: Get Rebuild up to speed

Updates #2297
This commit is contained in:
Bjørn Erik Pedersen 2016-11-09 09:58:18 +01:00
parent 80e453f114
commit 503fb29953
3 changed files with 55 additions and 54 deletions

View 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,14 +299,22 @@ func (h *HugoSites) Rebuild(config BuildCfg, events ...fsnotify.Event) error {
}
}
}
// 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 {
return err
@ -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)
}

View 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")
},

View 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