Skip to content

Commit

Permalink
Move the Build* methods to HugoSites
Browse files Browse the repository at this point in the history
See #2309
  • Loading branch information
bep committed Jul 30, 2016
1 parent d43d42d commit ab56083
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 34 deletions.
38 changes: 4 additions & 34 deletions commands/hugo.go
Expand Up @@ -699,43 +699,13 @@ func getDirList() []string {
}

func buildSites(watching ...bool) (err error) {
fmt.Println("Started building site")
t0 := time.Now()

for _, site := range Hugo {
t1 := time.Now()
if len(watching) > 0 && watching[0] {
site.RunMode.Watching = true
}

if err := site.Build(); err != nil {
return err
}

site.Stats(t1)
}

jww.FEEDBACK.Printf("total in %v ms\n", int(1000*time.Since(t0).Seconds()))

return nil
fmt.Println("Started building sites ...")
w := len(watching) > 0 && watching[0]
return Hugo.Build(w, true)
}

func rebuildSites(events []fsnotify.Event) error {
t0 := time.Now()

for _, site := range Hugo {
t1 := time.Now()

if err := site.ReBuild(events); err != nil {
return err
}

site.Stats(t1)
}

jww.FEEDBACK.Printf("total in %v ms\n", int(1000*time.Since(t0).Seconds()))

return nil
return Hugo.Rebuild(events, true)
}

// NewWatcher creates a new watcher to watch filesystem events.
Expand Down
57 changes: 57 additions & 0 deletions hugolib/hugo_sites.go
Expand Up @@ -13,6 +13,14 @@

package hugolib

import (
"time"

"github.com/fsnotify/fsnotify"

jww "github.com/spf13/jwalterweatherman"
)

// HugoSites represents the sites to build. Each site represents a language.
type HugoSites []*Site

Expand All @@ -23,3 +31,52 @@ func (h HugoSites) Reset() {
h[i] = s.Reset()
}
}

// Build builds all sites.
func (h HugoSites) Build(watching, printStats bool) error {
t0 := time.Now()

for _, site := range h {
t1 := time.Now()

site.RunMode.Watching = watching

if err := site.Build(); err != nil {
return err
}
if printStats {
site.Stats(t1)
}
}

if printStats {
jww.FEEDBACK.Printf("total in %v ms\n", int(1000*time.Since(t0).Seconds()))
}

return nil

}

// Rebuild rebuilds all sites.
func (h HugoSites) Rebuild(events []fsnotify.Event, printStats bool) error {
t0 := time.Now()

for _, site := range h {
t1 := time.Now()

if err := site.ReBuild(events); err != nil {
return err
}

if printStats {
site.Stats(t1)
}
}

if printStats {
jww.FEEDBACK.Printf("total in %v ms\n", int(1000*time.Since(t0).Seconds()))
}

return nil

}

0 comments on commit ab56083

Please sign in to comment.