mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-25 22:00:58 +02:00
Better error handling when rendering error found when in watch mode
In watch mode it should continue to watch for changes, in any other mode it should exit with a -1 error code so can check for success when scripting
This commit is contained in:
@@ -84,9 +84,13 @@ func InitializeConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
func build() {
|
||||
func build(watches ...bool) {
|
||||
utils.CheckErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", Config.GetAbsPath(Config.PublishDir)))
|
||||
utils.StopOnErr(buildSite())
|
||||
watch := false
|
||||
if len(watches) > 0 && watches[0] {
|
||||
watch = true
|
||||
}
|
||||
utils.StopOnErr(buildSite(BuildWatch || watch))
|
||||
|
||||
if BuildWatch {
|
||||
fmt.Println("Watching for changes in", Config.GetAbsPath(Config.ContentDir))
|
||||
@@ -121,9 +125,12 @@ func getDirList() []string {
|
||||
return a
|
||||
}
|
||||
|
||||
func buildSite() (err error) {
|
||||
func buildSite(watching ...bool) (err error) {
|
||||
startTime := time.Now()
|
||||
site := &hugolib.Site{Config: *Config}
|
||||
if len(watching) > 0 && watching[0] {
|
||||
site.RunMode.Watching = true
|
||||
}
|
||||
err = site.Build()
|
||||
if err != nil {
|
||||
return
|
||||
@@ -185,7 +192,7 @@ func watchChange(ev *fsnotify.FileEvent) {
|
||||
// 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())
|
||||
utils.StopOnErr(buildSite(true))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user