summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-08-07 19:56:02 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-08-08 09:13:17 +0200
commit7d74cd0cc88716fba813e9e2e229c3b22b828b5f (patch)
treee07eae705148988da70e54cb48ec426c3b0a375a /common
parentd139f30234cbc60fef8a49611189519d40336dbe (diff)
commands: Handle floats without decimals in hugo config
Updates #11345
Diffstat (limited to 'common')
-rw-r--r--common/maps/maps.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/common/maps/maps.go b/common/maps/maps.go
index 6aefde927..f0fd3d5ce 100644
--- a/common/maps/maps.go
+++ b/common/maps/maps.go
@@ -210,3 +210,28 @@ func (r KeyRenamer) renamePath(parentKeyPath string, m map[string]any) {
}
}
}
+
+// ConvertFloat64WithNoDecimalsToInt converts float64 values with no decimals to int recursively.
+func ConvertFloat64WithNoDecimalsToInt(m map[string]any) {
+ for k, v := range m {
+ switch vv := v.(type) {
+ case float64:
+ if v == float64(int64(vv)) {
+ m[k] = int64(vv)
+ }
+ case map[string]any:
+ ConvertFloat64WithNoDecimalsToInt(vv)
+ case []any:
+ for i, vvv := range vv {
+ switch vvvv := vvv.(type) {
+ case float64:
+ if vvv == float64(int64(vvvv)) {
+ vv[i] = int64(vvvv)
+ }
+ case map[string]any:
+ ConvertFloat64WithNoDecimalsToInt(vvvv)
+ }
+ }
+ }
+ }
+}