Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix!: deprecate disallowNonIndexableRoutes #173

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions docs/content/3.api/1.config.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ The value to use when the page is indexable.

The value to use when the page is not indexable.

## `disallowNonIndexableRoutes: boolean`{lang="ts"}

- Default: `'false'`{lang="ts"}

Should route rules which disallow indexing be added to the `/robots.txt` file.

## `mergeWithRobotsTxtPath: boolean | string`{lang="ts"}

- Default: `true`{lang="ts"}
Expand Down Expand Up @@ -167,3 +161,11 @@ export default defineNuxtConfig({
}
})
```

## `disallowNonIndexableRoutes: boolean`{lang="ts"}

**⚠️ Deprecated**: Explicitly disallow routes in the `/robots.txt` file if you don't want them to be accessible.

- Default: `'false'`{lang="ts"}

Should route rules which disallow indexing be added to the `/robots.txt` file.
6 changes: 4 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ export interface ModuleOptions {
*/
robotsDisabledValue: string
/**
* @deprecated Explicitly add paths to your robots.txt with the `allow` and `disallow` options.
*
* Should route rules which disallow indexing be added to the `/robots.txt` file.
*
* @default true
* @default false
*/
disallowNonIndexableRoutes: boolean
/**
Expand Down Expand Up @@ -191,7 +193,7 @@ export default defineNuxtModule<ModuleOptions>({
cacheControl: 'max-age=14400, must-revalidate',
robotsEnabledValue: 'index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1',
robotsDisabledValue: 'noindex, nofollow',
disallowNonIndexableRoutes: true,
disallowNonIndexableRoutes: false,
robotsTxt: true,
},
async setup(config, nuxt) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/composables/getPathRobotConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function getPathRobotConfig(e: H3Event, options?: { userAgent?: string, s
// 3. nitro route rules
nitroApp._robotsRuleMactcher = nitroApp._robotsRuleMactcher || createNitroRouteRuleMatcher()
const routeRules = normaliseRobotsRouteRule(nitroApp._robotsRuleMactcher(path))
if (routeRules && (routeRules.allow || routeRules.rule)) {
if (routeRules && (typeof routeRules.allow !== 'undefined' || typeof routeRules.rule !== 'undefined')) {
return {
indexable: routeRules.allow,
rule: routeRules.rule || (routeRules.allow ? robotsEnabledValue : robotsDisabledValue),
Expand Down
2 changes: 0 additions & 2 deletions test/default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ describe('default', () => {
Disallow: /users/*/hidden
Disallow: /?a=
Disallow: /visible?*a=
Disallow: /*/account
Disallow: /sub/*

Sitemap: https://nuxtseo.com/sitemap.xml
# END nuxt-robots"
Expand Down
2 changes: 0 additions & 2 deletions test/groups.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ describe('stack', () => {
Disallow: /users/*/hidden
Disallow: /?a=
Disallow: /visible?*a=
Disallow: /*/account
Disallow: /sub/*

Sitemap: https://nuxtseo.com/sitemap.xml
# END nuxt-robots"
Expand Down
2 changes: 0 additions & 2 deletions test/mergeWithRobotsTxtPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ describe('mergeWithRobotsTxtPath', () => {
Allow: /secret/exception
Disallow: /secret
Disallow: /admin
Disallow: /*/account
Disallow: /sub/*

Sitemap: https://nuxtseo.com/sitemap.xml
# END nuxt-robots"
Expand Down
Loading