Listing all posts

I have a page in my site at /archives using this template in layouts/_default/archives.html

This lists all posts in one page, grouped by month and year. I have a “mainSections” param in my config.toml file that lets me pick which content types should be listed here, or displayed on the front page of the site.

mainSections = ["posts", "podcast"] # list any other content types to include

It’s viewable at Archives - D'Arcy Norman dot net

{{ define "main" }}

<div class="container" role="main">
  <div class="row">
    <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
  <main>
      {{ .Content }}

	{{ $pages := where site.RegularPages "Type" "in" site.Params.mainSections }}
	{{ range $pages.GroupByPublishDate "2006-01" }}
	<h2 class="archive-year" id="{{.Key | urlize}}">{{.Key}}</h2>
		<ul class="year-of-posts">
			{{ range sort .Pages "PublishDate" "asc" }}
			<li>
				<p>
					<time datetime="{{ .PublishDate.Format "2006-01-02T15:04:05-07:00" }}"></time>
					{{ .PublishDate.Format "January 2" }}: <a href="{{.Permalink}}">{{.Title}} </a>
				</p>
			</li>
			{{end}}
		</ul>
	{{end}}
  </main>
</div>
</div>
</div>

{{end}}