Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Fok <foka@debian.org>2015-01-24 14:44:35 +0300
committerbep <bjorn.erik.pedersen@gmail.com>2015-01-24 17:25:44 +0300
commit803865f870f9d0b4aa0015b6bdec15d37c2fab00 (patch)
tree04dd96c71c2666dc127d73931853ce6d6397a62b
parenta0c6dba305b86f638ec2d7d75a3a07248e4ae158 (diff)
Fix for page.GetParam() for JSON and TOML maps
Setting per-page Blackfriday angledQuotes did not work with TOML or JSON front matter, but it does work with YAML. It turns out that page.Params("blackfriday") returns type map[interface{}]interface{} for YAML, but type map[string]interface{} for JSON and TOML. This patch updates page.GetParam() to catch the latter, with an error message if page.GetParam() does not recognize a type. A test is also added.
-rw-r--r--hugolib/page.go7
-rw-r--r--hugolib/page_test.go12
2 files changed, 18 insertions, 1 deletions
diff --git a/hugolib/page.go b/hugolib/page.go
index 395462d84..eadf6eb3d 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -19,6 +19,7 @@ import (
"fmt"
"github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/parser"
+ "reflect"
"github.com/spf13/cast"
"github.com/spf13/hugo/hugofs"
@@ -522,9 +523,13 @@ func (page *Page) GetParam(key string) interface{} {
return cast.ToTime(v)
case []string:
return helpers.SliceToLower(v.([]string))
- case map[interface{}]interface{}:
+ case map[string]interface{}: // JSON and TOML
+ return v
+ case map[interface{}]interface{}: // YAML
return v
}
+
+ jww.ERROR.Printf("GetParam(\"%s\"): Unknown type %s\n", key, reflect.TypeOf(v))
return nil
}
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
index 887bd1016..d4ce7a0a0 100644
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -3,10 +3,12 @@ package hugolib
import (
"html/template"
"path/filepath"
+ "reflect"
"strings"
"testing"
"time"
+ "github.com/spf13/cast"
"github.com/spf13/hugo/helpers"
)
@@ -219,6 +221,9 @@ an_integer = 1
a_float = 1.3
a_bool = false
a_date = 1979-05-27T07:32:00Z
+
+[a_table]
+a_key = "a_value"
+++
Front Matter with various frontmatter types`
@@ -499,6 +504,13 @@ func TestDifferentFrontMatterVarTypes(t *testing.T) {
if page.GetParam("a_date") != dateval {
t.Errorf("frontmatter not handling dates correctly should be %s, got: %s", dateval, page.GetParam("a_date"))
}
+ param := page.GetParam("a_table")
+ if param == nil {
+ t.Errorf("frontmatter not handling tables correctly should be type of %v, got: type of %v", reflect.TypeOf(page.Params["a_table"]), reflect.TypeOf(param))
+ }
+ if cast.ToStringMap(param)["a_key"] != "a_value" {
+ t.Errorf("frontmatter not handling values inside a table correctly should be %s, got: %s", "a_value", cast.ToStringMap(page.Params["a_table"])["a_key"])
+ }
}
func TestDegenerateInvalidFrontMatterLeadingWhitespace(t *testing.T) {