aboutsummaryrefslogtreecommitdiffhomepage
path: root/related
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2023-01-17 12:36:34 +0100
committerBjørn Erik Pedersen <[email protected]>2023-01-17 12:50:26 +0100
commitd595419031b247d6f15a615f6e70b1956ff8eab1 (patch)
treed9dd72eb28ddcdd4854244cbdcf2bfdb654aa7f3 /related
parent671f64b2eba077e2456a32feabfa94e5dc8af511 (diff)
downloadhugo-d595419031b247d6f15a615f6e70b1956ff8eab1.tar.gz
hugo-d595419031b247d6f15a615f6e70b1956ff8eab1.zip
related: Handly []any
See #10624
Diffstat (limited to 'related')
-rw-r--r--related/inverted_index.go3
-rw-r--r--related/inverted_index_test.go13
2 files changed, 16 insertions, 0 deletions
diff --git a/related/inverted_index.go b/related/inverted_index.go
index 1b1f69e3e..5502f9f11 100644
--- a/related/inverted_index.go
+++ b/related/inverted_index.go
@@ -23,6 +23,7 @@ import (
"time"
"github.com/gohugoio/hugo/common/maps"
+ "github.com/spf13/cast"
"github.com/gohugoio/hugo/common/types"
"github.com/mitchellh/mapstructure"
@@ -283,6 +284,8 @@ func (cfg IndexConfig) ToKeywords(v any) ([]Keyword, error) {
vv = vc
}
keywords = append(keywords, StringsToKeywords(vv...)...)
+ case []any:
+ return cfg.ToKeywords(cast.ToStringSlice(vv))
case time.Time:
layout := "2006"
if cfg.Pattern != "" {
diff --git a/related/inverted_index_test.go b/related/inverted_index_test.go
index fdef06b13..7a3bd89c7 100644
--- a/related/inverted_index_test.go
+++ b/related/inverted_index_test.go
@@ -212,6 +212,19 @@ func TestToKeywordsToLower(t *testing.T) {
})
}
+func TestToKeywordsAnySlice(t *testing.T) {
+ c := qt.New(t)
+ var config IndexConfig
+ slice := []any{"A", 32, "C"}
+ keywords, err := config.ToKeywords(slice)
+ c.Assert(err, qt.IsNil)
+ c.Assert(keywords, qt.DeepEquals, []Keyword{
+ StringKeyword("A"),
+ StringKeyword("32"),
+ StringKeyword("C"),
+ })
+}
+
func BenchmarkRelatedNewIndex(b *testing.B) {
pages := make([]*testDoc, 100)
numkeywords := 30