Front Matter

目录

了解 Hugo 和 FixIt 主题提供的 Front matter 配置项。

Hugo 允许你在内容文件中添加 yaml、toml 或 json 格式的 Front matter。

Hugo 内置字段

Hugo 原生支持的 Front matter 字段,详见 Hugo Front matter 文档。

  • title: 文章标题
  • date: 这篇文章创建的日期时间,通常从 Front matter 的 date 字段获取,但也可以在 主题配置 中设置
  • lastmod: 上次修改内容的日期时间
  • draft: 如果设为 true,除非 hugo 命令使用了 --buildDrafts/-D 参数,这篇文章不会被渲染
  • description: 文章内容的描述
  • keywords: 文章内容的关键词
  • images: 页面图片,用于 Open Graph 和 Twitter Cards
  • summary: 文章的摘要
  • tags: 文章的标签
  • categories: 文章所属的类别
  • type: 页面渲染模板,详见 页面模板
  • layout: 页面渲染模板,详见 页面模板
  • menu: 详见 添加内容到菜单

页面级字段

可在 hugo.toml 的 [params] 中全局设置,也可在每篇文章的 Front matter 中覆盖。详见 主题配置 - 页面级参数。

页面专属字段

FixIt 主题提供的仅在页面 Front matter 中使用的字段,无法在 hugo.toml 中设置全局默认值。

封面图片

  • featuredImage: 文章的特色图片
  • featuredImagePreview: 用在主页预览的文章特色图片

featuredImage 和 featuredImagePreview 支持 本地资源引用 的完整用法。

如果带有在 Front matter 中设置了 name: featured-image 或 name: featured-image-preview 属性的页面资源, 没有必要再设置 featuredImage 或 featuredImagePreview:

1
2
3
4
5
resources:
  - name: featured-image
    src: featured-image.jpg
  - name: featured-image-preview
    src: featured-image-preview.jpg

可见性控制

  • hidden_from_home_page: 如果设为 true,这篇文章将不会显示在主页上
  • hidden_from_search: 如果设为 true,这篇文章将不会显示在搜索结果中
  • hidden_from_related: FixIt 0.3.0 | 新增 如果设为 true,这篇文章将不会显示在相关文章中
  • hidden_from_feed: FixIt 0.3.10 | 新增 如果设为 true,这篇文章将不会显示在 RSS、ATOM 和 JSON Feed 中

集合

  • collections: FixIt 0.3.0 | 新增 文章的集合,类似 tags 和 categories,但为 FixIt 特有。

作者

  • authors: FixIt 1.0.0 | 新增 文章的作者注册表键名列表(多作者),例如 authors: [Alice, Bob]
  • author: 旧版单作者字段,可为名称字符串,或包含 name / link / email / avatar 的 map

当设置了 authors 时优先于 author。作者资料存放在 data/authors/<Key>.toml(可选 [zh-cn] 等语言子表);缺失的注册表键回退为 {name: key},且不会继承 params.author。结合 authors 分类,每个键还会生成 /authors/<key>/ 归档页。详见 主题配置 - author。

1
2
3
authors:
  - Alice
  - Bob

内容加密

特殊页面

仅在特殊页面(_index.md)中有效的 Front matter 字段。

  • titleIcon: 用于页面标题的图标
  • cardIcon: 用于分类(taxonomy)页面中分类卡片的图标,仅在分类 _index.md 中有效

示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
---
title: 我的第一篇文章
date: 2020-03-04T15:58:26+08:00
draft: true
authors:
  - Alice
categories:
  - Documentation
tags:
  - Hugo
  - FixIt
featuredImage: cover.jpg
hidden_from_home_page: false
lightgallery: true
toc:
  enable: true
math:
  enable: true
---

FixIt 主题内嵌了一些 原型 (Archetype),使用以下命令创建新内容时会自动带入常用的 Front matter:

hugo new posts/foo.md
# 或
hugo new --kind post-bundle posts/bar/

相关内容

Buy me a coffee
Lruihao 支付宝支付宝
Lruihao 微信微信

发现新版本

当前站点有新版本可用。