Skip to content

Commit 5b6483b

Browse files
committedJan 20, 2025·
fix(content): warn when module is loaded after Content v3
1 parent 632cb64 commit 5b6483b

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed
 

‎docs/content/2.guides/5.content.md

+11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ export default defineContentConfig({
2929
})
3030
```
3131

32+
Due to current Nuxt Content v3 limitations, you must load the sitemap module before the content module.
33+
34+
```ts
35+
export default defineNuxtConfig({
36+
modules: [
37+
'@nuxtjs/sitemap',
38+
'@nuxt/content' // <-- Must be after @nuxtjs/sitemap
39+
]
40+
})
41+
```
42+
3243

3344
## Setup Nuxt Content v2
3445

‎src/module.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ declare module 'vue-router' {
360360
const nuxtV3Collections = new Set<string>()
361361
const isNuxtContentV2 = usingNuxtContent && await hasNuxtModuleCompatibility('@nuxt/content', '^2')
362362
if (isNuxtContentV3) {
363+
// check if content was loaded first
364+
if (nuxt.options._installedModules.some(m => m.meta.name === 'Content')) {
365+
logger.warn('You have loaded `@nuxt/content` before `@nuxtjs/sitemap`, this may cause issues with the integration. Please ensure `@nuxtjs/sitemap` is loaded first.')
366+
}
363367
// TODO this is a hack until content gives us an alias
364368
nuxt.options.alias['#sitemap/content-v3-nitro-path'] = resolve(dirname(resolveModule('@nuxt/content')), 'runtime/nitro')
365369
// @ts-expect-error runtime type
@@ -388,7 +392,6 @@ declare module 'vue-router' {
388392
}
389393
// Note: videos only supported through prerendering for simpler logic
390394

391-
const sitemapConfig = typeof content.sitemap === 'object' ? content.sitemap : {}
392395
const lastmod = content.seo?.articleModifiedTime || content.updatedAt
393396
const defaults: Partial<SitemapUrl> = {
394397
loc: content.path,
@@ -397,8 +400,7 @@ declare module 'vue-router' {
397400
defaults.images = images
398401
if (lastmod)
399402
defaults.lastmod = lastmod
400-
content.sitemap = defu(sitemapConfig, defaults) as Partial<SitemapUrl>
401-
ctx.content = content
403+
ctx.content.sitemap = defu(typeof content.sitemap === 'object' ? content.sitemap : {}, defaults) as Partial<SitemapUrl>
402404
})
403405

404406
addServerHandler({

‎test/fixtures/content-v3/nuxt.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import NuxtRobots from '../../../src/module'
22

33
export default defineNuxtConfig({
44
modules: [
5-
NuxtRobots,
65
'@nuxt/content',
6+
NuxtRobots,
77
],
88

99
site: {

0 commit comments

Comments
 (0)
Please sign in to comment.