Skip to content

Commit f582941

Browse files
committedAug 21, 2024·
fix: fast path for when group is not indexable
1 parent 0b67224 commit f582941

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed
 

Diff for: ‎src/runtime/nitro/composables/getPathRobotConfig.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { matchPathToRule, normaliseRobotsRouteRule } from '../../util'
77
import { useRuntimeConfig } from '#imports'
88
import { getSiteRobotConfig } from '#internal/nuxt-robots'
99

10-
export function getPathRobotConfig(e: H3Event, options?: { userAgent?: string, skipSiteIndexable?: boolean, path?: string }): { rule: string, indexable: boolean, debug?: { source: string, line: string }} {
10+
export function getPathRobotConfig(e: H3Event, options?: { userAgent?: string, skipSiteIndexable?: boolean, path?: string }): { rule: string, indexable: boolean, debug?: { source: string, line: string } } {
1111
// has already been resolved
1212
const { robotsDisabledValue, robotsEnabledValue, usingNuxtContent } = useRuntimeConfig()['nuxt-robots']
1313
if (!options?.skipSiteIndexable) {
@@ -34,6 +34,16 @@ export function getPathRobotConfig(e: H3Event, options?: { userAgent?: string, s
3434
...nitroApp._robots.ctx.groups.filter(g => g.userAgent.includes('*')),
3535
]
3636
for (const group of groups) {
37+
if (!group._indexable) {
38+
return {
39+
indexable: false,
40+
rule: robotsDisabledValue,
41+
debug: {
42+
source: '/robots.txt',
43+
line: `Disallow: /`,
44+
},
45+
}
46+
}
3747
const robotsTxtRule = matchPathToRule(path, group._rules)
3848
if (robotsTxtRule) {
3949
if (!robotsTxtRule.allow) {
@@ -65,7 +75,7 @@ export function getPathRobotConfig(e: H3Event, options?: { userAgent?: string, s
6575
// 3. nitro route rules
6676
nitroApp._robotsRuleMactcher = nitroApp._robotsRuleMactcher || createNitroRouteRuleMatcher()
6777
const routeRules = normaliseRobotsRouteRule(nitroApp._robotsRuleMactcher(path))
68-
if (routeRules) {
78+
if (routeRules && (routeRules.allow || routeRules.rule)) {
6979
return {
7080
indexable: routeRules.allow,
7181
rule: routeRules.rule || (routeRules.allow ? robotsEnabledValue : robotsDisabledValue),

0 commit comments

Comments
 (0)
Please sign in to comment.