|
|
|
@ -10,6 +10,7 @@ import ( |
|
|
|
|
"path/filepath" |
|
|
|
|
"os" |
|
|
|
|
"flag" |
|
|
|
|
"time" |
|
|
|
|
"text/template" |
|
|
|
|
"zedshaw.games/ssgod/config" |
|
|
|
|
"github.com/yuin/goldmark" |
|
|
|
@ -160,21 +161,37 @@ func RenderPages() { |
|
|
|
|
if err != nil { log.Fatalf("can't walk content") } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func WatchMatches(name string) bool { |
|
|
|
|
return filepath.Ext(name) == ".html" || filepath.Ext(name) == ".md" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func WatchDir() { |
|
|
|
|
watcher, err := fsnotify.NewWatcher() |
|
|
|
|
if err != nil { log.Fatal(err) } |
|
|
|
|
|
|
|
|
|
defer watcher.Close() |
|
|
|
|
|
|
|
|
|
wait_time, err := time.ParseDuration(config.Settings.WatchDelay) |
|
|
|
|
if err != nil { log.Fatal(err) } |
|
|
|
|
|
|
|
|
|
doit := time.NewTimer(wait_time) |
|
|
|
|
doit.Stop() |
|
|
|
|
|
|
|
|
|
log.Println("WATCHING directory", config.Settings.Views) |
|
|
|
|
|
|
|
|
|
go func() { |
|
|
|
|
for { |
|
|
|
|
select { |
|
|
|
|
case event, ok := <-watcher.Events: |
|
|
|
|
if !ok { return } |
|
|
|
|
log.Println("event: ", event) |
|
|
|
|
if event.Has(fsnotify.Write) { |
|
|
|
|
|
|
|
|
|
if WatchMatches(event.Name) { |
|
|
|
|
log.Println("modified file: ", event.Name) |
|
|
|
|
RenderPages() |
|
|
|
|
doit.Reset(wait_time) |
|
|
|
|
} |
|
|
|
|
case <-doit.C: |
|
|
|
|
RenderPages() |
|
|
|
|
case err, ok := <-watcher.Errors: |
|
|
|
|
if !ok { return } |
|
|
|
|
log.Println("error: ", err) |
|
|
|
|