Mentions
Webmentions
In an earlier post, I mentioned an issue with rendering a website built with Hugo. In the build command, I had to specify the theme. Jack Baty pointed out the theme could also be added to a configuration file (config.toml) so as not to have to enter it each time at the command line.
My next problem was that I wanted the blog post part of the Book theme to display the posts in reverse chronological order. However, it was displaying my post in the middle of the example posts, and I could not figure out what was driving the order. Jack Baty suggested looking at the template file in /layouts/posts/list.html. I looked at that file in the Book theme directory, and started looking at the lists page on the Hugo documentation site. After some reading, I found an example that showed how to display content in reverse order based on the date specified within the file. I changed the third line in the file from:
{{ range sort .Paginator.Pages }}
to
{{ range .Pages.ByDate.Reverse }}
I also edited the Date field in the posts to all have the same format:
date: “2019-06-03”
Once I did that, I got the results i was looking for – hurray! It would have been nice if the theme had done this “out of the box”, but at least I figured it out.
@AndySylvester You may have figured this out, but if not…You can also put
theme = "book"
in the config.toml file so you don’t need to add the flag every time you render.@jack thanks for the tip! I will try it on my next build.
@jack that worked great! I have a follow-up question: how do I get blog posts to be displayed in reverse chronological order?
@AndySylvester Most themes display posts in reverse chronological order by default, I would think. Perhaps “book” is different. I’ve not done it, but my guess is you’ll need to tinker with the template
/layouts/posts/list.html
and probably either removesort
or add.reverse
to the pagination bits. Sorry I’m not more useful.@jack per this page (https://gohugo.io/templates/lists/#reverse-order), I changed list.html to match the range command in the example, and that gave me the reverse order I wanted (also changed the date format in all the posts to be consistent). Thanks for the tip, that seemed to be the correct template to change!