-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
25 lines (21 loc) · 791 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
( function() {
'use strict';
var xmlParser = require( 'xml-parser' );
var fs = require( 'fs' );
var request = require( 'sync-request' );
var getSitemapUrls = function( sitemapUrl, options ) {
if ( sitemapUrl.match( /^https?\:\/\// ) ) {
var res = request( 'GET', sitemapUrl );
var sitemap = xmlParser( res.getBody().toString() );
var urls = sitemap.root.children.map( function( url ) {
var loc = url.children.filter( function( item ) {
return item.name === 'loc';
} )[ 0 ];
return loc.content;
} );
return urls;
}
throw new Error( 'Please specify a valid URL' );
};
module.exports = getSitemapUrls;
} () );