gulp-sitemap
Generate a search engine friendly sitemap.xml using a Gulp stream
Easily generate a search engine friendly sitemap.xml from your project.
Search engines love the sitemap.xml and it helps SEO as well.
Install with npm
$ npm install --save-dev gulp-sitemap
var gulp = require('gulp');
var sitemap = require('gulp-sitemap');
gulp.task('sitemap', function () {
gulp.src('build/**/*.html', {
read: false
}).pipe(sitemap({
siteUrl: 'http://www.amazon.com'
}))
.pipe(gulp.dest('build/'));
});
- File content isn't necessary when reading files. To speed up building use
{read:false}
withgulp.src
. - index.html will be turned into directory path
/
. - 404.html will be skipped automatically. No need to unglob it.
required
Your website's base url. This gets prepended to all documents locations.
Type: String
Determine the output filename for the sitemap.
Type: String
Default: sitemap.xml
Gets filled inside the sitemap in the tag <changefreq>
.
Type: String
Default: daily
Gets filled inside the sitemap in the tag <priority>
.
Type: String
Default: 0.5
How to join line in the target sitemap file.
Type: String
Default: Your OS's new line, mostly: \n
How should the sitemap xml file be spaced. You can use \t
for tabs, or
with 2
spaces if you'd like.
Type: String
Default:
(4 spaces)
Strip the extension of the files being processed. /some-page.html
becomes /some-page
Type: Boolean
Default: false
var gulp = require('gulp');
var sitemap = require('gulp-sitemap');
gulp.task('sitemap', function () {
gulp.src('build/**/*.html', {
read: false
}).pipe(sitemap({
fileName: 'sitemap.xml',
newLine: '\n',
changeFreq: 'daily',
priority: '0.5',
siteUrl: '', // no default - this is a required param
spacing: ' ',
stripExtensions: false
}))
.pipe(gulp.dest('build/'));
});
To grunt-sitemap for the inspiration on writing this.
MIT ©2014 Gilad Peleg