removed fs/walk error check, added title default value heuristics

This commit is contained in:
Serge A. Zaitsev 2015-09-02 19:41:06 +02:00
parent 6b71f501a7
commit 56b0884d64

11
zs.go
View File

@ -111,6 +111,9 @@ func getVars(path string, globals Vars) (Vars, string, error) {
} else { } else {
v["layout"] = "layout.html" v["layout"] = "layout.html"
} }
title := strings.Replace(strings.Replace(path, "_", " ", -1), "-", " ", -1)
v["title"] = strings.ToTitle(title)
v["description"] = ""
v["file"] = path v["file"] = path
v["url"] = path[:len(path)-len(filepath.Ext(path))] + ".html" v["url"] = path[:len(path)-len(filepath.Ext(path))] + ".html"
v["output"] = filepath.Join(PUBDIR, v["url"]) v["output"] = filepath.Join(PUBDIR, v["url"])
@ -129,7 +132,6 @@ func getVars(path string, globals Vars) (Vars, string, error) {
} else { } else {
for key, value := range vars { for key, value := range vars {
v[key] = value v[key] = value
log.Println(key, value)
} }
} }
if strings.HasPrefix(v["url"], "./") { if strings.HasPrefix(v["url"], "./") {
@ -324,14 +326,14 @@ func buildAll(watch bool) {
vars := globals() vars := globals()
for { for {
os.Mkdir(PUBDIR, 0755) os.Mkdir(PUBDIR, 0755)
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error { filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
// ignore hidden files and directories // ignore hidden files and directories
if filepath.Base(path)[0] == '.' || strings.HasPrefix(path, ".") { if filepath.Base(path)[0] == '.' || strings.HasPrefix(path, ".") {
return nil return nil
} }
// inform user about fs walk errors, but continue iteration // inform user about fs walk errors, but continue iteration
if err != nil { if err != nil {
log.Println("ERROR:", err) fmt.Println("error:", err)
return nil return nil
} }
@ -349,9 +351,6 @@ func buildAll(watch bool) {
} }
return nil return nil
}) })
if err != nil {
log.Println("ERROR:", err)
}
if modified { if modified {
// At least one file in this build cycle has been modified // At least one file in this build cycle has been modified
run(vars, "posthook") run(vars, "posthook")