mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 07:18:54 +00:00
committed by
Bjørn Erik Pedersen
parent
df5421918a
commit
80e60847fb
@@ -107,29 +107,33 @@ func (c ReplacingJSONMarshaller) MarshalJSON() ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var removeZeroVAlues func(m map[string]any)
|
||||
removeZeroVAlues = func(m map[string]any) {
|
||||
var removeZeroValues func(m map[string]any)
|
||||
removeZeroValues = func(m map[string]any) {
|
||||
for k, v := range m {
|
||||
if !hreflect.IsMap(v) && !hreflect.IsTruthful(v) {
|
||||
delete(m, k)
|
||||
} else {
|
||||
switch vv := v.(type) {
|
||||
case map[string]any:
|
||||
removeZeroVAlues(vv)
|
||||
if len(vv) == 0 {
|
||||
// Keep intentionally empty map.
|
||||
continue
|
||||
}
|
||||
removeZeroValues(vv)
|
||||
if len(vv) == 0 {
|
||||
delete(m, k)
|
||||
}
|
||||
case []any:
|
||||
for _, vvv := range vv {
|
||||
if m, ok := vvv.(map[string]any); ok {
|
||||
removeZeroVAlues(m)
|
||||
removeZeroValues(m)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
removeZeroVAlues(m)
|
||||
removeZeroValues(m)
|
||||
converted, err = json.Marshal(m)
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ stdout 'Display project configuration'
|
||||
|
||||
hugo config
|
||||
stdout 'baseurl = .https://example.com/'
|
||||
stdout '\[contenttypes\.'
|
||||
hugo config --format json
|
||||
stdout '\"baseurl\": \"https://example.com/\",'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user