ref: f5fda804866d971ece34d8862bcdcb8379d3cf92
parent: 0318f7c149f98eb2bcbb44b0ca1c7420379190eb
author: spf13 <[email protected]>
date: Wed Oct 9 15:06:47 EDT 2013
simplified buildSite & better error handling around it
--- a/commands/benchmark.go
+++ b/commands/benchmark.go
@@ -46,6 +46,6 @@
defer pprof.StopCPUProfile()
for i := 0; i < benchmarkTimes; i++ {
- _, _ = buildSite()
+ _ = buildSite()
}
}
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -49,7 +49,7 @@
func Execute() {
AddCommands()
Hugo := HugoCmd.ToCommander()
- utils.CheckErrExit(Hugo.Execute())
+ utils.StopOnErr(Hugo.Execute())
}
func AddCommands() {
@@ -86,10 +86,8 @@
func build() {
utils.CheckErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", Config.GetAbsPath(Config.PublishDir)))
+ utils.StopOnErr(buildSite())
- _, e := buildSite()
- utils.CheckErrExit(e)
-
if BuildWatch {
fmt.Println("Watching for changes in", Config.GetAbsPath(Config.ContentDir))
fmt.Println("Press ctrl+c to stop")
@@ -123,9 +121,9 @@
return a
}
-func buildSite() (site *hugolib.Site, err error) {
+func buildSite() (err error) {
startTime := time.Now()
- site = &hugolib.Site{Config: *Config}
+ site := &hugolib.Site{Config: *Config}
err = site.Build()
if err != nil {
return
@@ -132,7 +130,7 @@
}
site.Stats()
fmt.Printf("in %v ms\n", int(1000*time.Since(startTime).Seconds()))
- return site, nil
+ return nil
}
func NewWatcher(port int) error {
@@ -181,9 +179,9 @@
func watchChange(ev *fsnotify.FileEvent) {
if strings.HasPrefix(ev.Name, Config.GetAbsPath(Config.StaticDir)) {
fmt.Println("Static file changed, syncing\n")
- copyStatic()
+ utils.CheckErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", Config.GetAbsPath(Config.PublishDir)))
} else {
fmt.Println("Change detected, rebuilding site\n")
- buildSite()
+ utils.StopOnErr(buildSite())
}
}
--- a/hugolib/node.go
+++ b/hugolib/node.go
@@ -19,9 +19,9 @@
)
type Node struct {
- RSSlink template.HTML
- Site SiteInfo
-// layout string
+ RSSlink template.HTML
+ Site SiteInfo
+ // layout string
Data map[string]interface{}
Title string
Description string
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -14,7 +14,7 @@
}
}
-func CheckErrExit(err error, s ...string) {
+func StopOnErr(err error, s ...string) {
if err != nil {
CheckErr(err, s...)
os.Exit(-1)