> For AI agents: the complete documentation index is available at https://rspress.rs/zh/llms.txt, the full documentation bundle is available at https://rspress.rs/zh/llms-full.txt.

# Frontmatter

你可以在 Markdown 文件的顶部添加 front matter。它是一个使用 [YAML](https://yaml.org/) 格式定义元数据的块，位于文件顶部的三个连字符 `---` 之间。

例如使用 [title](https://rspress.rs/zh/api/config/config-frontmatter.md#title) 来指定页面的标题，默认情况下，页面的 h1 标题将用作 HTML 文档的标题。如果你想使用不同的标题，你可以使用 front matter 来指定页面的标题。

```mdx
---
title: 我的主页
---

这是我的**主页内容**。
```

你也可以使用 [description](https://rspress.rs/zh/api/config/config-frontmatter.md#description) 来指定自定义的页面描述。默认情况下，Rspress 会提取 `h1` 标题下方第一段有内容的段落作为描述（参见 [description 的获取方式](https://rspress.rs/zh/guide/advanced/custom-head.md#description-%E7%9A%84%E8%8E%B7%E5%8F%96%E6%96%B9%E5%BC%8F)）。如果提取结果不满足需求，可以手动覆盖：

```mdx
---
description: 我的主页简介，用于 SEO 和社交媒体分享。
---
```

例如，你可以使用 [head](https://rspress.rs/zh/api/config/config-frontmatter.md#head) 设置 为 [Open Graph](https://ogp.me/) 指定自定义元标签。

```yaml
---
head:
  - - meta
    - property: og:url
      content: https://example.com/foo/
  - - meta
    - property: og:image
      content: https://example.com/bar.jpg
# - - [htmlTag]
#   - [attributeName]: [attributeValue]
#     [attributeName]: [attributeValue]
---
```

:::tip
查看 [Front matter 配置](https://rspress.rs/zh/api/config/config-frontmatter.md) 了解可用的 front matter 配置，查看 [useFrontmatter](https://rspress.rs/zh/ui/hooks/use-frontmatter.md) 了解如何在代码中获取 front matter。
:::
