在 Hugo 中默认只生成 tags 和 categories 两个页面,没有 archives (归档)页面,所以我们需要自己实现

1 新建归档单页面模板

首先,在 themes/主题/layouts 目录创建一个目录 archives 然后在里面新建一个文件 single.html

2 替换归档页面模板代码

注意我们接下来要覆盖 themes/主题/layouts/_default/baseof.html 中的 main 模块:

{{ define "main" }}
<link rel="stylesheet" href="{{ "css/archives.css" | absURL }}">
<article class="article article-type-post" itemscope="" itemprop="blogPost">
    <div class="article-inner">
        <div class="post-archive">
            {{ range (where (where .Site.Pages "Type" "post") "Kind" "page").GroupByDate "2006" }}
            <h2> {{ .Key }} </h2>
            <ul class="listing">
                {{ range .Pages }}
                <li>
                    <date class="meta-date">{{ .Date.Format "2006/01/02" }}</date>
                    <a class="archive-title" href="{{ .Permalink }}" title="{{ .Title }}">{{ .Title }}</a>
                </li>
                {{ end }}
            </ul>
            {{ end }}

        </div>
    </div>
</article>
{{ end }}

3 新建归档页面

接着在 content 目录创建文件 archives.mdtype 设置为 archives 就可以了:

---
title: "归档"
type: "archives"
prevnext: false
---

4 总结

在 Hugo 中定一个页面模板 baseof.html 我们可以去修改这个模板,然后再去填充或者覆盖对应的区域