Does the order of .Data.Pages.ByPublishDate changed

Hi all,

I just set up my new computer and after running “hugo server” I realized that all my blog posts are now in the wrong order. I use {{ range .Data.Pages.ByPublishDate }} to list all blog posts and until now the newest blog was on top, now the list starts with the oldest blog.

I can’t say which version of Hugo was installed in my old system. On my new one it is version 0.35 and the output looks a bit different so it is probably a different/newer version.

Is this a bug or does the order of .Data.Pages.ByPublishDate changed in one of the last versions from “newest first” to “oldest first”?

Someone can help you better if you share the site source.

The whole source can be found here:

I have a CI job which builds the page and upload it to the webserver if I push some changes to the git repository. I just did this and the output of the CI job is still correct (newest blog first) so it seems to be a issue with my local Hugo installation. But the question is: bug or feature? :wink:

The sort order has not changed, but some versions ago we made sure that your publishDate gets the date’s value if not set in front matter, which may be what you see.

Indeed, the pages don’t have a publishDate but only a Date. But also with respect to the date the order changed and shows now the oldest post first in my local system. I also tried to change the code to .Data.Pages.ByDate which has the same result. The blog with the oldest date is first. You can find the blog post in question and the whole page here:

According to Git, the current ByPublishDate sort function was added/changed back in 2014:

5e28606b84 (Tatsushi Demachi 2014-10-18 00:10:19 +0900 185) 		return p1.PublishDate.Unix() < p2.PublishDate.Unix()

So when you say “changed”, what is your “before date” in that statement? 2013?

I don’t know. Maybe it is a bug in the Debian sid package? But this would be a strange bug caused by packaging.

Some additional observation. I noticed that on my local machine the blog articles on the webpage are in the wrong order but the rss feed contain the article in the right order. So I checked the differences. The template for the RSS feed doesn’t use .Data.Pages.ByPublishDate but Data.Pages. If I change it accordingly for the webpage the articles are again in the right order. Really confusing…

.Data.Pages uses a different (the default sort, which I think uses weight, Date, title), so that the order is changing should not be surprising.