npm.io
1.0.2 • Published 4 years ago

@fengsi/nuxt-robots

Licence
MIT
Version
1.0.2
Deps
1
Size
7 kB
Vulns
0
Weekly
0
Stars
1

@fengsi/nuxt-robots

Setup

  1. Add @fengsi/nuxt-robots dependency to your project
yarn add @fengsi/nuxt-robots # or npm install @fengsi/nuxt-robots
  1. Add @fengsi/nuxt-robots to the modules section of nuxt.config.js
export default {
  modules: [
    // Simple usage
    '@fengsi/nuxt-robots',

    // With options
    ['@fengsi/nuxt-robots', { 
      /* module options */
      cacheTime: 1000 * 60 * 10,
      robots: () => {
        return []
      }
    }]
  ]
}

Using top level options

export default {
  modules: [
    '@fengsi/nuxt-robots'
  ],
  robots: {
    /* module options */
    cacheTime: 1000 * 60 * 10,
    robots: () => {
      return []
    }
  }
}
cache time

default 1000 * 60 * 10 s

Options

The module option parameter can be:

Object
export default {
  robots: {
    cacheTime: 1000 * 60 * 10,
    robots: {
      UserAgent: '*',
      Disallow: '/'
    }
  }
}
Array
export default {
  robots: {
    cacheTime: 1000 * 60 * 10,
    robots: [
      {
        UserAgent: 'Googlebot',
        Disallow: () => '/users' // accepts function
      }
    ]
  }
}
Function
export default {
  robots: {
    cacheTime: 1000 * 60 * 10,
    robots: () => {
      return {
        UserAgent: '*',
        Disallow: '/'
      }
    }
  }
}
null

status code: 404

export default {
  robots: {
    cacheTime: 1000 * 60 * 10,
    robots: null
  }
}
Will generate a /robots.txt
User-agent: Googlebot
Disallow: /users
User-agent: Bingbot
Disallow: /admin
The keys and values available:
  • UserAgent = User-agent
  • CrawlDelay = Crawl-delay
  • Disallow = Disallow
  • Allow = Allow
  • Host = Host
  • Sitemap = Sitemap
  • CleanParam = Clean-param

Note: Don't worry keys are parsed with case insensitive and special characters.

The original link @nuxtjs/robots