summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSteve Francia <steve.francia@gmail.com>2015-12-22 00:10:01 -0500
committerSteve Francia <steve.francia@gmail.com>2016-01-26 14:25:39 -0500
commitca6ca4f4fc29906e491b5ac6b63fb65125c9c9e4 (patch)
tree804eea0730c7a30a036ffce6748a4f07055466e6 /commands
parentbcc42c0549263681ef9eada21a9fc4eb2d8ff055 (diff)
Separate handling content, data and template changes
Data & Templates reading independently Need to work on page source reading and other source files
Diffstat (limited to 'commands')
-rw-r--r--commands/hugo.go36
1 files changed, 30 insertions, 6 deletions
diff --git a/commands/hugo.go b/commands/hugo.go
index 57f2796b0..ab847c01e 100644
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -44,6 +44,8 @@ import (
"gopkg.in/fsnotify.v1"
)
+var mainSite *hugolib.Site
+
// userError is an error used to signal different error situations in command handling.
type commandError struct {
s string
@@ -528,15 +530,29 @@ func getDirList() []string {
func buildSite(watching ...bool) (err error) {
startTime := time.Now()
- site := &hugolib.Site{}
+ if mainSite == nil {
+ mainSite = new(hugolib.Site)
+ }
if len(watching) > 0 && watching[0] {
- site.RunMode.Watching = true
+ mainSite.RunMode.Watching = true
}
- err = site.Build()
+ err = mainSite.Build()
+ if err != nil {
+ return err
+ }
+ mainSite.Stats()
+ jww.FEEDBACK.Printf("in %v ms\n", int(1000*time.Since(startTime).Seconds()))
+
+ return nil
+}
+
+func rebuildSite(changes map[string]bool) error {
+ startTime := time.Now()
+ err := mainSite.ReBuild(changes)
if err != nil {
return err
}
- site.Stats()
+ mainSite.Stats()
jww.FEEDBACK.Printf("in %v ms\n", int(1000*time.Since(startTime).Seconds()))
return nil
@@ -574,6 +590,7 @@ func NewWatcher(port int) error {
staticChanged := false
dynamicChanged := false
staticFilesChanged := make(map[string]bool)
+ dynamicFilesChanged := make(map[string]bool)
for _, ev := range evs {
ext := filepath.Ext(ev.Name)
@@ -603,7 +620,11 @@ func NewWatcher(port int) error {
dynamicChanged = dynamicChanged || !isstatic
if isstatic {
- staticFilesChanged[ev.Name] = true
+ if staticPath, err := helpers.MakeStaticPathRelative(ev.Name); err == nil {
+ staticFilesChanged[staticPath] = true
+ }
+ } else {
+ dynamicFilesChanged[ev.Name] = true
}
// add new directory to watch list
@@ -680,7 +701,10 @@ func NewWatcher(port int) error {
fmt.Print("\nChange detected, rebuilding site\n")
const layout = "2006-01-02 15:04 -0700"
fmt.Println(time.Now().Format(layout))
- utils.CheckErr(buildSite(true))
+ //TODO here
+
+ // utils.CheckErr(buildSite(true))
+ rebuildSite(dynamicFilesChanged)
if !BuildWatch && !viper.GetBool("DisableLiveReload") {
// Will block forever trying to write to a channel that nobody is reading if livereload isn't initalized