Nuxt Module that generate sitemap, robot.txt and many things like that
Install it via NPM:
npm i nuxt-seo-module
or via yarn:
yarn add nuxt-seo-module
Add it to your nuxt.config.js
file.
/** ... **/
modules: [
/* ... */
'nuxt-seo-module'
]
/** ... **/
It will create a robots.txt
file and a sitemap.xml with all of your pages
nuxt-seo-module is composed of 2 modules, the robots and the sitemap one. You can configure them individually :
/** ... **/
modules: [
/* ... */
['nuxt-seo-module', {
robots: {
// ROBOTS.TXT options
},
sitemap: [
// sitemaps options is an array of object
]
}]
]
/** ... **/
modules: [
/* ... */
['nuxt-seo-module', {
robots: {
UserAgent: '',
CrawlDelay: '',
Disallow: '',
Allow: '',
Sitemap: ''
}
}]
Each parameters can be a string or an array.
If you add a sitemap entry in your robots.txt, generated sitemap will not be added to the robots.txt file.
A complete example of sitemap options:
modules: [
/* ... */
['nuxt-seo-module', {
sitemap: [{
path: 'sitemap.xml',
hostname: null,
generate: true,
exclude: [],
routes: [
{
url: '/page/2',
changefreq: 'daily',
priority: 1,
lastmodISO: '2017-06-30T13:30:00.000Z'
},
{
url: '/page/1',
changefreq: 'daily',
priority: 0.3,
lastmodISO: '2017-06-30T13:30:00.000Z',
links: [
{ lang: 'en', url: 'http://test.com/page-1/', },
{ lang: 'fr', url: 'http://test.com/page-1/fr/', },
androidLink: 'android-app://com.company.test/page-1/'
]
}
],
cacheTime: 1000 * 60 * 15
}, {
path: 'sitemap-news.xml',
hostname: 'my-url.com',
generate: false,
routes: getNews().map(news => {
return {
url: imgPath,
img: news.imgs.map(img => {
return {
url: 'http://test.com/img1.jpg',
caption: 'An image',
title: 'The Title of Image One',
geoLocation: 'London, United Kingdom',
license: 'https://creativecommons.org/licenses/by/4.0/'
},
}),
video: news.videos.map(video => {
return {
thumbnail_loc: 'http://test.com/tmbn1.jpg',
title: 'A video title',
description: 'This is a video'
};
})
};
})
}]
}]
You can also use env variable in nuxt.config.js
:
/** ... **/
modules: [
/* ... */
['nuxt-seo-module'],
],
env: {
robots: {},
sitemap: [{
generate: true
}]
}
/** ... **/