主要 Sections§
mainSections
参数用于过滤页面,默认为 ["posts", "docs"]
。
1mainSections = ["blog", "posts", "docs", "notes"]
Front Matter§
Front Matter is the place where we put page metadata and parameters, such as title, date and so on.
Formats§
Hugo supports three formats of front matter: YAML
, TOML
and JSON
.
TOML
: identified by opening and closing+++
.YAML
: identified by opening and closing---
.JSON
: a single JSON object surrounded by{
and}
, followed by a new line.
Let’s take TOML
as an example:
1+++
2title = 'Hello world!'
3+++
See also Page Parameters and Hugo Front Matter.
内容类型§
你可能想在其他 Section 中使用 docs
布局,比如 /notes
。这可以通过在 front matter 中设置 type = "docs"
实现。
文章原型§
我们也可以为 notes
创建一个原型,让 Hugo 处理 type
。
1$ cp themes/hugo-theme-bootstrap/archetypes/default.md archetypes/notes.md
然后在 archetypes/notes.md
中添加 type = "docs"
。现在 hugo new notes/blah-blah-blah
将会复制 archetypes/notes.md
的内容到新的文章。
同样地,你也可以为 posts
、docs
等自定义原型。
Sections 模板§
你可能还想在 notes
中使用和 docs
一样的列表布局。
1{{ define "content" }}
2{{- partial "docs/nav" . -}}
3<div class="col-xxl-7 ms-auto">
4 {{ partial "docs/list" . }}
5</div>
6{{- partial "docs/sidebar" . -}}
7{{ end }}
书写文章§
假设默认语言为
en
。
1$ hugo new posts/new-post/index.md
上述命令创建了一篇英文文章,同样的,我们也可以创建一篇简体中文的文章:
1$ hugo new posts/new-post/index.zh-cn.md
请注意:创建的文章一般处于草稿状态,本地预览时,
hugo server
需要指定-D
参数才能预览草稿文章。文章发布时,需要将draft
改为false
,或者直接移除draft
参数。
摘要选择顺序§
- If
post.excerpt = "description"
anddescription
is not empty, then it’ll be used. - Manual splitting via
<!–more–>
. - If
summary
on front matter isn’t empty, thensummary
will be selected. - The text of content will be cut off by
post.excerptMaxLength
and formatted in plain text or HTML whenpost.plainifyExcerpt = true
.
1[post]
2 # excerpt = "description"
3 # excerptMaxLength = 120
4 # copyright = false # Whether to display copyright section on each post.
5 # plainifyExcerpt = false # Format excerpt in HTML if false.
特色图片选择顺序§
- The
images
on front matter are preferred. - Page images resources that match the
*feature*
pattern. Such asposts/my-page/feature.png
,posts/my-page/featured-sample.jpg
.
The featured image doesn’t show up above content by default, you’ll need to turn on this feature by following parameter.
config/_default/params.toml
1[post]
2 featuredImage = true
config/_default/params.yaml
1post:
2 featuredImage: true
config/_default/params.json
1{
2 "post": {
3 "featuredImage": true
4 }
5}
缩略图选择顺序§
- The
images
on front matter are preferred. - Page images resources that match the filename’s patterns:
*feature*
,*cover*
and*thumbnail*
. Such asposts/my-page/feature.png
,posts/my-page/thumnail.jpg
.
The page images resources will be resized to several smaller versions to suit the users devices for saving the bandwidth.
文章置顶§
你可以通过在 front matter 设置 pinned
为 true
以置顶文章。
1+++
2title = "Pinned Post"
3pinned = true
4pinnedWeight = 100
5+++
如果有多个置顶文章,那么将按照
pinnedWeight
进行降序排序。
站点配置§
1pinnedPost = false # 关闭文章置顶功能
2pinnedPostCount = 2 # 首页显示的置顶文章的数目
Carousel§
将文章于 carousel 显示。
1+++
2carousel = true
3+++
作者§
HBS supports the authors taxonomy. Firstly, you’ll need to enable it by setting the following configuration.
config.toml
1[taxonomies]
2 author = 'authors'
config.yaml
1taxonomies:
2 author: authors
config.json
1{
2 "taxonomies": {
3 "author": "authors"
4 }
5}
And then define the authors
on your posts.
1+++
2authors = [
3 "Foo",
4 "Bar"
5]
6+++
Now, the authors will be present on the post meta and sidebar taxonomies.
Finally, we may need to introduce the author in more detail. Take the Foo
as an example, just create a page with the following content and save it as /content/authors/foo/index.md
.
1---
2title: Razon Yang
3description: Gopher, PHPer, Full Stack Engineer.
4social:
5 github: razonyang
6 twitter: razonyang
7---
title
: The author display name.description
: The introduction.social
: Social links.
The author image should be placed at the same folder with pattern avatar*
, such as /content/authors/foo/avatar.png
. If there is no avatar, the social.email
will be used to generate Gravatar avatar.
评论