lib/sitemap.js
function buildSitemapIndex (conf) {
  var xml = [];
  var lastmod;

  xml.push('<?xml version="1.0" encoding="UTF-8"?>');
  if (conf.xslUrl) {
    xml.push('<?xml-stylesheet type="text/xsl" href="' + conf.xslUrl + '"?>');
  }
  if (!conf.xmlNs) {
    xml.push('<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" ' +
      'xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" ' +
      'xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" ' +
      'xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">');
  } else {
    xml.push('<sitemapindex ' + conf.xmlNs + '>')
  }

  if (conf.lastmodISO) {
    lastmod = conf.lastmodISO;
  } else if (conf.lastmodrealtime) {
    lastmod = new Date().toISOString();
  } else if (conf.lastmod) {
    lastmod = new Date(conf.lastmod).toISOString();
  }


  conf.urls.forEach(url => {
    if (url instanceof Object) {
      lastmod = url.lastmod ? url.lastmod : lastmod;

      url = url.url;
    }
    xml.push('<sitemap>');
    xml.push('<loc>' + url + '</loc>');
    if (lastmod) {
      xml.push('<lastmod>' + lastmod + '</lastmod>');
    }
    xml.push('</sitemap>');
  });

  xml.push('</sitemapindex>');

  return xml.join('\n');
}
function buildSitemapIndex (conf) {
  var xml = [];
  var lastmod;

  xml.push('<?xml version="1.0" encoding="UTF-8"?>');
  if (conf.xslUrl) {
    xml.push('<?xml-stylesheet type="text/xsl" href="' + conf.xslUrl + '"?>');
  }
  if (!conf.xmlNs) {
    xml.push('<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" ' +
      'xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" ' +
      'xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" ' +
      'xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">');
  } else {
    xml.push('<sitemapindex ' + conf.xmlNs + '>')
  }

  if (conf.lastmodISO) {
    lastmod = conf.lastmodISO;
  } else if (conf.lastmodrealtime) {
    lastmod = new Date().toISOString();
  } else if (conf.lastmod) {
    lastmod = new Date(conf.lastmod).toISOString();
  }


  conf.urls.forEach(url => {
    if (url instanceof Object) {
      lastmod = url.lastmod ? url.lastmod : lastmod;

      url = url.url;
    }
    xml.push('<sitemap>');
    xml.push('<loc>' + url + '</loc>');
    if (lastmod) {
      xml.push('<lastmod>' + lastmod + '</lastmod>');
    }
    xml.push('</sitemap>');
  });

  xml.push('</sitemapindex>');

  return xml.join('\n');
}
function buildSitemapIndex ( conf ) { var xml = [ ] ; var lastmod ; xml . push ( '<?xml version="1.0" encoding="UTF-8"?>' ) ; if ( conf . xslUrl ) { xml . push ( '<?xml-stylesheet type="text/xsl" href="' + conf . xslUrl + '"?>' ) ; } if ( ! conf . xmlNs ) { xml . push ( '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" ' + 'xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" ' + 'xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" ' + 'xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">' ) ; } else { xml . push ( '<sitemapindex ' + conf . xmlNs + '>' ) } if ( conf . lastmodISO ) { lastmod = conf . lastmodISO ; } else if ( conf . lastmodrealtime ) { lastmod = new Date ( ) . toISOString ( ) ; } else if ( conf . lastmod ) { lastmod = new Date ( conf . lastmod ) . toISOString ( ) ; } conf . urls . forEach ( url => { if ( url instanceof Object ) { lastmod = url . lastmod ? url . lastmod : lastmod ; url = url . url ; } xml . push ( '<sitemap>' ) ; xml . push ( '<loc>' + url + '</loc>' ) ; if ( lastmod ) { xml . push ( '<lastmod>' + lastmod + '</lastmod>' ) ; } xml . push ( '</sitemap>' ) ; } ) ; xml . push ( '</sitemapindex>' ) ; return xml . join ( '\n' ) ; }
Builds a sitemap index from urls

@param   {Object}    conf
@param   {Array}     conf.urls
@param   {String}    conf.xslUrl
@param   {String}    conf.xmlNs
@return  {String}    XML String of SitemapIndex
Builds a sitemap index from urls