mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-13 20:24:00 +02:00
Add support for YAML array data files
* Unmarshaled YAML arrays indistinguishable from JSON arrays. * Fixes #3890
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
bb549a0d57
commit
1fa2417777
@@ -216,6 +216,23 @@ func HandleYAMLMetaData(datum []byte) (map[string]interface{}, error) {
|
||||
return m, err
|
||||
}
|
||||
|
||||
// HandleYAMLData unmarshals YAML-encoded datum and returns a Go interface
|
||||
// representing the encoded data structure.
|
||||
func HandleYAMLData(datum []byte) (interface{}, error) {
|
||||
var m interface{}
|
||||
err := yaml.Unmarshal(datum, &m)
|
||||
|
||||
// To support boolean keys, the `yaml` package unmarshals maps to
|
||||
// map[interface{}]interface{}. Here we recurse through the result
|
||||
// and change all maps to map[string]interface{} like we would've
|
||||
// gotten from `json`.
|
||||
if err == nil {
|
||||
m = stringifyYAMLMapKeys(m)
|
||||
}
|
||||
|
||||
return m, err
|
||||
}
|
||||
|
||||
// stringifyKeysMapValue recurses into in and changes all instances of
|
||||
// map[interface{}]interface{} to map[string]interface{}. This is useful to
|
||||
// work around the impedence mismatch between JSON and YAML unmarshaling that's
|
||||
|
Reference in New Issue
Block a user