要开始使用,您可以遵循官方指南或简要概述
pnpm add @nuxt/content
yarn add @nuxt/content
npm install @nuxt/content
bun add @nuxt/content
然后,在您的 nuxt.config.ts 中添加 @nuxt/content 模块
export default defineNuxtConfig({
modules: [
'@nuxt/ui',
'@nuxt/content'
],
css: ['~/assets/css/main.css']
})
@nuxt/content 注册在 modules 数组中的 @nuxt/ui 之后,否则散文组件将不可用。在您的 markdown 内容文件中使用 Tailwind CSS 类时,您需要确保 Tailwind 能够检测并生成必要的实用程序类。默认情况下,Tailwind 的自动内容检测可能无法识别 markdown 文件中编写的类。
要解决此问题,请使用@source 指令在您的 CSS 文件中明确包含您的内容目录
@import "tailwindcss";
@import "@nuxt/ui";
@source "../../../content/**/*";
这确保了
text-primary)都包含在最终的 CSS 中@source "../../../content/docs/**/*.md" - 只扫描 docs 文件夹中的 markdown@source "../../../content/**/*.{md,yml}" - 同时包含 markdown 和 YAML 文件您可能正在使用 @nuxt/content 构建文档。为了帮助您,我们构建了一些您可以在页面中使用的组件
Nuxt UI 提供了所有散文组件的自定义实现,以便与 @nuxt/content 无缝集成。这种方法确保了样式一致性、对排版的完全控制,并与 Nuxt UI 设计系统完美对齐,因此您的内容开箱即用,始终看起来和感觉都具有凝聚力。
mapContentNavigation此工具将映射来自 queryCollectionNavigation 的导航,并将其递归转换为一个对象数组,可供各种组件使用。
mapContentNavigation(navigation, options?)
navigation: 导航树 (ContentNavigationItem 数组)。options (可选)labelAttribute: (字符串) 用作标签的字段(默认为 title)deep: (数字或 undefined) 控制包含多少层导航(默认为 undefined:包含所有级别)示例: 如下面的面包屑示例所示,它通常用于将导航数据转换为正确的格式。
<script setup lang="ts">
import { mapContentNavigation } from '@nuxt/ui/utils/content'
import { findPageBreadcrumb } from '@nuxt/content/utils'
const { data: navigation } = await useAsyncData('navigation', () => queryCollectionNavigation('content'))
const breadcrumb = computed(() => mapContentNavigation(findPageBreadcrumb(navigation?.value, page.value?.path, { indexAsChild: true })).map(({ icon, ...link }) => link), { deep: 0 })
</script>
<template>
<UPage>
<UPageHeader v-bind="page">
<template #headline>
<UBreadcrumb :items="breadcrumb" />
</template>
</UPageHeader>
</UPage>
</template>