页面元数据(Front matter)¶
对应官方:Frontmatter
Front matter 是放在 Markdown 文件顶部的 YAML 块,用
---包裹。Zensical 会在交给 Markdown 解析器前将其剥离,用于设置页面标题、描述、图标、隐藏元素等。
基本写法¶
docs/某页.md
---
title: 页面标题
description: 页面描述
---
# 正文标题
也可用 meta 插件在 meta.yml 中集中提供元数据,避免每页重复写。
官方支持的字段¶
| 字段 | 作用 |
|---|---|
title |
覆盖页面标题,用于导航和 <title> 标签 |
description |
页面描述,写入 HTML head 的 meta 标签 |
icon |
导航栏中显示的页面图标,须来自内置图标集 |
status |
页面状态,在导航侧边栏显示 |
template |
为页面指定自定义模板,替代默认 main.html |
hide |
隐藏页面元素 |
| 自定义字段 | 传给模板或插件使用 |
title / description / icon¶
---
title: Lorem ipsum dolor sit amet
description: Nullam urna elit, malesuada eget finibus ut, ac tortor.
icon: lucide/braces
---
status(页面状态)¶
先在配置中定义状态:
[project.extra.status]
new = "Recently added"
extra:
status:
new: Recently added
然后在页面使用:
---
status: new
---
- 状态标识符只允许字母、数字、
-、_ - 内置状态:
new(:lucide-badge-alert:图标)、deprecated(:lucide-trash:图标)
template(自定义模板)¶
---
template: my_homepage.html
---
模板需放入已配置的 custom_dir 目录,见 主题定制指南。
hide(隐藏元素)¶
---
hide:
- navigation
- toc
---
| 值 | 隐藏内容 |
|---|---|
navigation |
导航侧边栏 |
toc |
目录 |
path |
导航路径(面包屑) |
footer |
上一页/下一页链接 |
feedback |
反馈组件 |
tags |
页面标签 |
自定义字段¶
Front matter 可加入任意元数据,供模板或插件读取:
---
robots: noindex, nofollow
---
模板中通过 page.meta.robots 使用:
{% if page and page.meta and page.meta.robots %}
<meta name="robots" content="{{ page.meta.robots }}" />
{% else %}
<meta name="robots" content="index, follow" />
{% endif %}
标签插件也会读取 tags 字段,见 标签插件使用。
综合示例¶
---
title: Lorem ipsum dolor sit amet
description: Nullam urna elit, malesuada eget finibus ut, ac tortor.
icon: lucide/braces
status: new
template: my_homepage.html
hide:
- navigation
- toc
tags:
- Authoring
robots: noindex, nofollow
---