How can I read in chronological order?

Also, the favicon now works too. No idea why it didn’t before, which troubles me. I know enough to get myself into trouble, but not enough to get out of it.

So I guess, you suckered me into learning more about templating, @sod :laughing:

That was my evil plan all along; you’re welcome. :wink: I do hope you get some utility and fun out of this new knowledge, though.

There seems to be a bug in the code for “previous/next.” After editing older posts, they got shoved elsewhere in the order. This means from that post, no earlier posts can be accessed, while those certainly exist.

I need date order, not the order in which they are stored in the database. Is there a way to accomplish this?

Okay, I’ll try my best to help you troubleshoot the problem. I need a post with a missing Eerder :point_left: link and the URL to the post you would expect to be there.

Here you go:

I suspect the post is shoved onto the back of the date base, or the ordering is based on modification date, instead of publication date. In either case, me updating old articles will change things. So there’s that to consider.

The proper ordering for 2010 is on this page:

For the year before, 2009:

I hope that’s enough for you. Thanks in advance!

So what we see here is the effect of .PrevInSection and .NextInSection. Let’s see what Hugo’s official documentation has to say about .PrevInSection:

Points down to the previous regular page below the same top level section (e.g. /blog). Pages are sorted by Hugo’s default sort. Example: {{if .PrevInSection}}{{.PrevInSection.Permalink}}{{end}}. Calling .PrevInSection from the last page returns nil.

Okay, I admit, that’s a bit of a mouthful. :blush: In your case, and I guess for everyone hosted on, the top-level section is the year the post was published. So in my basic example posted above, the next and previous links will always be scoped to the year.

When you arrive at the first post of a year, you won’t be able to go further back. In the same way, there won’t be a next post link when you arrive at the last post of a year.

To fix this, you could use .Next and .Prev instead. But that may have other unwanted side effects. Feel free to try it out, though. Just change every instance of .PrevInSection to .Prev and .NextInSection to .Next.

Another solution would be to order posts into a common top-level section (like /blog). I don’t know enough to tell you if that’s possible on a hosted, though. Maybe @manton can chime in here?

A third solution is to build upon my basic version to support navigation between sections (years).

I tried it, but—as you suspected—the result is unpredictable. The links seem to lead anywhere but the next or previous post. Sometimes it’s even a page instead of a post.

So, reverting to the old coding for now.

All my posts are in the category called “dagboek”; could this be used?

Also, see this Stackoverflow question:

Is using with somehow of influence?

Maybe, if you could collect posts in that category under a single section. Again, I don’t know if that is doable on a Hugo site. Let’s keep our fingers crossed @manton jumps into this thread to answer that. :blush:

No, unfortunately not. It’s just another way to write the same template, its output should be identical to my version. To quote the documentation for with:

An alternative way of writing an if statement and then referencing the same value is to use with instead. with rebinds the context (. ) within its scope and skips the block if the variable is absent, unset or empty.

This may be closer to what you want, @renevanbelzen.

{{ $diaryPages := .Site.Taxonomies.categories.dagboek.Pages.Reverse }}
{{ $currentPage := .Site.GetPage (.File.Path) }}
  {{ with $diaryPages.Prev $currentPage }}
    <a href="{{ .Permalink }}" rel="prev">Eerder 👈</a>
  {{ end }}

  {{ with $diaryPages.Next $currentPage }}
    <a href="{{ .Permalink }}" rel="next">👉 Later</a>
  {{ end }}

Replace my old version with the above and let me know how it works out.

Alas, @sod, it doesn’t work. The footer renders empty (no links to next or previous page), see screenshots below.

:point_up_2: single.html in Design

:point_up_2: single page (blog post) on test blog (with two pages in total)

:point_up_2: html source of the above blog post

This new version depends on the category you said you post under: dagboek. You can see that accounted for in the first part of the template:

{{ $diaryPages := .Site.Taxonomies.categories.dagboek.Pages.Reverse }}

If your test blog differs from your production blog, that snippet won’t work. Does your test blog have the category set up and posts assigned to that category?

No, it didn’t have any categories. I added those, and now it does work. Now testing on “the big blog.”

It works. A minor issue is that the most recent post points to the very first post, but that’s easy to fix by changing the wording (earlier to previous, later to next).

Thanks a lot. You helped me tremendously. :kissing_heart:


And now’s the time I try to decide if I feel the energy to try to adapt this “reverse chronological by day” to Marfa…

FWIW, I did use jsonbecker’s code and got this working in a Marfa template.

ETA: Hrm. I just discovered this breaks when paginating. I set my test blog to paginate at 5 posts, and it put the later of two posts from a given day on the first page and the earlier of the two on the second page.

Hey, @jsonbecker, I’ve a question about your “reverse days, chrono posts within days” code, which I played with adapting for Marfa thusly.

{{ define "main" }}  

{{ $posts := where site.RegularPages "Type" "post" }}
{{ $grouped := $posts.GroupByDate "2006-01-02" }}
{{ $paginated := (.Paginate ($grouped)) }}
<ul id="post-list">
{{ range $paginated.PageGroups }}
{{ $thedate := (time .Key) }}
<div class="day" style="text-align: center;"><aside class="dates" style="color: #000;">{{ $thedate.Format "Jan 2, 2006" }}</aside></div>
  {{ range .Pages.Reverse }}
    {{ if eq .Type "post" }}
{{ partial "post-item.html" . }}
    {{- end }}
  {{ end }}
{{ end }}
{{ partial "pagination.html" . }}
{{ end }}

The default Marfa file is below. Does anything jump out at you that I need to suss out how to incorporate from the default file that I didn’t already? (I’m not making a request that you do the work for me, just wondering if you see something obvious that I should be looking at. I’m no coder but I’m generally good at understanding code’s logic if I have a pointer or two.) Thanks!

{{ define "main" }}

<ul id="post-list">

{{ if or .IsHome .Site.Params.paginate_categories }}
	{{ $paginator := .Paginate (where .Site.Pages.ByDate.Reverse "Type" "post") }}
	{{ $list := $paginator.Pages }}
	{{ range $list  }}
		{{ partial "post-item.html" . }}
	{{ end }}
{{ else }}
	{{ $list := where .Site.Pages.ByDate.Reverse "Type" "post" }}
	{{ range $list  }}
		{{ partial "post-item.html" . }}
	{{ end }}
{{ end }}


{{ if .IsHome }}
	{{ if .Site.Params.paginate_home }}
		{{ partial "pagination" . }}
	{{ end }}
{{ else if .Site.Params.paginate_categories }}
	{{ partial "pagination" . }}
{{ end }}

{{ end }}

Nothing too specific. This code is cleaner than that earlier post (and is from my current theme which I have written as a plug-in but not released)

I don’t really know what the logic about paginated by category or home pages etc is trying to accomplish since I’m not familiar with Marfa.

I was just tackling the Dave Winer-style blog organization. But now I can’t figure out the problem that erupts upon pagination, which I noticed on your site, too. It’s like it’s counting out the number of posts for the page first, then passing that to the Winery magic, stranding the wrong post on the next page.

I’m pretty sure that’s a Hugo bug and/or some default somewhere in the pagination functions that I haven’t tracked down. I’m quite confident what I wrote is as close as you will be able to find about Hugo anywhere on the internet-- it may be worth asking on the Hugo forums, someone may know what default value I’m hitting into to split them up. It’s also possible it’s a oddity, though I doubt it-- there are some times defaults that get picked up set by if they’re not overwritten, but those have been reduced over time.

I wrote a post on the Hugo forums to see if anyone there has an idea.