content

使用 content/ 目录为你的应用创建基于文件的内容管理系统 (CMS)。

Nuxt 内容 读取项目中的 content/ 目录 并解析 .md.yml.csv.json 文件,为你的应用创建基于文件的 CMS。

¥Nuxt Content reads the content/ directory in your project and parses .md, .yml, .csv and .json files to create a file-based CMS for your application.

  • 使用内置组件渲染你的内容。
  • 使用类似 MongoDB 的 API 查询你的内容。
  • 使用 MDC 语法在 Markdown 文件中使用你的 Vue 组件。
  • 自动生成导航。

:

Read more in https://content.nuxt.com.

在 Nuxt Content 文档中了解更多信息。

¥Learn more in Nuxt Content documentation.

::

启用 Nuxt 内容

¥Enable Nuxt Content

在你的项目中安装 @nuxt/content 模块,并使用一个命令将其添加到你的 nuxt.config.ts 中:

¥Install the @nuxt/content module in your project as well as adding it to your nuxt.config.ts with one command:

Terminal
npx nuxi module add content

创建内容

¥Create Content

将 Markdown 文件放在 content/ 目录中:

¥Place your markdown files inside the content/ directory:

content/index.md
# Hello Content

模块会自动加载并解析它们。

¥The module automatically loads and parses them.

渲染内容

¥Render Content

要渲染内容页面,请使用 <ContentRenderer> 组件添加 catch-all 路由

¥To render content pages, add a catch-all route using the <ContentRenderer> component:

pages/[...slug].vue
<script lang="ts" setup>
const route = useRoute()
const { data: page } = await useAsyncData(route.path, () => {
  return queryCollection('content').path(route.path).first()
})
</script>

<template>
  <div>
    <header><!-- ... --></header>

    <ContentRenderer v-if="page" :value="page" />

    <footer><!-- ... --></footer>
  </div>
</template>

文档

¥Documentation

前往 https://content.nuxt.com 了解更多关于内容模块功能的信息,例如如何构建查询以及如何使用 MDC 语法在 Markdown 文件中使用 Vue 组件。¥Head over to https://content.nuxt.com to learn more about the Content module features, such as how to build queries and use Vue components in your Markdown files with the MDC syntax.