Skip to content

Instantly share code, notes, and snippets.

@matthewmueller
Created May 9, 2012 02:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewmueller/2641307 to your computer and use it in GitHub Desktop.
Save matthewmueller/2641307 to your computer and use it in GitHub Desktop.
Readability
#!/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);
});
});
@matthewmueller
Copy link
Author

To use this script, you will need nom. Run, npm install nom and you should be good to go!

Example usage:

./read http://www.alistapart.com/articles/say-no-to-faux-bold/ > out.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment