@@ -29,6 +29,12 @@ export interface ModuleOptions {
29
29
* @default true
30
30
*/
31
31
enabled : boolean
32
+ /**
33
+ * Should a `X-Robots-Tag` header be added to the response.
34
+ *
35
+ * @default true
36
+ */
37
+ header : boolean
32
38
/**
33
39
* Should a `<meta name="robots" content="<>">` tag be added to the head.
34
40
*
@@ -161,6 +167,7 @@ export default defineNuxtModule<ModuleOptions>({
161
167
groups : [ ] ,
162
168
blockNonSeoBots : false ,
163
169
mergeWithRobotsTxtPath : true ,
170
+ header : true ,
164
171
metaTag : true ,
165
172
cacheControl : 'max-age=14400, must-revalidate' ,
166
173
robotsEnabledValue : 'index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' ,
@@ -362,18 +369,20 @@ export default defineNuxtModule<ModuleOptions>({
362
369
363
370
nuxt . options . routeRules = nuxt . options . routeRules || { }
364
371
// convert robot routeRules to header routeRules for static hosting
365
- Object . entries ( nuxt . options . routeRules ) . forEach ( ( [ route , rules ] ) => {
366
- const url = route . split ( '/' ) . map ( segment => segment . startsWith ( ':' ) ? '*' : segment ) . join ( '/' )
367
- const groupIndexable = indexableFromGroup ( config . groups , url )
368
- const robotRules = normaliseRobotsRouteRule ( rules , groupIndexable , config . robotsDisabledValue , config . robotsEnabledValue )
369
- // single * is supported but ignored
370
- // @ts -expect-error untyped
371
- nuxt . options . routeRules [ route ] = defu ( {
372
- headers : {
373
- 'X-Robots-Tag' : robotRules . rule ,
374
- } ,
375
- } , nuxt . options . routeRules ?. [ route ] )
376
- } )
372
+ if ( config . header ) {
373
+ Object . entries ( nuxt . options . routeRules ) . forEach ( ( [ route , rules ] ) => {
374
+ const url = route . split ( '/' ) . map ( segment => segment . startsWith ( ':' ) ? '*' : segment ) . join ( '/' )
375
+ const groupIndexable = indexableFromGroup ( config . groups , url )
376
+ const robotRules = normaliseRobotsRouteRule ( rules , groupIndexable , config . robotsDisabledValue , config . robotsEnabledValue )
377
+ // single * is supported but ignored
378
+ // @ts -expect-error untyped
379
+ nuxt . options . routeRules [ route ] = defu ( {
380
+ headers : {
381
+ 'X-Robots-Tag' : robotRules . rule ,
382
+ } ,
383
+ } , nuxt . options . routeRules ?. [ route ] )
384
+ } )
385
+ }
377
386
378
387
const extraDisallows = new Set < string > ( )
379
388
if ( config . disallowNonIndexableRoutes ) {
@@ -408,6 +417,7 @@ export default defineNuxtModule<ModuleOptions>({
408
417
credits : config . credits ,
409
418
groups : config . groups ,
410
419
sitemap : config . sitemap ,
420
+ header : config . header ,
411
421
robotsEnabledValue : config . robotsEnabledValue ,
412
422
robotsDisabledValue : config . robotsDisabledValue ,
413
423
// @ts -expect-error untyped
0 commit comments