Mercurial > yakumo_izuru > aya
comparison zs.go @ 35:0498cb3afc1d draft
removed fs/walk error check, added title default value heuristics
author | zaitsev.serge |
---|---|
date | Wed, 02 Sep 2015 17:41:06 +0000 |
parents | ed40ca93db1e |
children | a88ccfbd4103 |
comparison
equal
deleted
inserted
replaced
34:ed40ca93db1e | 35:0498cb3afc1d |
---|---|
109 if _, err := os.Stat(filepath.Join(ZSDIR, "layout.amber")); err == nil { | 109 if _, err := os.Stat(filepath.Join(ZSDIR, "layout.amber")); err == nil { |
110 v["layout"] = "layout.amber" | 110 v["layout"] = "layout.amber" |
111 } else { | 111 } else { |
112 v["layout"] = "layout.html" | 112 v["layout"] = "layout.html" |
113 } | 113 } |
114 title := strings.Replace(strings.Replace(path, "_", " ", -1), "-", " ", -1) | |
115 v["title"] = strings.ToTitle(title) | |
116 v["description"] = "" | |
114 v["file"] = path | 117 v["file"] = path |
115 v["url"] = path[:len(path)-len(filepath.Ext(path))] + ".html" | 118 v["url"] = path[:len(path)-len(filepath.Ext(path))] + ".html" |
116 v["output"] = filepath.Join(PUBDIR, v["url"]) | 119 v["output"] = filepath.Join(PUBDIR, v["url"]) |
117 | 120 |
118 delim := "\n---\n" | 121 delim := "\n---\n" |
127 fmt.Println("ERROR: failed to parse header", err) | 130 fmt.Println("ERROR: failed to parse header", err) |
128 return nil, "", err | 131 return nil, "", err |
129 } else { | 132 } else { |
130 for key, value := range vars { | 133 for key, value := range vars { |
131 v[key] = value | 134 v[key] = value |
132 log.Println(key, value) | |
133 } | 135 } |
134 } | 136 } |
135 if strings.HasPrefix(v["url"], "./") { | 137 if strings.HasPrefix(v["url"], "./") { |
136 v["url"] = v["url"][2:] | 138 v["url"] = v["url"][2:] |
137 } | 139 } |
322 modified := false | 324 modified := false |
323 | 325 |
324 vars := globals() | 326 vars := globals() |
325 for { | 327 for { |
326 os.Mkdir(PUBDIR, 0755) | 328 os.Mkdir(PUBDIR, 0755) |
327 err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error { | 329 filepath.Walk(".", func(path string, info os.FileInfo, err error) error { |
328 // ignore hidden files and directories | 330 // ignore hidden files and directories |
329 if filepath.Base(path)[0] == '.' || strings.HasPrefix(path, ".") { | 331 if filepath.Base(path)[0] == '.' || strings.HasPrefix(path, ".") { |
330 return nil | 332 return nil |
331 } | 333 } |
332 // inform user about fs walk errors, but continue iteration | 334 // inform user about fs walk errors, but continue iteration |
333 if err != nil { | 335 if err != nil { |
334 log.Println("ERROR:", err) | 336 fmt.Println("error:", err) |
335 return nil | 337 return nil |
336 } | 338 } |
337 | 339 |
338 if info.IsDir() { | 340 if info.IsDir() { |
339 os.Mkdir(filepath.Join(PUBDIR, path), 0755) | 341 os.Mkdir(filepath.Join(PUBDIR, path), 0755) |
347 log.Println("build:", path) | 349 log.Println("build:", path) |
348 return build(path, nil, vars) | 350 return build(path, nil, vars) |
349 } | 351 } |
350 return nil | 352 return nil |
351 }) | 353 }) |
352 if err != nil { | |
353 log.Println("ERROR:", err) | |
354 } | |
355 if modified { | 354 if modified { |
356 // At least one file in this build cycle has been modified | 355 // At least one file in this build cycle has been modified |
357 run(vars, "posthook") | 356 run(vars, "posthook") |
358 modified = false | 357 modified = false |
359 } | 358 } |