JSPM

  • Created
  • Published
  • Downloads 5269
  • Score
    100M100P100Q15553F
  • License MIT

Package Exports

  • nuxt-simple-robots

Readme

nuxt-simple-robots

NPM version NPM Downloads GitHub stars

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-Tag header, 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-robots

Setup

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

host

  • Type: string
  • Default: process.env.NUXT_PUBLIC_SITE_URL || nuxt.options.runtimeConfig.public?.siteUrl

Used to ensure sitemaps are absolute URLs.

It's recommended that you use runtime config for this.

export default defineNuxtConfig({
  runtimeConfig: {
    public: {
      // can be set with environment variables
      siteUrl: process.env.NUXT_PUBLIC_SITE_URL || 'https://example.com',
    }
  },
})

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.

export default defineNuxtConfig({
  robots: {
    sitemap: [
      '/sitemap-one.xml',
      '/sitemap-two.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