I’m developing a blog with two sections: posts and notes. Notes will be published several times a day, whereas posts will appear less frequently. Each content type is formatted differently.
I’m trying to get all content to appear on the home page in reverse chronological order, but would like notes published in succession on the same day to be grouped under a date heading. If a post appears in between that day’s notes, notes should be grouped above and below them. For example:
January 25
Note 5.
Note 4.
Note 3.
Post headline
January 25
Post content.
January 25
Note 2.
Note 1.
I’ve been able to get part of the way there with the code below, which groups all notes under a date heading and publishes any posts above them if they appear.
Post headline
January 25
Post content.
January 25
Note 5.
Note 4.
Note 3.
Note 2.
Note 1.
Any ideas?
{{ range .Site.RegularPages.GroupByDate "January 2, 2006" }}
{{ range (.Pages.GroupBy "Section") }}
{{ if eq .Key "posts" }}
{{ range .Pages }}
<article class="post">
<header>
<h2><a href="{{ .Permalink }}">{{ .Title }}</a></h2>
<p>{{ .Date.Format "January 2, 2006" }}</p>
</header>
{{ .Content }}
</article>
{{ end }}
{{ end }}
{{ if eq .Key "notes" }}
{{ range .Pages.GroupByDate "January 2, 2006" }}
<h3 class="date">{{ .Key }}</h3>
{{ range .Pages }}
<div class="note">
{{ .Content }}
</div>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
Thanks in advance.