Creating an archive page

This will add an archive page similar to archive pages like these.

{{- define "main" -}}

<h1>{{ .Title }}</h1>

{{ .Content }}

<hr>

{{- /* Creating a section that lists out regular pages by year */ -}}
{{ range $.Site.RegularPages.GroupByPublishDate "2006" }}
    {{- /* Skip regular pages with an invalid creation date string. */ -}}
    {{- /* This is convenient if we want to exclude certain posts to be listed by giving no value to `date` in the frontmatter. */ -}}
    {{- /* We will also exclude hidden pages. */ -}}
    {{ if ne .Key "0001" }}
        <section data-year="{{ .Key }}">
            <h2 id="{{ .Key }}">{{ .Key }}</h2>
            <ul>
            {{- range where .Pages "Params.hidden" "!=" true -}}
                <li>
                    <date>{{ .Date.Format "2006-01-02" }}</date> -
                    <a aria-label="{{ .Title }}" href="{{ .Permalink }}">{{ .Title }}</a>
                </li>
            {{- end -}}
            </ul>
        </section>
    {{- end }}
{{ end }}

{{- end -}}

We will simply add this as a layout in our customized theme. Let’s call it archives so we have to add a file in layouts/_default/archives.html then set a page of our project with the layout key in the frontmatter.

We want the archives page to be accessed at $.Site.BaseURL/archives so we’ll simply create archives.adoc (any valid content files with certain file extensions can do, I’m using Asciidoctor) with the following example content.

---
title: "Archives"
layout: "archive"
---

= Archives

This is the archives of the century.