Frontmatter 是每个 Markdown 文件开头的 YAML 格式配置部分,使用两个 --- 包裹内容(数据格式不同,包裹的符号不同,推荐使用 YAML),用于设置文章的元数据和特定功能,在每篇文章中通过更改 Frontmatter 参数,可以实现对 hugo.yaml 相关参数的覆盖,更灵活的修改站点。不同的内容模板支持的 frontmatter 参数不同。

如果你不清楚什么是内容模板,请访问:内容模板

默认内容模板

默认内容模板用于生成文章文件和未定义内容模板的其他内容。

基础配置

YAML
 1---
 2# 必填项
 3title: "文章标题"
 4date: 2025-06-13
 5# 可选项
 6description: "文章描述"
 7draft: false
 8categories: ["分类1", "分类2"]
 9tags: ["标签1", "标签2"]
10slug: "custom-url"
11cover: ""
12---
点击展开查看更多

如果你不在意 SEO,可以使用 ~/archetypes/default.md 文件中的配置自动生成 slug,会生成随机的 7 位字符串。

YAML
1slug: { { substr .File.UniqueID 0 7 } }
点击展开查看更多

其他配置

文章内容模板还支持其他配置,这些配置涉及到主题的一些功能,通常在 hugo.yaml 配置,但你也可以在头信息中修改覆盖。

YAML
 1# 公式
 2katex:
 3  enabled: true
 4  delimiters:
 5    - left: $$
 6      right: $$
 7      display: true
 8    - left: $
 9      right: $
10      display: false
11
12# 图表
13mermaid:
14  enabled: true
15
16# 相关文章
17showRelated: true
18
19# 文章版权信息
20post:
21  license:
22    show: true
23    author: "Hugo Narrow"
24    name: "CC BY-NC-SA 4.0"
25    description: "This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license."
26    url: "https://creativecommons.org/licenses/by-nc-sa/4.0/"
27    displayName: "CC BY-NC-SA 4.0"
点击展开查看更多

项目内容模板

项目内容模板用于生成项目文件,基础的参数设置和默认内容模板一致,同时还存在特有的配置参数,下面是项目内容模板特有的头信息参数:

YAML
1cover: ""
2featured: false
3url: "www.example.com"
4status: "completed" # Options: completed, in_progress, planning
点击展开查看更多

版权声明

作者: Hugo Narrow

链接: https://hugo-narrow-docs.vercel.app/zh-cn/docs/frontmatter/

许可证: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license.

开始搜索

输入关键词搜索文章内容

↑↓
ESC
⌘K 快捷键