---
title: My Go Journey
date: 2017-03-23
publishdate: 2017-03-24
---
I decided to start learning Go in March 2017.
Follow my journey through this new blog.
<!--top of your baseof code--><main>
<article>
<header>
<h1>My Go Journey</h1>
</header>
<p>I decided to start learning Go in March 2017.</p>
<p>Follow my journey through this new blog.</p>
</article>
<ul>
<li><ahref="/posts/post-01/">Post 1</a></li>
<li><ahref="/posts/post-02/">Post 2</a></li>
</ul>
</main>
<!--bottom of your baseof-->
<!--baseof--><main>
<article>
<header>
<!-- Hugo assumes that .Title is the name of the section since there is no _index.md content file from which to pull a "title:" field --> <h1>Quotes</h1>
</header>
</article>
<ul>
<li><ahref="https://example.com/quote/quotes-01/">Quote 1</a></li>
<li><ahref="https://example.com/quote/quotes-02/">Quote 2</a></li>
</ul>
</main>
<!--baseof-->
{{partial"header.html".}}{{partial"subheader.html".}}<main>
<div>
<h1>{{.Title}}</h1>
<ul>
<!-- Renders the li.html content view for each content/posts/*.md -->{{range.Pages}}{{.Render"li"}}{{end}} </ul>
</div>
</main>
{{partial"footer.html".}}
分类模板
layouts/_default/taxonomy.html
1
2
3
4
5
6
7
8
9
10
11
{{define"main"}}<main>
<div>
<h1>{{.Title}}</h1>
<!-- ranges through each of the content files associated with a particular taxonomy term and renders the summary.html content view -->{{range.Pages}}{{.Render"summary"}}{{end}} </div>
</main>
{{end}}
内容排序
Hugo 根据您在前置元数据中提供的内容来渲染列表。除了合理的默认值外,Hugo 还提供了多种方法,以便在列表模板内快速进行内容排序:
Default: Weight > Date > LinkTitle > FilePath
layouts/partials/default-order.html
1
2
3
4
5
6
7
8
<ul>
{{range.Pages}} <li>
<h1><ahref="{{.Permalink}}">{{.Title}}</a></h1>
<time>{{.Date.Format"Mon, Jan 2, 2006"}}</time>
</li>
{{end}}</ul>
按权重
较低的权重具有较高的优先级。因此,权重较低的内容将排在前面。
layouts/partials/by-weight.html
1
2
3
4
5
6
7
8
<ul>
{{range.Pages.ByWeight}} <li>
<h1><ahref="{{.Permalink}}">{{.Title}}</a></h1>
<time>{{.Date.Format"Mon, Jan 2, 2006"}}</time>
</li>
{{end}}</ul>
按日期
layouts/partials/by-date.html
1
2
3
4
5
6
7
8
9
<ul>
<!-- orders content according to the "date" field in front matter -->{{range.Pages.ByDate}} <li>
<h1><ahref="{{.Permalink}}">{{.Title}}</a></h1>
<time>{{.Date.Format"Mon, Jan 2, 2006"}}</time>
</li>
{{end}}</ul>
按发布日期
layouts/partials/by-publish-date.html
1
2
3
4
5
6
7
8
9
<ul>
<!-- orders content according to the "publishdate" field in front matter -->{{range.Pages.ByPublishDate}} <li>
<h1><ahref="{{.Permalink}}">{{.Title}}</a></h1>
<time>{{.Date.Format"Mon, Jan 2, 2006"}}</time>
</li>
{{end}}</ul>
按到期日期
layouts/partials/by-expiry-date.html
1
2
3
4
5
6
7
8
<ul>
{{range.Pages.ByExpiryDate}} <li>
<h1><ahref="{{.Permalink}}">{{.Title}}</a></h1>
<time>{{.Date.Format"Mon, Jan 2, 2006"}}</time>
</li>
{{end}}</ul>
按最后修改日期
layouts/partials/by-last-mod.html
1
2
3
4
5
6
7
8
9
<ul>
<!-- orders content according to the "lastmod" field in front matter -->{{range.Pages.ByLastmod}} <li>
<h1><ahref="{{.Permalink}}">{{.Title}}</a></h1>
<time>{{.Date.Format"Mon, Jan 2, 2006"}}</time>
</li>
{{end}}</ul>
按长度
layouts/partials/by-length.html
1
2
3
4
5
6
7
8
9
<ul>
<!-- orders content according to content length in ascending order (i.e., the shortest content will be listed first) -->{{range.Pages.ByLength}} <li>
<h1><ahref="{{.Permalink}}">{{.Title}}</a></h1>
<time>{{.Date.Format"Mon, Jan 2, 2006"}}</time>
</li>
{{end}}</ul>
按标题
layouts/partials/by-title.html
1
2
3
4
5
6
7
8
9
<ul>
<!-- ranges through content in ascending order according to the "title" field set in front matter -->{{range.Pages.ByTitle}} <li>
<h1><ahref="{{.Permalink}}">{{.Title}}</a></h1>
<time>{{.Date.Format"Mon, Jan 2, 2006"}}</time>
</li>
{{end}}</ul>
按链接标题
layouts/partials/by-link-title.html
1
2
3
4
5
6
7
8
9
<ul>
<!-- ranges through content in ascending order according to the "linktitle" field in front matter. If a "linktitle" field is not set, the range will start with content that only has a "title" field and use that value for .LinkTitle -->{{range.Pages.ByLinkTitle}} <li>
<h1><ahref="{{.Permalink}}">{{.LinkTitle}}</a></h1>
<time>{{.Date.Format"Mon, Jan 2, 2006"}}</time>
</li>
{{end}}</ul>
<ul>
{{range.Pages.ByDate.Reverse}} <li>
<h1><ahref="{{.Permalink}}">{{.Title}}</a></h1>
<time>{{.Date.Format"Mon, Jan 2, 2006"}}</time>
</li>
{{end}}</ul>
分组内容
Hugo 提供一些函数,可按章节、类型、日期等对页面进行分组。
按页面字段
layouts/partials/by-page-field.html
1
2
3
4
5
6
7
8
9
10
11
12
<!-- Groups content according to content section. The ".Key" in this instance will be the section's title. -->{{range.Pages.GroupBy"Section"}}<h3>{{.Key}}</h3>
<ul>
{{range.Pages}} <li>
<ahref="{{.Permalink}}">{{.Title}}</a>
<divclass="meta">{{.Date.Format"Mon, Jan 2, 2006"}}</div>
</li>
{{end}}</ul>
{{end}}
<!-- Groups content according to content section.-->{{range.Pages.GroupBy"Section"}}<!-- Checks for existence of _index.md for a section; if available, pulls from "title" in front matter -->{{with$.Site.GetPage"section".Key}}<h3>{{.Title}}</h3>
{{else}}<!-- If no _index.md is available, ".Key" defaults to the section title and filters to title casing --><h3>{{.Key|title}}</h3>
{{end}}<ul>
{{range.Pages}} <li>
<ahref="{{.Permalink}}">{{.Title}}</a>
<divclass="meta">{{.Date.Format"Mon, Jan 2, 2006"}}</div>
</li>
{{end}}</ul>
{{end}}
按日期
layouts/partials/by-page-date.html
1
2
3
4
5
6
7
8
9
10
11
12
<!-- Groups content by month according to the "date" field in front matter -->{{range.Pages.GroupByDate"2006-01"}}<h3>{{.Key}}</h3>
<ul>
{{range.Pages}} <li>
<ahref="{{.Permalink}}">{{.Title}}</a>
<divclass="meta">{{.Date.Format"Mon, Jan 2, 2006"}}</div>
</li>
{{end}}</ul>
{{end}}
<!-- Groups content by month according to the "publishDate" field in front matter -->{{range.Pages.GroupByPublishDate"2006-01"}}<h3>{{.Key}}</h3>
<ul>
{{range.Pages}} <li>
<ahref="{{.Permalink}}">{{.Title}}</a>
<divclass="meta">{{.PublishDate.Format"Mon, Jan 2, 2006"}}</div>
</li>
{{end}}</ul>
{{end}}
<!-- Groups content by month according to the "lastMod" field in front matter -->{{range.Pages.GroupByLastmod"2006-01"}}<h3>{{.Key}}</h3>
<ul>
{{range.Pages}} <li>
<ahref="{{.Permalink}}">{{.Title}}</a>
<divclass="meta">{{.Lastmod.Format"Mon, Jan 2, 2006"}}</div>
</li>
{{end}}</ul>
{{end}}
<!-- Groups content by month according to the "expiryDate" field in front matter -->{{range.Pages.GroupByExpiryDate"2006-01"}}<h3>{{.Key}}</h3>
<ul>
{{range.Pages}} <li>
<ahref="{{.Permalink}}">{{.Title}}</a>
<divclass="meta">{{.ExpiryDate.Format"Mon, Jan 2, 2006"}}</div>
</li>
{{end}}</ul>
{{end}}
<!-- Groups content according to the "param_key" field in front matter -->{{range.Pages.GroupByParam"param_key"}}<h3>{{.Key}}</h3>
<ul>
{{range.Pages}} <li>
<ahref="{{.Permalink}}">{{.Title}}</a>
<divclass="meta">{{.Date.Format"Mon, Jan 2, 2006"}}</div>
</li>
{{end}}</ul>
{{end}}
按照页面参数和日期格式
在按date分组的模板中,使用了 Go 的布局字符串来进一步分组。有关如何使用 Go 的布局字符串格式化 Hugo 中的日期的更多示例,请参见 Format 函数。
layouts/partials/by-page-param-as-date.html
1
2
3
4
5
6
7
8
9
10
11
12
<!-- Groups content by month according to the "param_key" field in front matter -->{{range.Pages.GroupByParamDate"param_key""2006-01"}}<h3>{{.Key}}</h3>
<ul>
{{range.Pages}} <li>
<ahref="{{.Permalink}}">{{.Title}}</a>
<divclass="meta">{{.Date.Format"Mon, Jan 2, 2006"}}</div>
</li>
{{end}}</ul>
{{end}}