mirror of
https://github.com/foo-dogsquared/hugo-theme-more-contentful.git
synced 2025-01-31 10:58:19 +00:00
2f06fd7861
All of the changes should be documented in the changelog.
1.9 KiB
1.9 KiB
title: "Creating an archive page" date: 2020-10-20T20:36:55+08:00
categories: - "recipe" ---
Creating an archive page
John Doe <johndoe@example.com> 2020-10-20 20:36:55 +0800 :stem: latexmath
{{- 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.