@@ -8,8 +8,9 @@ import { createNitroRouteRuleMatcher } from '../kit'
8
8
import { getSiteRobotConfig } from './getSiteRobotConfig'
9
9
10
10
export function getPathRobotConfig ( e : H3Event , options ?: { userAgent ?: string , skipSiteIndexable ?: boolean , path ?: string } ) : RobotsContext {
11
+ const runtimeConfig = useRuntimeConfig ( e )
11
12
// has already been resolved
12
- const { robotsDisabledValue, robotsEnabledValue, isNuxtContentV2 } = useRuntimeConfig ( ) [ 'nuxt-robots' ]
13
+ const { robotsDisabledValue, robotsEnabledValue, isNuxtContentV2 } = runtimeConfig [ 'nuxt-robots' ]
13
14
if ( ! options ?. skipSiteIndexable ) {
14
15
if ( ! getSiteRobotConfig ( e ) . indexable ) {
15
16
return {
@@ -85,7 +86,16 @@ export function getPathRobotConfig(e: H3Event, options?: { userAgent?: string, s
85
86
86
87
// 3. nitro route rules
87
88
nitroApp . _robotsRuleMactcher = nitroApp . _robotsRuleMactcher || createNitroRouteRuleMatcher ( )
88
- const routeRules = normaliseRobotsRouteRule ( nitroApp . _robotsRuleMactcher ( path ) )
89
+ let routeRulesPath = path
90
+ // if we're using i18n we need to strip leading prefixes so the rule will match
91
+ if ( runtimeConfig . public ?. i18n ?. locales ) {
92
+ const { locales } = runtimeConfig . public . i18n
93
+ const locale = locales . find ( l => routeRulesPath . startsWith ( `/${ l . code } ` ) )
94
+ if ( locale ) {
95
+ routeRulesPath = routeRulesPath . replace ( `/${ locale . code } ` , '' )
96
+ }
97
+ }
98
+ const routeRules = normaliseRobotsRouteRule ( nitroApp . _robotsRuleMactcher ( routeRulesPath ) )
89
99
if ( routeRules && ( typeof routeRules . allow !== 'undefined' || typeof routeRules . rule !== 'undefined' ) ) {
90
100
return {
91
101
indexable : routeRules . allow ,
0 commit comments