diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-05-27 22:57:57 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-06-09 16:54:36 +0200 |
commit | 8d898ad6672e0ccb62c5a29b6fccab24d980f104 (patch) | |
tree | cc937519b8b2008ff7311ab6af6b9685c4756f62 /hugolib/menu_test.go | |
parent | fad183c4ae55069be9246e64ab1c8b2f43d08d06 (diff) |
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
Diffstat (limited to 'hugolib/menu_test.go')
-rw-r--r-- | hugolib/menu_test.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go index f1db3cb3a..4a2b17603 100644 --- a/hugolib/menu_test.go +++ b/hugolib/menu_test.go @@ -222,3 +222,54 @@ menu: "main" b.AssertFileContent("public/index.html", "AMP and HTML|/blog/html-amp/|AMP only|/amp/blog/amp/|HTML only|/blog/html/|Home Sweet Home|/|") b.AssertFileContent("public/amp/index.html", "AMP and HTML|/amp/blog/html-amp/|AMP only|/amp/blog/amp/|HTML only|/blog/html/|Home Sweet Home|/amp/|") } + +// https://github.com/gohugoio/hugo/issues/5989 +func TestMenuPageSortByDate(t *testing.T) { + + b := newTestSitesBuilder(t).WithSimpleConfigFile() + + b.WithContent("blog/a.md", ` +--- +Title: A +date: 2019-01-01 +menu: + main: + identifier: "a" + weight: 1 +--- + +`) + + b.WithContent("blog/b.md", ` +--- +Title: B +date: 2018-01-02 +menu: + main: + parent: "a" + weight: 100 +--- + +`) + + b.WithContent("blog/c.md", ` +--- +Title: C +date: 2019-01-03 +menu: + main: + parent: "a" + weight: 10 +--- + +`) + + b.WithTemplatesAdded("index.html", `{{ range .Site.Menus.main }}{{ .Title }}|Children: +{{- $children := sort .Children ".Page.Date" "desc" }}{{ range $children }}{{ .Title }}|{{ end }}{{ end }} + +`) + + b.Build(BuildCfg{}) + + b.AssertFileContent("public/index.html", "A|Children:C|B|") +} |