mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
e56ecab157
commit
6b552db75f
3 changed files with 45 additions and 5 deletions
|
@ -242,7 +242,7 @@ func (h *HugoSites) Rebuild(config BuildCfg, events ...fsnotify.Event) error {
|
||||||
s.resetBuildState()
|
s.resetBuildState()
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceChanged, err := firstSite.ReBuild(events)
|
sourceChanged, err := firstSite.reBuild(events)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package hugolib
|
package hugolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -141,6 +142,9 @@ func TestMultiSitesBuild(t *testing.T) {
|
||||||
assert.False(t, strings.Contains(string(doc1en.Content), "«"), string(doc1en.Content))
|
assert.False(t, strings.Contains(string(doc1en.Content), "«"), string(doc1en.Content))
|
||||||
assert.True(t, strings.Contains(string(doc1en.Content), "“"), string(doc1en.Content))
|
assert.True(t, strings.Contains(string(doc1en.Content), "“"), string(doc1en.Content))
|
||||||
|
|
||||||
|
// Check that the drafts etc. are not built/processed/rendered.
|
||||||
|
assertShouldNotBuild(t, sites)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiSitesRebuild(t *testing.T) {
|
func TestMultiSitesRebuild(t *testing.T) {
|
||||||
|
@ -303,6 +307,30 @@ func TestMultiSitesRebuild(t *testing.T) {
|
||||||
|
|
||||||
this.assertFunc(t)
|
this.assertFunc(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that the drafts etc. are not built/processed/rendered.
|
||||||
|
assertShouldNotBuild(t, sites)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertShouldNotBuild(t *testing.T, sites *HugoSites) {
|
||||||
|
s := sites.Sites[0]
|
||||||
|
|
||||||
|
for _, p := range s.rawAllPages {
|
||||||
|
// No HTML when not processed
|
||||||
|
require.Equal(t, p.shouldBuild(), bytes.Contains(p.rawContent, []byte("</")), p.BaseFileName()+": "+string(p.rawContent))
|
||||||
|
require.Equal(t, p.shouldBuild(), p.Content != "", p.BaseFileName())
|
||||||
|
|
||||||
|
require.Equal(t, p.shouldBuild(), p.Content != "", p.BaseFileName())
|
||||||
|
|
||||||
|
filename := filepath.Join("public", p.TargetPath())
|
||||||
|
if strings.HasSuffix(filename, ".html") {
|
||||||
|
// TODO(bep) the end result is correct, but it is weird that we cannot use targetPath directly here.
|
||||||
|
filename = strings.Replace(filename, ".html", "/index.html", 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
require.Equal(t, p.shouldBuild(), destinationExists(filename), filename)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddNewLanguage(t *testing.T) {
|
func TestAddNewLanguage(t *testing.T) {
|
||||||
|
@ -579,6 +607,14 @@ func readDestination(t *testing.T, filename string) string {
|
||||||
return readFileFromFs(t, hugofs.Destination(), filename)
|
return readFileFromFs(t, hugofs.Destination(), filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func destinationExists(filename string) bool {
|
||||||
|
b, err := helpers.Exists(filename, hugofs.Destination())
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
func readSource(t *testing.T, filename string) string {
|
func readSource(t *testing.T, filename string) string {
|
||||||
return readFileFromFs(t, hugofs.Source(), filename)
|
return readFileFromFs(t, hugofs.Source(), filename)
|
||||||
}
|
}
|
||||||
|
|
|
@ -437,9 +437,9 @@ func (s *Site) timerStep(step string) {
|
||||||
s.timer.Step(step)
|
s.timer.Step(step)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReBuild partially rebuilds a site given the filesystem events.
|
// reBuild partially rebuilds a site given the filesystem events.
|
||||||
// It returns whetever the content source was changed.
|
// It returns whetever the content source was changed.
|
||||||
func (s *Site) ReBuild(events []fsnotify.Event) (bool, error) {
|
func (s *Site) reBuild(events []fsnotify.Event) (bool, error) {
|
||||||
|
|
||||||
jww.DEBUG.Printf("Rebuild for events %q", events)
|
jww.DEBUG.Printf("Rebuild for events %q", events)
|
||||||
|
|
||||||
|
@ -555,7 +555,9 @@ func (s *Site) ReBuild(events []fsnotify.Event) (bool, error) {
|
||||||
// Do not need to read the files again, but they need conversion
|
// Do not need to read the files again, but they need conversion
|
||||||
// for shortocde re-rendering.
|
// for shortocde re-rendering.
|
||||||
for _, p := range s.rawAllPages {
|
for _, p := range s.rawAllPages {
|
||||||
pageChan <- p
|
if p.shouldBuild() {
|
||||||
|
pageChan <- p
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1016,7 +1018,9 @@ func (s *Site) convertSource() chan error {
|
||||||
go converterCollator(s, results, errs)
|
go converterCollator(s, results, errs)
|
||||||
|
|
||||||
for _, p := range s.rawAllPages {
|
for _, p := range s.rawAllPages {
|
||||||
pageChan <- p
|
if p.shouldBuild() {
|
||||||
|
pageChan <- p
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range s.Files {
|
for _, f := range s.Files {
|
||||||
|
|
Loading…
Reference in a new issue