Lastmod, Priority, and Changefreq
Introduction
Changing the <loc>
entry data can be useful for a variety of reasons, such as changing the changefreq
, priority
, or lastmod
values.
If you're using Dynamic URLs, you can modify the data in the sitemap
object, otherwise, you will
need to override the app sources directly.
While modifying these in most cases may be unnecessary, see Best Practices, it can be useful when used right.
Setting Defaults
While this is not recommended, in special circumstances you may wish to set defaults for your sitemap entries:
export default defineNuxtConfig({
sitemap: {
defaults: {
lastmod: new Date().toISOString(),
priority: 0.5,
changefreq: 'weekly'
}
}
})
Data Source Merging
You can provide the page you want to set the lastmod
, priority
, or changefreq
for in your app sources, which includes
the urls
config.
export default defineNuxtConfig({
sitemap: {
urls: [
{
loc: '/about',
lastmod: '2023-01-01',
priority: 0.3,
changefreq: 'daily'
}
]
}
})
Modify Loc Data With Route Rules
To change the behaviour of your sitemap URLs, you can use Route rules.
export default defineNuxtConfig({
routeRules: {
// Don't add any /secret/** URLs to the sitemap.xml
'/secret/**': { robots: false },
// modify the sitemap.xml entry for specific URLs
'/about': { sitemap: { changefreq: 'daily', priority: 0.3 } }
}
})
Alternatively, you can use the experimental macro defineRouteRules
, which must
be enabled.
<script setup>
defineRouteRules({
sitemap: {
changefreq: 'daily',
priority: 0.3
}
})
</script>
Lastmod: Prerendering Hints
When prerendering your site, you can make use of setting the article:modified_time
meta tag in your page's head. This
meta tag will be used as the lastmod
value in your sitemap.
<script setup>
useSeoMeta({
// will be inferred as the lastmod value in the sitemap
articleModifiedTime: '2023-01-01'
})
</script>