数据绑定

在 Markdown 中绑定数据

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

YAML frontmatter 中的文档变量

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

# The Title is {{ $doc.title }} and customVariable is {{ $doc.customVariable || 'defaultValue' }}

app.config.ts 中的全局变量

app.config.ts
export default defineAppConfig({
  shadcnDocs: {
    // ...
    data: {
      currentVersion: 'v1.0.0'
    }
  }
});
example.md
# Current Version is {{ $doc.currentVersion || 'v1.0.0' }}