From cd71eb738947696cae71cb39027996d108221add Mon Sep 17 00:00:00 2001 From: spf13 Date: Thu, 24 Oct 2013 16:45:24 -0700 Subject: [PATCH] Watching doesn't built site 2x on write (ignores rename events). Also ignores temporary files written by editors. --- commands/hugo.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/commands/hugo.go b/commands/hugo.go index 819b5c207..bdd1171c5 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -181,7 +181,12 @@ func watchChange(ev *fsnotify.FileEvent) { fmt.Println("Static file changed, syncing\n") utils.CheckErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", Config.GetAbsPath(Config.PublishDir))) } else { - fmt.Println("Change detected, rebuilding site\n") - utils.StopOnErr(buildSite()) + if !ev.IsRename() { // Rename is always accompanied by a create or modify + // Ignoring temp files created by editors (vim) + if !strings.HasSuffix(ev.Name, "~") && !strings.HasSuffix(ev.Name, ".swp") { + fmt.Println("Change detected, rebuilding site\n") + utils.StopOnErr(buildSite()) + } + } } }