diff options
author | Tatsushi Demachi <tdemachi@gmail.com> | 2015-11-10 22:02:45 +0900 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2015-11-10 14:57:03 +0100 |
commit | 139be09f1739238e757271058bb3cf0efec779c6 (patch) | |
tree | f753466cb31cef9cfd2b8cea78859977676f957d /hugolib | |
parent | bccf957e36346390336b172d10aae60bde90e397 (diff) |
Fix GroupByParam to return original param string
Page.GroupByParam function internally uses Page.GetParam to get a
parameter value for a key of a page group but now Page.GetParam returns
a lowercase character string every time. It has no need to using
lowercase character string as a group key value and it confuse a
function user.
This fixes it to keep and return an original parameter string as a group
key value.
Fix #1564
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/pageGroup.go | 2 | ||||
-rw-r--r-- | hugolib/pageGroup_test.go | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/hugolib/pageGroup.go b/hugolib/pageGroup.go index 05d8aff9f..955e76b65 100644 --- a/hugolib/pageGroup.go +++ b/hugolib/pageGroup.go @@ -171,7 +171,7 @@ func (p Pages) GroupByParam(key string, order ...string) (PagesGroup, error) { } for _, e := range p { - param := e.GetParam(key) + param := e.getParam(key, false) if param == nil || reflect.TypeOf(param) != keyt { continue } diff --git a/hugolib/pageGroup_test.go b/hugolib/pageGroup_test.go index c8d89fb03..2de07bc9d 100644 --- a/hugolib/pageGroup_test.go +++ b/hugolib/pageGroup_test.go @@ -220,6 +220,25 @@ func TestGroupByParamInReverseOrder(t *testing.T) { } } +func TestGroupByParamCalledWithCapitalLetterString(t *testing.T) { + testStr := "TestString" + f := "/section1/test_capital.md" + p, err := NewPage(filepath.FromSlash(f)) + if err != nil { + t.Fatalf("failed to prepare test page %s", f) + } + p.Params["custom_param"] = testStr + pages := Pages{p} + + groups, err := pages.GroupByParam("custom_param") + if err != nil { + t.Fatalf("Unable to make PagesGroup array: %s", err) + } + if groups[0].Key != testStr { + t.Errorf("PagesGroup key is converted to a lower character string. It should be %#v, got %#v", testStr, groups[0].Key) + } +} + func TestGroupByParamCalledWithSomeUnavailableParams(t *testing.T) { pages := preparePageGroupTestPages(t) delete(pages[1].Params, "custom_param") |