Skip to content

Commit 78979f8

Browse files
committedOct 29, 2024
fix: disable nuxt content integration for v3 and cloudflare
Fixes harlan-zw/nuxt-seo#344
1 parent 52e42df commit 78979f8

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed
 

‎client/composables/shiki.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { MaybeRef } from '@vueuse/core'
2-
import type { Highlighter, BundledLanguage } from 'shiki'
2+
import type { BundledLanguage, Highlighter } from 'shiki'
33
import { createHighlighter } from 'shiki'
44
import { computed, ref, toValue } from 'vue'
55
import { devtools } from './rpc'

‎src/module.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
createResolver,
1111
defineNuxtModule,
1212
hasNuxtModule,
13+
hasNuxtModuleCompatibility,
1314
} from '@nuxt/kit'
1415
import { defu } from 'defu'
1516
import { installNuxtSiteConfig, updateSiteConfig } from 'nuxt-site-config-kit'
@@ -127,6 +128,10 @@ export interface ModuleOptions {
127128
* @default max-age=14400, must-revalidate
128129
*/
129130
cacheControl?: string | false
131+
/**
132+
* Disabled the Frontmatter Nuxt Content integration.
133+
*/
134+
disableNuxtContentIntegration?: boolean
130135
/**
131136
* Whether the robots.txt file should be generated. Useful to disable when running your app with a base URL.
132137
*
@@ -353,6 +358,19 @@ export default defineNuxtModule<ModuleOptions>({
353358
}
354359
}
355360

361+
const nitroPreset = resolveNitroPreset(nuxt.options.nitro)
362+
let usingNuxtContent = hasNuxtModule('@nuxt/content') && config.disableNuxtContentIntegration !== false
363+
if (usingNuxtContent) {
364+
if (await hasNuxtModuleCompatibility('@nuxt/content', '^3')) {
365+
logger.warn('Nuxt Robots does not work with Nuxt Content v3 yet, the integration will be disabled. Learn more at: https://nuxtseo.com/docs/robots/guides/content')
366+
usingNuxtContent = false
367+
}
368+
else if (nitroPreset.startsWith('cloudflare')) {
369+
logger.warn('The Nuxt Robots, Nuxt Content integration does not work with CloudFlare yet, the integration will be disabled. Learn more at: https://nuxtseo.com/docs/robots/guides/content')
370+
usingNuxtContent = false
371+
}
372+
}
373+
356374
nuxt.hook('modules:done', async () => {
357375
config.sitemap = asArray(config.sitemap)
358376
config.disallow = asArray(config.disallow)
@@ -428,7 +446,7 @@ export default defineNuxtModule<ModuleOptions>({
428446

429447
nuxt.options.runtimeConfig['nuxt-robots'] = {
430448
version: version || '',
431-
usingNuxtContent: hasNuxtModule('@nuxt/content'),
449+
usingNuxtContent,
432450
debug: config.debug,
433451
credits: config.credits,
434452
groups: config.groups,
@@ -449,7 +467,7 @@ declare module 'nitropack' {
449467
interface NitroApp {
450468
_robots: {
451469
ctx: import('${typesPath}').HookRobotsConfigContext
452-
nuxtContentUrls: Set<string>
470+
nuxtContentUrls?: Set<string>
453471
},
454472
_robotsRuleMactcher: (url: string) => string
455473
}
@@ -489,7 +507,6 @@ declare module 'h3' {
489507
`
490508
})
491509

492-
const nitroPreset = resolveNitroPreset(nuxt.options.nitro)
493510
// only prerender for `nuxi generate`
494511
const isFirebase = nitroPreset === 'firebase'
495512
if ((isNuxtGenerate() || (isFirebase && nuxt.options._build)) && config.robotsTxt) {
@@ -531,7 +548,7 @@ declare module 'h3' {
531548
})
532549
addServerPlugin(resolve('./runtime/nitro/plugins/initContext'))
533550

534-
if (hasNuxtModule('@nuxt/content')) {
551+
if (usingNuxtContent) {
535552
addServerHandler({
536553
route: '/__robots__/nuxt-content.json',
537554
handler: resolve('./runtime/nitro/server/__robots__/nuxt-content'),

‎src/runtime/nitro/plugins/initContext.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export default defineNitroPlugin(async (nitroApp: NitroApp) => {
2626
urls.forEach((url: string) => nuxtContentUrls.add(withoutTrailingSlash(url)))
2727
}
2828
}
29-
nitroApp._robots.nuxtContentUrls = nuxtContentUrls
29+
if (nuxtContentUrls.size) {
30+
nitroApp._robots.nuxtContentUrls = nuxtContentUrls
31+
}
3032

3133
if (import.meta.prerender) {
3234
// need to inject HTML if we have an SPA route

0 commit comments

Comments
 (0)
Please sign in to comment.