From 3af10fef075146638cdfe2d5dbedc4163cc6588b Mon Sep 17 00:00:00 2001 From: harlan Date: Wed, 18 Dec 2024 01:35:42 +1100 Subject: [PATCH 1/2] feat: set `noindex` header for build asset dir `/_nuxt` --- src/module.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/module.ts b/src/module.ts index f5d8f32d..3ed29896 100644 --- a/src/module.ts +++ b/src/module.ts @@ -15,7 +15,7 @@ import { defu } from 'defu' import { installNuxtSiteConfig, updateSiteConfig } from 'nuxt-site-config/kit' import { relative } from 'pathe' import { readPackageJSON } from 'pkg-types' -import { withTrailingSlash } from 'ufo' +import { withoutTrailingSlash, withTrailingSlash } from 'ufo' import { AiBots, NonHelpfulBots } from './const' import { setupDevToolsUI } from './devtools' import { resolveI18nConfig, splitPathForI18nLocales } from './i18n' @@ -373,6 +373,12 @@ export default defineNuxtModule({ nuxt.options.routeRules = nuxt.options.routeRules || {} // convert robot routeRules to header routeRules for static hosting if (config.header) { + const noIndexPaths = [withoutTrailingSlash(nuxt.options.app.buildAssetsDir), `${nuxt.options.app.buildAssetsDir}**`] + for (const path of noIndexPaths) { + nuxt.options.routeRules[path] = defu({ + robots: 'noindex', + }, nuxt.options.routeRules[path]) + } Object.entries(nuxt.options.routeRules).forEach(([route, rules]) => { const robotRule = normaliseRobotsRouteRule(rules) // only if a rule has been specified as robots.txt will cover disallows @@ -413,7 +419,12 @@ export default defineNuxtModule({ } const groups = config.groups.map(normalizeGroup) - const pathsToCheck = ['/_nuxt', '/_nuxt/', '/api', '/api/'] + const pathsToCheck = [ + withoutTrailingSlash(nuxt.options.app.buildAssetsDir), + nuxt.options.app.buildAssetsDir, + '/api', + '/api/', + ] for (const p of pathsToCheck) { if (groups.some(g => g.disallow.includes(p))) { logger.warn(`You have disallowed robots accessing \`${withTrailingSlash(p)}**\`, this may prevent your site from being indexed correctly.`) From 3bab1a9e95469ac0df95a0abc0689a69a6d1e46c Mon Sep 17 00:00:00 2001 From: harlan Date: Wed, 18 Dec 2024 02:53:56 +1100 Subject: [PATCH 2/2] chore: bump snapshot --- test/routeRules.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/routeRules.test.ts b/test/routeRules.test.ts index eb6c699d..75f4f3f6 100644 --- a/test/routeRules.test.ts +++ b/test/routeRules.test.ts @@ -55,6 +55,8 @@ describe('route rule merging', () => { Disallow: /robots-rule/* Disallow: /secret/* Disallow: /excluded/* + Disallow: /_nuxt + Disallow: /_nuxt/* Sitemap: https://nuxtseo.com/sitemap.xml # END nuxt-robots"