aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Mathes <adam@trenchant.org>2018-02-18 09:24:10 -0800
committerAdam Mathes <adam@trenchant.org>2018-02-18 09:24:10 -0800
commit9989337b3f760267f40bfe67a501eed3de012417 (patch)
tree86b52d4606d1bf8a4c431df329fc59aaad48c1e3
parent1dc63a221695eeacf226e301ec4306e8573e1b79 (diff)
downloadsnkt-9989337b3f760267f40bfe67a501eed3de012417.tar.gz
snkt-9989337b3f760267f40bfe67a501eed3de012417.tar.bz2
snkt-9989337b3f760267f40bfe67a501eed3de012417.zip
watch now also rebuilds on template file changes
-rw-r--r--main.go14
-rw-r--r--render/render.go6
2 files changed, 16 insertions, 4 deletions
diff --git a/main.go b/main.go
index ba9595f..c938916 100644
--- a/main.go
+++ b/main.go
@@ -47,7 +47,6 @@ func main() {
if verbose {
config.Config.Verbose = true
}
- render.Init()
if build {
buildSite()
@@ -61,7 +60,6 @@ func main() {
}
if watch {
- fmt.Printf("watching %s\n", config.Config.TxtDir)
watchSite()
}
@@ -73,11 +71,14 @@ func main() {
}
func buildSite() {
+ vlog.Printf("reading templates...\n")
+ render.Init()
var s site.Site
vlog.Printf("reading posts...\n")
s.Read()
vlog.Printf("writing posts and archives...\n")
s.Write()
+ vlog.Printf("done...\n")
}
func watchSite() {
@@ -93,8 +94,9 @@ func watchSite() {
select {
case event := <-watcher.Events:
if event.Op&fsnotify.Write == fsnotify.Write {
- fmt.Printf("rebuilding\n")
+ fmt.Printf("rebuilding... ")
buildSite()
+ fmt.Printf("done\n")
}
case err := <-watcher.Errors:
vlog.Printf("error: %v", err)
@@ -102,9 +104,15 @@ func watchSite() {
}
}()
+ fmt.Printf("watching %s\n", config.Config.TxtDir)
err = watcher.Add(config.Config.TxtDir)
if err != nil {
panic(err)
}
+ fmt.Printf("watching %s\n", config.Config.TmplDir)
+ err = watcher.Add(config.Config.TmplDir)
+ if err != nil {
+ panic(err)
+ }
<-done
}
diff --git a/render/render.go b/render/render.go
index ba8e52b..bf53208 100644
--- a/render/render.go
+++ b/render/render.go
@@ -77,7 +77,11 @@ func Init() {
tx := template.New("t").Funcs(tmplFuncs)
templates[tf], err = tx.ParseFiles(base, t)
if err != nil {
- panic(err)
+ // temporary files can confuse this, especially when
+ // running the file system watcher so we silently
+ // ignore any templates that disappeared since we started
+ // since this is usually not a real error condition
+ delete(templates, tf)
}
}
rel_href = regexp.MustCompile(`href="/(.+)"`)