@@ -15,7 +15,7 @@ import { defu } from 'defu'
15
15
import { installNuxtSiteConfig , updateSiteConfig } from 'nuxt-site-config/kit'
16
16
import { relative } from 'pathe'
17
17
import { readPackageJSON } from 'pkg-types'
18
- import { withTrailingSlash } from 'ufo'
18
+ import { withoutTrailingSlash , withTrailingSlash } from 'ufo'
19
19
import { AiBots , NonHelpfulBots } from './const'
20
20
import { setupDevToolsUI } from './devtools'
21
21
import { resolveI18nConfig , splitPathForI18nLocales } from './i18n'
@@ -375,6 +375,12 @@ export default defineNuxtModule<ModuleOptions>({
375
375
nuxt . options . routeRules = nuxt . options . routeRules || { }
376
376
// convert robot routeRules to header routeRules for static hosting
377
377
if ( config . header ) {
378
+ const noIndexPaths = [ withoutTrailingSlash ( nuxt . options . app . buildAssetsDir ) , `${ nuxt . options . app . buildAssetsDir } **` ]
379
+ for ( const path of noIndexPaths ) {
380
+ nuxt . options . routeRules [ path ] = defu ( {
381
+ robots : 'noindex' ,
382
+ } , nuxt . options . routeRules [ path ] )
383
+ }
378
384
Object . entries ( nuxt . options . routeRules ) . forEach ( ( [ route , rules ] ) => {
379
385
const robotRule = normaliseRobotsRouteRule ( rules )
380
386
// only if a rule has been specified as robots.txt will cover disallows
@@ -415,7 +421,12 @@ export default defineNuxtModule<ModuleOptions>({
415
421
}
416
422
417
423
const groups = config . groups . map ( normalizeGroup )
418
- const pathsToCheck = [ '/_nuxt' , '/_nuxt/' , '/api' , '/api/' ]
424
+ const pathsToCheck = [
425
+ withoutTrailingSlash ( nuxt . options . app . buildAssetsDir ) ,
426
+ nuxt . options . app . buildAssetsDir ,
427
+ '/api' ,
428
+ '/api/' ,
429
+ ]
419
430
for ( const p of pathsToCheck ) {
420
431
if ( groups . some ( g => g . disallow . includes ( p ) ) ) {
421
432
logger . warn ( `You have disallowed robots accessing \`${ withTrailingSlash ( p ) } **\`, this may prevent your site from being indexed correctly.` )
0 commit comments