Created
May 9, 2012 02:25
-
-
Save matthewmueller/2641307 to your computer and use it in GitHub Desktop.
Readability
This file contains 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
#!/usr/bin/env node | |
var nom = require('nom'), | |
join = require('path').join, | |
args = process.argv.slice(2); | |
if(!args[0]) { | |
console.log('Usage: read <url>'); | |
process.exit(0); | |
} | |
var root = 'http://readability.com/', | |
query = 'read?url=' + encodeURIComponent(args[0]), | |
url = root + query; | |
// Selectors | |
var iframe = '#read-frame', | |
content = '#container .entry-content'; | |
nom(url, function(err, $) { | |
if(err) throw new Error(err); | |
// Article source | |
var src = $(iframe).attr('src'); | |
src = (src[0] === '/') ? src.substring(1) : src; | |
url = root + src; | |
nom(url, function(err, $) { | |
if(err) throw new Error(err); | |
var title = $('<h1>').text($('.entry-title').text()); | |
console.log($(content).prepend(title).html()); | |
process.exit(0); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use this script, you will need
nom
. Run,npm install nom
and you should be good to go!Example usage: