Nuxt Content
Nuxt Sitemap integrates with Nuxt Content out of the box.
It comes with automatic configuration when using document driven mode. Otherwise, you can opt in on each markdown file or set up your own app source.
Setup
Document Driven Mode
When using
export default defineNuxtConfig({
// things just work!
content: {
documentDriven: true
}
})
If you're not using
export default defineNuxtConfig({
sitemap: {
strictNuxtContentPaths: true
}
})
Markdown opt in
If you want to add markdown pages to your sitemap without any extra config, you can use the
---
sitemap:
loc: /my-page
lastmod: 2021-01-01
changefreq: monthly
priority: 0.8
---
# My Page
Nuxt Content App Source
If you'd like to set up a more automated Nuxt Content integration and your not using Document Driven mode, you can add content to the sitemap as you would with Dynamic URLs.
An example of what this might look like is below, customize to your own needs.
import { defineEventHandler } from 'h3'
import type { ParsedContent } from '@nuxt/content/dist/runtime/types'
import { serverQueryContent } from '#content/server'
import { asSitemapUrl, defineSitemapEventHandler } from '#imports'
export default defineSitemapEventHandler(async (e) => {
const contentList = (await serverQueryContent(e).find()) as ParsedContent[]
return contentList
.filter(c => c._path.startsWith('_articles'))
.map((c) => {
return asSitemapUrl({
loc: `/blog/${c._path.replace('_articles', '')}`,
lastmod: updatedAt
})
})
})
export default defineNuxtConfig({
sitemap: {
sources: [
'/api/__sitemap__/urls'
]
}
})
Guides
Opt out from Sitemap
You can also disable the content from being used by passing in