@breschke doing this from mobile, so I’m not 100%, but I believe sorting for pages goes weight > date, so sorting by modify date isn’t quite as easy. That said, I know that @moorereason gave me a similar response on a similar question.
I re-installed hugo from github to take advantage of this new sort function. I tried creating a new site and then using a modifed hyde-x theme with the following in layouts/_default/list.html:
But when I start the server, I get the following error:
ERROR: 2016/04/22 Error while rendering section post: template: theme/_default/list.html:4:16: executing "theme/_default/list.html" at <.Data.Pages.ByLastmo...>: can't evaluate field ByLastmod in type interface {}
OK, I managed to correctly install the latest source build and I no longer get an error. But the function appears to have no effect on the order of posts. MWE posts with the abovelist.hmtl layout:
1:
+++
date = "2016-04-20T13:43:35-06:00"
lastmod = "2016-04-20T13:43:35-06:00"
draft = true
title = "first"
+++
Testing 123
2:
+++
date = "2016-04-21T13:43:35-06:00"
lastmod = "9999-04-21T13:43:35-06:00"
draft = true
title = "next"
+++
Testing 456
3:
+++
date = "2016-04-22T13:43:35-06:00"
lastmod = "2016-04-22T13:43:35-06:00"
draft = true
title = "last"
+++
Testing 789
I’ve got the very newest version 0.24 and .ByLastmod does nothing for me on my list templates. Is there any sort of trick that I need to utilize? .Lastmod is usable in my .Render call and on my single.html, but it just won’t sort by it. Right now I’m using weight to try to feature recently modified stories but it’s not ideal.
This may be wrong in light of the replies already posted. But I am using the following:
date: I am using this as the last mod. So I update this on modification. It is used in sitemap and sort by detail.
publishdate: The initial publish date.
Isn’t this the easiest solution, or am I missing something obvious (only been using gohugo for 3 weeks or so)?
I enabled enableGitInfo = true in config.toml, and .Lastmod can retrieve the modified date correctly. However, the
Data.Pages.ByLastmod does not work.
I guess there’s no lastmod in my frontmatter and ByLastmod doesn’t retrieve .Lastmod.