mirror of
https://git.mills.io/prologic/zs
synced 2024-11-25 23:06:11 +03:00
more obvious rules of variable overriding
This commit is contained in:
parent
76175692a6
commit
e21b87dfb6
23
zs.go
23
zs.go
@ -104,21 +104,23 @@ func getVars(path string, globals Vars) (Vars, string, error) {
|
|||||||
title := strings.Replace(strings.Replace(path, "_", " ", -1), "-", " ", -1)
|
title := strings.Replace(strings.Replace(path, "_", " ", -1), "-", " ", -1)
|
||||||
v["title"] = strings.ToTitle(title)
|
v["title"] = strings.ToTitle(title)
|
||||||
v["description"] = ""
|
v["description"] = ""
|
||||||
|
v["file"] = path
|
||||||
|
v["url"] = path[:len(path)-len(filepath.Ext(path))] + ".html"
|
||||||
|
v["output"] = filepath.Join(PUBDIR, v["url"])
|
||||||
|
|
||||||
// Copy globals (will override title and description for markdown layouts
|
// Override default values with globals
|
||||||
for name, value := range globals {
|
for name, value := range globals {
|
||||||
v[name] = value
|
v[name] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add default values extracted from file name/path
|
// Add layout if none is specified
|
||||||
if _, err := os.Stat(filepath.Join(ZSDIR, "layout.amber")); err == nil {
|
if _, ok := v["layout"]; !ok {
|
||||||
v["layout"] = "layout.amber"
|
if _, err := os.Stat(filepath.Join(ZSDIR, "layout.amber")); err == nil {
|
||||||
} else {
|
v["layout"] = "layout.amber"
|
||||||
v["layout"] = "layout.html"
|
} else {
|
||||||
|
v["layout"] = "layout.html"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
v["file"] = path
|
|
||||||
v["url"] = path[:len(path)-len(filepath.Ext(path))] + ".html"
|
|
||||||
v["output"] = filepath.Join(PUBDIR, v["url"])
|
|
||||||
|
|
||||||
delim := "\n---\n"
|
delim := "\n---\n"
|
||||||
if sep := strings.Index(s, delim); sep == -1 {
|
if sep := strings.Index(s, delim); sep == -1 {
|
||||||
@ -132,6 +134,7 @@ func getVars(path string, globals Vars) (Vars, string, error) {
|
|||||||
fmt.Println("ERROR: failed to parse header", err)
|
fmt.Println("ERROR: failed to parse header", err)
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
} else {
|
} else {
|
||||||
|
// Override default values + globals with the ones defines in the file
|
||||||
for key, value := range vars {
|
for key, value := range vars {
|
||||||
v[key] = value
|
v[key] = value
|
||||||
}
|
}
|
||||||
@ -398,7 +401,7 @@ func main() {
|
|||||||
fmt.Println("var: filename expected")
|
fmt.Println("var: filename expected")
|
||||||
} else {
|
} else {
|
||||||
s := ""
|
s := ""
|
||||||
if vars, _, err := getVars(args[0], globals()); err != nil {
|
if vars, _, err := getVars(args[0], Vars{}); err != nil {
|
||||||
fmt.Println("var: " + err.Error())
|
fmt.Println("var: " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
|
Loading…
Reference in New Issue
Block a user