Fix #36 and reduce code repetitions
parent
b15b9b8b08
commit
f66f5af562
|
@ -42,28 +42,28 @@ func rawToPretty(config interface{}, parent *frontmatter) interface{} {
|
||||||
arrays := []*frontmatter{}
|
arrays := []*frontmatter{}
|
||||||
fields := []*frontmatter{}
|
fields := []*frontmatter{}
|
||||||
|
|
||||||
if parent.Type == "array" {
|
cnf := map[string]interface{}{}
|
||||||
for index, element := range config.([]interface{}) {
|
|
||||||
if utils.IsMap(element) {
|
if reflect.TypeOf(config) == reflect.TypeOf(map[interface{}]interface{}{}) {
|
||||||
objects = append(objects, handleObjects(element, parent, string(index)))
|
for key, value := range config.(map[interface{}]interface{}) {
|
||||||
} else if utils.IsSlice(element) {
|
cnf[key.(string)] = value
|
||||||
arrays = append(arrays, handleArrays(element, parent, string(index)))
|
|
||||||
} else {
|
|
||||||
fields = append(fields, handleFlatValues(element, parent, string(index)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if parent.Type == "object" {
|
} else if reflect.TypeOf(config) == reflect.TypeOf([]interface{}{}) {
|
||||||
for name, element := range config.(map[string]interface{}) {
|
for key, value := range config.([]interface{}) {
|
||||||
if utils.IsMap(element) {
|
cnf[string(key)] = value
|
||||||
objects = append(objects, handleObjects(element, parent, name))
|
|
||||||
} else if utils.IsSlice(element) {
|
|
||||||
arrays = append(arrays, handleArrays(element, parent, name))
|
|
||||||
} else {
|
|
||||||
fields = append(fields, handleFlatValues(element, parent, name))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Panic("Parent type not allowed.")
|
cnf = config.(map[string]interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, element := range cnf {
|
||||||
|
if utils.IsMap(element) {
|
||||||
|
objects = append(objects, handleObjects(element, parent, name))
|
||||||
|
} else if utils.IsSlice(element) {
|
||||||
|
arrays = append(arrays, handleArrays(element, parent, name))
|
||||||
|
} else {
|
||||||
|
fields = append(fields, handleFlatValues(element, parent, name))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(sortByTitle(objects))
|
sort.Sort(sortByTitle(objects))
|
||||||
|
|
Loading…
Reference in New Issue