Content

Nuxt UI enhances Nuxt Content with beautiful components and styling.

Installation

To get started, you can follow the official guide or in summary:

pnpm add @nuxt/content

Then, add the @nuxt/content module in your nuxt.config.ts:

nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    '@nuxt/ui',
    '@nuxt/content'
  ],
  css: ['~/assets/css/main.css']
})
You need to register @nuxt/content after @nuxt/ui in the modules array, otherwise the prose components will not be available.
If your content includes Tailwind CSS classes, make sure to use the @source directive in your CSS file.

Components

You might be using @nuxt/content to build a documentation. To help you with that, we've built some components that you can use in your pages:

Typography

To make the most out of @nuxt/content, we've revamped our typography system in v3. Instead of using the @tailwindcss/typography plugin like in v1, we now provide custom implementations of all prose components directly within Nuxt UI. This gives us precise control over styling while ensuring perfect visual harmony with our design system.

Learn more about the new Typography system and all the available components.

Utils

mapContentNavigation

This util will map the navigation from queryCollectionNavigation and transform it recursively into an array of objects that can be used by various components.

mapContentNavigation(navigation, options?)

  • navigation: The navigation tree (array of ContentNavigationItem).
  • options (optional):
    • labelAttribute: (string) Which field to use as label (title by default)
    • deep: (number or undefined) Controls how many levels of navigation are included (undefined by default : includes all levels)

Example: As shown in the breadcrumb example below, it's commonly used to transform the navigation data into the correct format.

app.vue
<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>