mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Adding support for boolean params
This commit is contained in:
parent
1da3fd039a
commit
1882ffabc6
2 changed files with 8 additions and 0 deletions
|
@ -412,6 +412,8 @@ func (page *Page) update(f interface{}) error {
|
||||||
default:
|
default:
|
||||||
// If not one of the explicit values, store in Params
|
// If not one of the explicit values, store in Params
|
||||||
switch vv := v.(type) {
|
switch vv := v.(type) {
|
||||||
|
case bool:
|
||||||
|
page.Params[loki] = vv
|
||||||
case string:
|
case string:
|
||||||
page.Params[loki] = vv
|
page.Params[loki] = vv
|
||||||
case int64, int32, int16, int8, int:
|
case int64, int32, int16, int8, int:
|
||||||
|
@ -444,6 +446,8 @@ func (page *Page) GetParam(key string) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch v.(type) {
|
switch v.(type) {
|
||||||
|
case bool:
|
||||||
|
return interfaceToBool(v)
|
||||||
case string:
|
case string:
|
||||||
return interfaceToString(v)
|
return interfaceToString(v)
|
||||||
case int64, int32, int16, int8, int:
|
case int64, int32, int16, int8, int:
|
||||||
|
|
|
@ -209,6 +209,7 @@ var PAGE_WITH_VARIOUS_FRONTMATTER_TYPES = `+++
|
||||||
a_string = "bar"
|
a_string = "bar"
|
||||||
an_integer = 1
|
an_integer = 1
|
||||||
a_float = 1.3
|
a_float = 1.3
|
||||||
|
a_bool = false
|
||||||
a_date = 1979-05-27T07:32:00Z
|
a_date = 1979-05-27T07:32:00Z
|
||||||
+++
|
+++
|
||||||
Front Matter with various frontmatter types`
|
Front Matter with various frontmatter types`
|
||||||
|
@ -458,6 +459,9 @@ func TestDifferentFrontMatterVarTypes(t *testing.T) {
|
||||||
if page.GetParam("a_float") != 1.3 {
|
if page.GetParam("a_float") != 1.3 {
|
||||||
t.Errorf("frontmatter not handling floats correctly should be %s, got: %s", 1.3, page.GetParam("a_float"))
|
t.Errorf("frontmatter not handling floats correctly should be %s, got: %s", 1.3, page.GetParam("a_float"))
|
||||||
}
|
}
|
||||||
|
if page.GetParam("a_bool") != false {
|
||||||
|
t.Errorf("frontmatter not handling bools correctly should be %s, got: %s", false, page.GetParam("a_bool"))
|
||||||
|
}
|
||||||
if page.GetParam("a_date") != dateval {
|
if page.GetParam("a_date") != dateval {
|
||||||
t.Errorf("frontmatter not handling dates correctly should be %s, got: %s", dateval, page.GetParam("a_date"))
|
t.Errorf("frontmatter not handling dates correctly should be %s, got: %s", dateval, page.GetParam("a_date"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue