Package Exports
- nuxt-simple-robots
Readme
nuxt-simple-robots
Simply manage the robots crawling your Nuxt 3 app.
|
Status: Stable Please report any issues đ Made possible by my Sponsor Program đ Follow me @harlan_zw đĻ âĸ Join Discord for help |
âšī¸ Looking for a complete SEO solution? Check out Nuxt SEO Kit.
Features
- đ¤ Creates best practice robot data
- đŋ Adds
X-Robots-Tagheader, robot meta tag and robots.txt - đ Configure using route rules
- đ Disables non-production environments from being crawled automatically
- Best practice default config
Install
npm install --save-dev nuxt-simple-robots
# Using yarn
yarn add --dev nuxt-simple-robotsSetup
nuxt.config.ts
export default defineNuxtConfig({
modules: [
'nuxt-simple-robots',
],
})Configure route indexing
Using route rules, you can configure how your routes are indexed by search engines.
export default defineNuxtConfig({
routeRules: {
// use the `index` shortcut for simple rules
'/secret/**': { index: false },
// add exceptions for individual routes
'/secret/visible': { index: true },
// use the `robots` rule if you need finer control
'/custom-robots': { robots: 'index, follow' },
}
})Injecting Meta Tags (optional)
By default, only the robots.txt and HTTP headers will be used to control indexing. If you want to add a meta tag to your page as well, you can use the composable or the component provided.
This shouldn't be necessary, but it's useful if you want to be extra sure that your page is not indexed and can make debugging easier.
Within your app.vue or a layout:
<script lang="ts" setup>
// Use Composition API
defineRobotMeta()
</script>
<template>
<div>
<!-- OR Component API -->
<RobotMeta />
</div>
</template>Module Config
indexable
- Type:
boolean - Default:
process.env.NUXT_INDEXABLE || nuxt.options.runtimeConfig.indexable || process.env.NODE_ENV === 'production'
Whether the site is indexable by search engines.
disallow
- Type:
string[] - Default:
[] - Required:
false
Disallow paths from being crawled.
sitemap
- Type:
string | string[] | false - Default:
false
The sitemap URL(s) for the site. If you have multiple sitemaps, you can provide an array of URLs.
You must either define the runtime config siteUrl or provide the sitemap as absolute URLs.
// option 1. provide runtime config for site url
export default defineNuxtConfig({
runtimeConfig: {
siteUrl: process.env.NUXT_PUBLIC_SITE_URL || 'https://example.com',
},
robots: {
sitemap: '/sitemap.xml',
},
})// option 2. provide absolute URLs
export default defineNuxtConfig({
robots: {
sitemap: [
'https://example.com/sitemap.xml',
],
},
})robotsEnabledValue
- Type:
string - Default:
'index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' - Required:
false
The value to use when the site is indexable.
robotsDisabledValue
- Type:
string - Default:
'noindex, nofollow' - Required:
false
The value to use when the site is not indexable.
Sponsors
License
MIT License Š 2022-PRESENT Harlan Wilton