mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-19 03:52:37 +00:00
parent
80e453f114
commit
503fb29953
3 changed files with 55 additions and 54 deletions
|
@ -194,7 +194,7 @@ func (h *HugoSites) Build(config BuildCfg) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
h.setupTranslationsForRegularPages()
|
h.setupTranslations()
|
||||||
|
|
||||||
if len(h.Sites) > 1 {
|
if len(h.Sites) > 1 {
|
||||||
// Initialize the rest
|
// Initialize the rest
|
||||||
|
@ -289,7 +289,7 @@ func (h *HugoSites) Rebuild(config BuildCfg, events ...fsnotify.Event) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign pages to sites per translation.
|
// Assign pages to sites per translation.
|
||||||
h.setupTranslationsForRegularPages()
|
h.setupTranslations()
|
||||||
|
|
||||||
if changed.source {
|
if changed.source {
|
||||||
h.assembleGitInfo()
|
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 {
|
// TODO(bep) np consolidate the build lifecycle methods
|
||||||
return err
|
// 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 {
|
if err := h.preRender(config, changed); err != nil {
|
||||||
|
@ -557,13 +565,11 @@ func (s *Site) newTaxonomyTermsPage(plural string) *Page {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HugoSites) setupTranslationsForRegularPages() {
|
func (h *HugoSites) setupTranslations() {
|
||||||
|
|
||||||
master := h.Sites[0]
|
master := h.Sites[0]
|
||||||
|
|
||||||
regularPages := master.rawAllPages // master.findRawAllPagesByNodeType(NodePage)
|
for _, p := range master.rawAllPages {
|
||||||
|
|
||||||
for _, p := range regularPages {
|
|
||||||
if p.Lang() == "" {
|
if p.Lang() == "" {
|
||||||
panic("Page language missing: " + p.Title)
|
panic("Page language missing: " + p.Title)
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,8 +51,7 @@ func testCommonResetState() {
|
||||||
func TestMultiSitesMainLangInRoot(t *testing.T) {
|
func TestMultiSitesMainLangInRoot(t *testing.T) {
|
||||||
//jww.SetStdoutThreshold(jww.LevelDebug)
|
//jww.SetStdoutThreshold(jww.LevelDebug)
|
||||||
|
|
||||||
// TODO(bep) np true false
|
for _, b := range []bool{true, false} {
|
||||||
for _, b := range []bool{true} {
|
|
||||||
doTestMultiSitesMainLangInRoot(t, b)
|
doTestMultiSitesMainLangInRoot(t, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -366,8 +365,6 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiSitesRebuild(t *testing.T) {
|
func TestMultiSitesRebuild(t *testing.T) {
|
||||||
// TODO(bep) np TestMultiSitesRebuild
|
|
||||||
t.Skip()
|
|
||||||
|
|
||||||
defer leaktest.Check(t)()
|
defer leaktest.Check(t)()
|
||||||
testCommonResetState()
|
testCommonResetState()
|
||||||
|
@ -390,14 +387,12 @@ func TestMultiSitesRebuild(t *testing.T) {
|
||||||
enSite := sites.Sites[0]
|
enSite := sites.Sites[0]
|
||||||
frSite := sites.Sites[1]
|
frSite := sites.Sites[1]
|
||||||
|
|
||||||
assert.Len(t, enSite.Pages, 3)
|
require.Len(t, enSite.Pages, 3)
|
||||||
assert.Len(t, frSite.Pages, 3)
|
require.Len(t, frSite.Pages, 3)
|
||||||
|
|
||||||
// Verify translations
|
// Verify translations
|
||||||
docEn := readDestination(t, "public/en/sect/doc1-slug/index.html")
|
assertFileContent(t, "public/en/sect/doc1-slug/index.html", true, "Hello")
|
||||||
assert.True(t, strings.Contains(docEn, "Hello"), "No Hello")
|
assertFileContent(t, "public/fr/sect/doc1/index.html", true, "Bonjour")
|
||||||
docFr := readDestination(t, "public/fr/sect/doc1/index.html")
|
|
||||||
assert.True(t, strings.Contains(docFr, "Bonjour"), "No Bonjour")
|
|
||||||
|
|
||||||
// check single page content
|
// check single page content
|
||||||
assertFileContent(t, "public/fr/sect/doc1/index.html", true, "Single", "Shortcode: Bonjour")
|
assertFileContent(t, "public/fr/sect/doc1/index.html", true, "Single", "Shortcode: Bonjour")
|
||||||
|
@ -419,15 +414,15 @@ func TestMultiSitesRebuild(t *testing.T) {
|
||||||
nil,
|
nil,
|
||||||
[]fsnotify.Event{{Name: "content/sect/doc2.en.md", Op: fsnotify.Remove}},
|
[]fsnotify.Event{{Name: "content/sect/doc2.en.md", Op: fsnotify.Remove}},
|
||||||
func(t *testing.T) {
|
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
|
// Check build stats
|
||||||
assert.Equal(t, 1, enSite.draftCount, "Draft")
|
require.Equal(t, 1, enSite.draftCount, "Draft")
|
||||||
assert.Equal(t, 1, enSite.futureCount, "Future")
|
require.Equal(t, 1, enSite.futureCount, "Future")
|
||||||
assert.Equal(t, 1, enSite.expiredCount, "Expired")
|
require.Equal(t, 1, enSite.expiredCount, "Expired")
|
||||||
assert.Equal(t, 0, frSite.draftCount, "Draft")
|
require.Equal(t, 0, frSite.draftCount, "Draft")
|
||||||
assert.Equal(t, 1, frSite.futureCount, "Future")
|
require.Equal(t, 1, frSite.futureCount, "Future")
|
||||||
assert.Equal(t, 1, frSite.expiredCount, "Expired")
|
require.Equal(t, 1, frSite.expiredCount, "Expired")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -442,15 +437,15 @@ func TestMultiSitesRebuild(t *testing.T) {
|
||||||
{Name: "content/new1.fr.md", Op: fsnotify.Create},
|
{Name: "content/new1.fr.md", Op: fsnotify.Create},
|
||||||
},
|
},
|
||||||
func(t *testing.T) {
|
func(t *testing.T) {
|
||||||
assert.Len(t, enSite.Pages, 4)
|
require.Len(t, enSite.Pages, 4)
|
||||||
assert.Len(t, enSite.AllPages, 10)
|
require.Len(t, enSite.AllPages, 10)
|
||||||
assert.Len(t, frSite.Pages, 4)
|
require.Len(t, frSite.Pages, 4)
|
||||||
assert.Equal(t, "new_fr_1", frSite.Pages[3].Title)
|
require.Equal(t, "new_fr_1", frSite.Pages[3].Title)
|
||||||
assert.Equal(t, "new_en_2", enSite.Pages[0].Title)
|
require.Equal(t, "new_en_2", enSite.Pages[0].Title)
|
||||||
assert.Equal(t, "new_en_1", enSite.Pages[1].Title)
|
require.Equal(t, "new_en_1", enSite.Pages[1].Title)
|
||||||
|
|
||||||
rendered := readDestination(t, "public/en/new1/index.html")
|
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}},
|
[]fsnotify.Event{{Name: "content/sect/doc1.en.md", Op: fsnotify.Write}},
|
||||||
func(t *testing.T) {
|
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")
|
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},
|
{Name: "content/new1.en.md", Op: fsnotify.Rename},
|
||||||
},
|
},
|
||||||
func(t *testing.T) {
|
func(t *testing.T) {
|
||||||
assert.Len(t, enSite.Pages, 4, "Rename")
|
require.Len(t, enSite.Pages, 4, "Rename")
|
||||||
assert.Equal(t, "new_en_1", enSite.Pages[1].Title)
|
require.Equal(t, "new_en_1", enSite.Pages[1].Title)
|
||||||
rendered := readDestination(t, "public/en/new1renamed/index.html")
|
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
|
// Change a template
|
||||||
|
@ -495,11 +490,11 @@ func TestMultiSitesRebuild(t *testing.T) {
|
||||||
},
|
},
|
||||||
[]fsnotify.Event{{Name: "layouts/_default/single.html", Op: fsnotify.Write}},
|
[]fsnotify.Event{{Name: "layouts/_default/single.html", Op: fsnotify.Write}},
|
||||||
func(t *testing.T) {
|
func(t *testing.T) {
|
||||||
assert.Len(t, enSite.Pages, 4)
|
require.Len(t, enSite.Pages, 4)
|
||||||
assert.Len(t, enSite.AllPages, 10)
|
require.Len(t, enSite.AllPages, 10)
|
||||||
assert.Len(t, frSite.Pages, 4)
|
require.Len(t, frSite.Pages, 4)
|
||||||
doc1 := readDestination(t, "public/en/sect/doc1-slug/index.html")
|
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}},
|
[]fsnotify.Event{{Name: "i18n/fr.yaml", Op: fsnotify.Write}},
|
||||||
func(t *testing.T) {
|
func(t *testing.T) {
|
||||||
assert.Len(t, enSite.Pages, 4)
|
require.Len(t, enSite.Pages, 4)
|
||||||
assert.Len(t, enSite.AllPages, 10)
|
require.Len(t, enSite.AllPages, 10)
|
||||||
assert.Len(t, frSite.Pages, 4)
|
require.Len(t, frSite.Pages, 4)
|
||||||
docEn := readDestination(t, "public/en/sect/doc1-slug/index.html")
|
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")
|
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)
|
homeEn := enSite.getPage(NodeHome)
|
||||||
require.NotNil(t, homeEn)
|
require.NotNil(t, homeEn)
|
||||||
|
@ -536,9 +531,9 @@ func TestMultiSitesRebuild(t *testing.T) {
|
||||||
{Name: "layouts/shortcodes/shortcode.html", Op: fsnotify.Write},
|
{Name: "layouts/shortcodes/shortcode.html", Op: fsnotify.Write},
|
||||||
},
|
},
|
||||||
func(t *testing.T) {
|
func(t *testing.T) {
|
||||||
assert.Len(t, enSite.Pages, 4)
|
require.Len(t, enSite.Pages, 4)
|
||||||
assert.Len(t, enSite.AllPages, 10)
|
require.Len(t, enSite.AllPages, 10)
|
||||||
assert.Len(t, frSite.Pages, 4)
|
require.Len(t, frSite.Pages, 4)
|
||||||
assertFileContent(t, "public/fr/sect/doc1/index.html", true, "Single", "Modified Shortcode: Salut")
|
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")
|
assertFileContent(t, "public/en/sect/doc1-slug/index.html", true, "Single", "Modified Shortcode: Hello")
|
||||||
},
|
},
|
||||||
|
|
|
@ -1529,7 +1529,7 @@ func (s *Site) assembleTaxonomies() {
|
||||||
// Prepare site for a new full build.
|
// Prepare site for a new full build.
|
||||||
func (s *Site) resetBuildState() {
|
func (s *Site) resetBuildState() {
|
||||||
|
|
||||||
s.PageCollections = newPageCollections()
|
s.PageCollections = newPageCollectionsFromPages(s.rawAllPages)
|
||||||
|
|
||||||
s.Info.paginationPageCount = 0
|
s.Info.paginationPageCount = 0
|
||||||
s.draftCount = 0
|
s.draftCount = 0
|
||||||
|
|
Loading…
Reference in a new issue