mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
Allow cascade _target to work with non toml fm
The TOML lib unmarshals slices of string maps to []map[string]interface{} whereas YAML and JSON decode to []interface{} The existing tests only check for TOML working correctly, and _target with cascade did not work at all for frontmatter defined in other formats. Add a function to normalize those slices Fixes #7874
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
fdfa4a5fe6
commit
3400aff258
@@ -14,6 +14,7 @@
|
||||
package maps
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/gobwas/glob"
|
||||
@@ -64,6 +65,23 @@ func ToStringMap(in interface{}) map[string]interface{} {
|
||||
return m
|
||||
}
|
||||
|
||||
func ToSliceStringMap(in interface{}) ([]map[string]interface{}, error) {
|
||||
switch v := in.(type) {
|
||||
case []map[string]interface{}:
|
||||
return v, nil
|
||||
case []interface{}:
|
||||
var s []map[string]interface{}
|
||||
for _, entry := range v {
|
||||
if vv, ok := entry.(map[string]interface{}); ok {
|
||||
s = append(s, vv)
|
||||
}
|
||||
}
|
||||
return s, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unable to cast %#v of type %T to []map[string]interface{}", in, in)
|
||||
}
|
||||
}
|
||||
|
||||
type keyRename struct {
|
||||
pattern glob.Glob
|
||||
newKey string
|
||||
|
Reference in New Issue
Block a user