"path/filepath"
"runtime"
"strings"
- "sync"
"time"
src "github.com/gohugoio/hugo/source"
}
c.Logger.FEEDBACK.Println("Watching for changes in", c.PathSpec().AbsPathify(c.Cfg.GetString("contentDir")))
c.Logger.FEEDBACK.Println("Press Ctrl+C to stop")
- utils.CheckErr(c.Logger, c.newWatcher(false, watchDirs...))
+ utils.CheckErr(c.Logger, c.newWatcher(watchDirs...))
}
return nil
}
// newWatcher creates a new watcher to watch filesystem events.
-// if serve is set it will also start one or more HTTP servers to serve those
-// files.
-func (c *commandeer) newWatcher(serve bool, dirList ...string) error {
+func (c *commandeer) newWatcher(dirList ...string) error {
if runtime.GOOS == "darwin" {
tweakLimit()
}
}
watcher, err := watcher.New(1 * time.Second)
- var wg sync.WaitGroup
if err != nil {
return err
defer watcher.Close()
- wg.Add(1)
-
for _, d := range dirList {
if d != "" {
_ = watcher.Add(d)
}
}()
- if serve {
- go c.serve()
- }
-
- wg.Wait()
return nil
}
"net/http"
"net/url"
"os"
+ "os/signal"
"path/filepath"
"runtime"
"strconv"
"strings"
+ "syscall"
"time"
"github.com/gohugoio/hugo/livereload"
rootWatchDirs := strings.Join(helpers.UniqueStrings(helpers.ExtractRootPaths(relWatchDirs)), ",")
jww.FEEDBACK.Printf("Watching for changes in %s%s{%s}\n", baseWatchDir, helpers.FilePathSeparator, rootWatchDirs)
- err = c.newWatcher(true, watchDirs...)
+ err = c.newWatcher(watchDirs...)
if err != nil {
return err
}
+
}
- return nil
+ return c.serve()
+
}
type fileServer struct {
return mu, u.String(), endpoint, nil
}
-func (c *commandeer) serve() {
+func (c *commandeer) serve() error {
isMultiHost := Hugo.IsMultihost()
livereload.Initialize()
}
+ var sigs = make(chan os.Signal)
+ signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
+
for i, _ := range baseURLs {
mu, serverURL, endpoint, err := srv.createEndpoint(i)
}
jww.FEEDBACK.Println("Press Ctrl+C to stop")
+
+ <-sigs
+
+ return nil
}
// fixURL massages the baseURL into a form needed for serving