Nuxt Content
Introduction
Nuxt Robots comes with an integration for Nuxt Content that allows you to configure robots straight from your markdown directly.
Setup Nuxt Content v3
In Nuxt Content v3 we need to use the asRobotsCollection()
function to augment any collections
to be able to use the robots
frontmatter key.
import { defineCollection, defineContentConfig } from '@nuxt/content'
import { asRobotsCollection } from '@nuxtjs/robots/content'
export default defineContentConfig({
collections: {
content: defineCollection(
// adds the robots frontmatter key to the collection
asRobotsCollection({
type: 'page',
source: '**/*.md',
}),
),
},
})
To ensure the tags actually gets rendered you need to ensure you're using the useSeoMeta()
composable with seo
.
<script setup lang="ts">
import { queryCollection, useRoute } from '#imports'
const route = useRoute()
const { data: page } = await useAsyncData(`page-${route.path}`, () => {
return queryCollection('content').path(route.path).first()
})
// Ensure the SEO meta tags are rendered
useSeoMeta(page.value?.seo || {})
</script>
Due to current Nuxt Content v3 limitations, you must load the robots module before the content module.
export default defineNuxtConfig({
modules: [
'@nuxtjs/robots',
'@nuxt/content' // <-- Must be after @nuxtjs/robots
]
})
Setup Nuxt Content v2
In Nuxt Content v2 markdown files require either Document Driven Mode or a path
key to be set
in the frontmatter.
---
path: /foo
---
Usage
You can use any boolean or string value as robots
that will be forwarded as a
Meta Robots Tag.
robots: false
<meta name="robots" content="noindex, nofollow">
Disabling Nuxt Content Integration
If you need to disable the Nuxt Content integration, you can do so by setting the disableNuxtContentIntegration
option in the module configuration.
export default defineNuxtConfig({
robots: {
disableNuxtContentIntegration: true,
}
})