hugo博客建立归档页面
在 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.md
将 type
设置为 archives
就可以了:
---
title: "归档"
type: "archives"
prevnext: false
---
4 总结
在 Hugo 中定一个页面模板 baseof.html 我们可以去修改这个模板,然后再去填充或者覆盖对应的区域
- 原文作者:jchen
- 原文链接:http://jchenTech.github.io/post/%E5%8D%9A%E5%AE%A2/hugo%E5%8D%9A%E5%AE%A2%E5%BB%BA%E7%AB%8B%E5%BD%92%E6%A1%A3%E9%A1%B5%E9%9D%A2/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。