JSPM

  • Created
  • Published
  • Downloads 1262
  • Score
    100M100P100Q108691F
  • License MIT

Generate a search engine friendly sitemap.xml using a Gulp stream

Package Exports

  • gulp-sitemap

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gulp-sitemap) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

gulp-sitemap

Generate a search engine friendly sitemap.xml using a Gulp stream

NPM version NPM Downloads Build Status

Easily generate a search engine friendly sitemap.xml from your project.

:bowtie: Search engines love the sitemap.xml and it helps SEO as well.

Install

Install with npm

$ npm install --save-dev gulp-sitemap

Example

var gulp = require('gulp');
var sitemap = require('gulp-sitemap');

gulp.task('sitemap', function () {
    gulp.src('build/**/*.html')
        .pipe(sitemap({
            siteUrl: 'http://www.amazon.com'
        }))
        .pipe(gulp.dest('./build'));
});
  • siteUrl is required.
  • index.html will be turned into directory path /.
  • 404.html will be skipped automatically. No need to unglob it.

Let's see an example of how we can create and output a sitemap, and then return to the original stream files:

var gulp = require('gulp');
var sitemap = require('gulp-sitemap');
var save = require('gulp-save');

gulp.task('html', function() {
    gulp.src('*.html')
        .pipe(save('before-sitemap'))
        .pipe(sitemap({
                siteUrl: 'http://www.amazon.com'
        })) // Returns sitemap.xml
        .pipe(gulp.dest('./dist'))
        .pipe(save.restore('before-sitemap')) //restore all files to the state when we cached them
        // -> continue stream with original html files
        // ...
});

Options

siteUrl

required

Your website's base url. This gets prepended to all documents locations.

Type: String

fileName

Determine the output filename for the sitemap.

Type: String

Default: sitemap.xml

changeFreq

Gets filled inside the sitemap in the tag <changefreq>.

Type: String

Default: daily

priority

Gets filled inside the sitemap in the tag <priority>.

Type: String

Default: 0.5

newLine

How to join line in the target sitemap file.

Type: String

Default: Your OS's new line, mostly: \n

spacing

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)

Example usage with default options

var gulp = require('gulp');
var sitemap = require('gulp-sitemap');

gulp.task('sitemap', function () {
    gulp.src('build/**/*.html')
        .pipe(sitemap({
            fileName: 'sitemap.xml',
            newLine: '\n',
            changeFreq: 'daily',
            priority: '0.5',
            siteUrl: '', // no default - this is a required param
            spacing: '    '
        }))
        .pipe(gulp.dest('./build'));
});

Complementary plugins

  • gulp-sitemap-files - Get all files listed in a sitemap (Perhaps one generated from this plugin)

Thanks

To grunt-sitemap for the inspiration on writing this.

License

MIT ©Gilad Peleg