Created
January 9, 2012 19:09
-
-
Save wyattdanger/1584407 to your computer and use it in GitHub Desktop.
quick utility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// bring in required modules | |
var fs = require('fs'), | |
util = require('util'), | |
jsdom = require('jsdom'); | |
var output = "", texts; | |
// read sitemap.xml into string | |
fs.readFile('sitemap.xml', 'utf8', function(err, data) { | |
if (err) throw err; | |
// build DOM and bring in jQuery | |
jsdom.env(data, ['http://code.jquery.com/jquery-1.5.min.js'], function(err, window) { | |
if (err) throw err; | |
var $ = window.$; | |
// map over nodes for URLs | |
texts = $.map( $('url loc'), function(val, i) { | |
return $(val).text(); | |
}); | |
// alphabetize | |
texts.sort(); | |
// build up output string | |
texts.forEach(function(text) { | |
output += text + "\n"; | |
}); | |
// write output string to file | |
var fname = util.format("url-list-%s.txt", Date.now()); | |
fs.writeFile(fname, output, 'utf8', function() { | |
console.log(util.format("Wrote %s URLs to %s", texts.length, fname)); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment