数据绑定

在 Markdown 中绑定数据

使用 Nuxt Content 的 数据绑定功能, 你可以在 Markdown 文档中使用 {{ $doc.variable || 'defaultValue' }} 语法绑定数据. 这允许你在文档顶部的 YAML frontmatter 中定义这些值, 或者通过 app.config.ts 中的全局变量来定义.

YAML 前置内容中的文档变量

example.md
---
title: 'Title of the page'
description: 'Meta description of the page'
customVariable: 'Custom Value'
---

# 标题是 {{ $doc.title }}, 自定义变量是 {{ $doc.customVariable || 'defaultValue' }}

app.config.ts 中的全局变量

app.config.ts
export default defineAppConfig({
  shadcnDocs: {
    // ...
    data: {
      currentVersion: 'v1.0.0'
    }
  }
});
example.md
# 当前版本是 {{ $doc.currentVersion || 'v1.0.0' }}