create: Simplify archetype logic

See ##2750
This commit is contained in:
Bjørn Erik Pedersen 2016-11-29 20:32:26 +01:00
parent 96018ab98c
commit b2eadd93d3

View file

@ -119,28 +119,19 @@ func createMetadata(archetype parser.Page, name string) (map[string]interface{},
}
case "title":
// Use the archetype title as is
metadata[lk] = cast.ToString(v)
metadata[lk] = v
}
}
caseimatch := func(m map[string]interface{}, key string) bool {
for k := range m {
if strings.ToLower(k) == strings.ToLower(key) {
return true
}
}
return false
}
if metadata == nil {
metadata = make(map[string]interface{})
}
if !caseimatch(metadata, "date") {
if date.IsZero() {
date = time.Now()
}
if !caseimatch(metadata, "title") {
if _, ok := metadata["title"]; !ok {
metadata["title"] = helpers.MakeTitle(helpers.Filename(name))
}