mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-01 22:42:45 +02:00
tpl/collections: Unwrap any interface value in sort and where
Hugo `0.55.0` introduced some new interface types for `Page` etc. This worked great in general, but there were cases where this would fail in `where` and `sort`. One such example would be sorting by `MenuItem.Page.Date` where `Page` on `MenuItem` was a small subset of the bigger `page.Page` interface. This commit fixes that by unwrapping such interface values. Fixes #5989
This commit is contained in:
@@ -819,6 +819,10 @@ func (x TstX) TstRv() string {
|
||||
return "r" + x.B
|
||||
}
|
||||
|
||||
func (x TstX) TstRv2() string {
|
||||
return "r" + x.B
|
||||
}
|
||||
|
||||
func (x TstX) unexportedMethod() string {
|
||||
return x.unexported
|
||||
}
|
||||
@@ -850,6 +854,33 @@ type TstX struct {
|
||||
unexported string
|
||||
}
|
||||
|
||||
type TstXIHolder struct {
|
||||
XI TstXI
|
||||
}
|
||||
|
||||
// Partially implemented by the TstX struct.
|
||||
type TstXI interface {
|
||||
TstRv2() string
|
||||
}
|
||||
|
||||
func ToTstXIs(slice interface{}) []TstXI {
|
||||
s := reflect.ValueOf(slice)
|
||||
if s.Kind() != reflect.Slice {
|
||||
return nil
|
||||
}
|
||||
tis := make([]TstXI, s.Len())
|
||||
|
||||
for i := 0; i < s.Len(); i++ {
|
||||
tsti, ok := s.Index(i).Interface().(TstXI)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
tis[i] = tsti
|
||||
}
|
||||
|
||||
return tis
|
||||
}
|
||||
|
||||
func newDeps(cfg config.Provider) *deps.Deps {
|
||||
l := langs.NewLanguage("en", cfg)
|
||||
l.Set("i18nDir", "i18n")
|
||||
|
Reference in New Issue
Block a user