I’m using Hugo Static Site Generator v0.62.0/extended darwin/amd64 BuildDate: unknown from Homebrew and I’m trying to group posts by date and limit those posts to the first 10 day’s worth of posts on the home page.
I can’t get this working and end up with a single post rendered by my single.html and not my home index.html. This single post is the 30th newest post and not the latest and I can’t explain how this is selected either.
A simplified version of what I’m doing is this:
In mytheme/layouts/_default/baseof.html I have a {{ block "main" . }}{{ end }}
In mytheme/layouts/index.html I have the following:
{{ define "main" }}
<ul class="post-list">
{{ range first 10 (( where .Site.RegularPages "Type" "post" ).GroupByDate "2 Jan 2006") }}
<li><div class="post-meta">{{ .Key }}</div>
{{ range .Pages }}
<ul class="post-list">
<li>
<h2>
<a href="{{ .Permalink }}">{{ .Title }}</a>
</h2>
</li>
{{ end }}
{{ end }}
</ul>
{{ end }}
This for some reason renders only the single post I mentioned earlier.
If I move the {{ range first 10...}} section from mytheme/layouts/index.html into mytheme/layouts/_default/baseof.html, I get the posts as I expect.
It’s difficult to say without seeing the rest of your site code. Other than a missing closlng </ul> it looks like it should work. Do you have a repo somewhere we can have a look at?
Have a read about Requesting Help to see how to make it easier to get help.
Whoops, I should have included that in the OP. The code can be seen at https://github.com/lildude/hugo-minima-dude - I’m in the process of porting one of my Jekyll themes to Hugo.
I’ve also tried dropping the block of code into a few other themes and get the same behaviour.
Ooops, sorry I didn’t think content would be needed. I’ve added the copy of hugoBasicExample I’m using to test this to the repo and symlinked to the base dir for the theme.
I made a mistake in my previous post - when I ran the server of the new clone, I left off --disableFastRender so found the in both my original and copy I got the bad behaviour with that flag, but not without.
That aside, I think I’ve found the ultimate cause… several of my posts don’t have titles and the one and only post that shows when I hit the issue is the first post without a title in the frontmatter. As soon as I added a title, things consistently display correctly.
Sorry about the noise and thanks for responding @pointyfar