Skip to content

Commit

Permalink
related: Handly []any
Browse files Browse the repository at this point in the history
See #10624
  • Loading branch information
bep committed Jan 17, 2023
1 parent 671f64b commit d595419
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions related/inverted_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 != "" {
Expand Down
13 changes: 13 additions & 0 deletions related/inverted_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d595419

Please sign in to comment.