gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.47k stars 7.5k forks source link

GroupByParamDate produces "runtime error: index out of range" #4440

Closed blob42 closed 6 years ago

blob42 commented 6 years ago

Hugo version: v0.36.1 linux/amd64 Go version: v1.10

I have a custom date param that looks like this on my front matter

---
date: 2018-02-20
my_param: 2017-02-01
---

This date param is used in many pages and I want to use it to group and order content. I tried using .GroupByParamDate like this

 {{ $grouped_pages := .Data.Pages.GroupByParamDate "my_param" "2006-01-02" }}

This produces the following error

ERROR 2018/02/21 17:39:17 Failed to render "theme/index.html": runtime error: index out of range

I made sure the my_param parameter is set and readable. I can even use it with GroupByParam without problem.

Problem is the custom param is parsed as string in Hugo so I cannot use the "sort" function reliably. It actually seems to work following the Golang string comparison function but there is no guarantee this sort is going to work on all dates. Or am I missing something ?

What would be the best way to achieve what I need ?

bep commented 6 years ago

Thanks for getting in touch, but it feels like this is a question that would be better suited to the Hugo Discussion Forum. We prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug. You may also find the answers you search for in Hugo Documentation.

blob42 commented 6 years ago

Ok thanks, as advised I posted on the forums here

blob42 commented 6 years ago

@bep I posted a link to a test repo on the forums and it seems it's actually a bug with the JSON format of front matter

sbibauw commented 6 years ago

Hi everyone, I am having the same error message, caused identically by GroupByParamDate, with an hugo website with the hugo-academic theme.

The interesting thing is that everything was working perfectly until I converted the frontmatter of all pages into YAML syntax (--- key: value) rather than TOML. Everything was fine until the last page of the section, and even after I converted this last page to YAML, if hugo was running as server mode, it correctly regenerated the page. But after stopping the server and trying to the build again, it fails with the same error.

Could it be possible to integrate @sp4ke fix into Hugo?

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.