Fix Params case handling in the index, sort and where func

This means that you can now do:

```
{{ range where .Site.Pages "Params.MYPARAM" "foo" }}
```
This commit is contained in:
Bjørn Erik Pedersen
2019-11-21 21:59:38 +01:00
parent cd07e6d57b
commit a3fe5e5e35
33 changed files with 317 additions and 155 deletions

View File

@@ -300,7 +300,7 @@ func (p *nopPage) Param(key interface{}) (interface{}, error) {
return nil, nil
}
func (p *nopPage) Params() map[string]interface{} {
func (p *nopPage) Params() maps.Params {
return nil
}

View File

@@ -17,6 +17,8 @@ import (
"html/template"
"time"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/common/hugo"
@@ -39,7 +41,7 @@ type Site interface {
Taxonomies() interface{}
LastChange() time.Time
Menus() navigation.Menus
Params() map[string]interface{}
Params() maps.Params
Data() map[string]interface{}
}
@@ -107,7 +109,7 @@ func (t testSite) BaseURL() template.URL {
return ""
}
func (t testSite) Params() map[string]interface{} {
func (t testSite) Params() maps.Params {
return nil
}

View File

@@ -370,7 +370,7 @@ func (p *testPage) Param(key interface{}) (interface{}, error) {
return resource.Param(p, nil, key)
}
func (p *testPage) Params() map[string]interface{} {
func (p *testPage) Params() maps.Params {
return p.params
}

View File

@@ -30,9 +30,9 @@ import (
"github.com/pkg/errors"
"github.com/gohugoio/hugo/common/hugio"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/resource"
"github.com/spf13/afero"
"github.com/gohugoio/hugo/helpers"
@@ -228,7 +228,7 @@ func (l *genericResource) Name() string {
return l.name
}
func (l *genericResource) Params() map[string]interface{} {
func (l *genericResource) Params() maps.Params {
return l.params
}

View File

@@ -19,12 +19,16 @@ import (
"github.com/spf13/cast"
)
func Param(r ResourceParamsProvider, fallback map[string]interface{}, key interface{}) (interface{}, error) {
func Param(r ResourceParamsProvider, fallback maps.Params, key interface{}) (interface{}, error) {
keyStr, err := cast.ToStringE(key)
if err != nil {
return nil, err
}
if fallback == nil {
return maps.GetNestedParam(keyStr, ".", r.Params())
}
return maps.GetNestedParam(keyStr, ".", r.Params(), fallback)
}

View File

@@ -14,6 +14,7 @@
package resource
import (
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/resources/images/exif"
@@ -85,7 +86,7 @@ type ResourceMetaProvider interface {
type ResourceParamsProvider interface {
// Params set in front matter for this resource.
Params() map[string]interface{}
Params() maps.Params
}
type ResourceDataProvider interface {

View File

@@ -129,7 +129,7 @@ func AssignMetadata(metadata []map[string]interface{}, resources ...resource.Res
params, found := meta["params"]
if found {
m := cast.ToStringMap(params)
m := maps.ToStringMap(params)
// Needed for case insensitive fetching of params values
maps.ToLower(m)
ma.updateParams(m)

View File

@@ -26,11 +26,11 @@ import (
bp "github.com/gohugoio/hugo/bufferpool"
"github.com/gohugoio/hugo/resources/internal"
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/hugio"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/resources/internal"
"github.com/gohugoio/hugo/resources/resource"
"github.com/gohugoio/hugo/media"
@@ -200,7 +200,7 @@ func (r *resourceAdapter) Name() string {
return r.target.Name()
}
func (r *resourceAdapter) Params() map[string]interface{} {
func (r *resourceAdapter) Params() maps.Params {
r.init(false, false)
return r.target.Params()
}