...
 
Commits (2)
......@@ -13,6 +13,10 @@
`npm install feedrat`
## Testing
`npm test`
## Usage
```javascript
......
......@@ -2,7 +2,16 @@ const request = require('request'),
cheerio = require('cheerio'),
Url = require('url');
var IsUrl = new RegExp('^(?:[a-z]+:)?//', 'i');
if (IsUrl.test('https://yphil.bitbucket.io/rss/feedtwo'))
console.log('yep!');
else
console.log('Nope!');
module.exports = function(url, callback) {
var p = Url.parse(url),
protocol = p.protocol != null ? p.protocol : 'http:',
root = protocol + "//" + p.hostname,
......@@ -25,19 +34,14 @@ module.exports = function(url, callback) {
if (!p.protocol) return callback(null, searchPrefix + url.split(' '));
if (p.host.endsWith('youtube.com') && p.path.startsWith('/channel') && p.path.split('/').length === 3) {
if (p.host.endsWith('youtube.com') && p.path.startsWith('/channel') && p.path.split('/').length === 3)
return callback(null, videoPrefix + p.path.split('/')[2]);
}
// Search the DOM of the page
does_it_render(feed, function(err, renders) {
if (err) return callback(err);
if (renders) {
return callback(null, feed);
}
request(feed, function(err, res, body) {
const $ = cheerio.load(body);
......@@ -46,7 +50,6 @@ module.exports = function(url, callback) {
$('link').each(function() {
if ($(this).attr('type'), linkTypes.indexOf($(this).attr('type')) > -1) {
feed = $(this).attr('href');
if (!isUrl.test(feed)) feed = root + feed;
}
});
}
......@@ -65,11 +68,11 @@ module.exports = function(url, callback) {
}
}
return callback(null, feed);
if (!isUrl.test(feed)) feed = root + feed;
return callback(null, feed);
});
});
};
function does_it_render(url, callback) {
......
{
"name": "feedrat",
"version": "0.1.47",
"version": "0.1.48",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
{
"name": "feedrat",
"version": "0.1.47",
"version": "0.1.48",
"description": "Search, find and report a web page's RSS feed",
"main": "feedrat.js",
"license": "SEE LICENSE IN LICENSE",
......
......@@ -24,15 +24,23 @@ describe('feedrat', function() {
it('discovers the RSS feed by reading the link rel', function(done) {
feedrat('http://lemonde.fr/', function(err, url) {
if (err) return done(err);
url.should.eql('http://www.lemonde.fr/rss/une.xml');
url.should.eql('https://www.lemonde.fr/rss/une.xml');
done();
});
});
it('returns an absolute path even when the site is serving a relative one', function(done) {
feedrat('https://sputniknews.com/', function(err, url) {
if (err) return done(err);
url.should.eql('https://sputniknews.com/export/rss2/archive/index.xml');
done();
});
});
it('handles finding several RSS feeds', function(done) {
feedrat('http://www.disclose.tv/', function(err, url) {
feedrat('https://yphil.bitbucket.io/', function(err, url) {
if (err) return done(err);
url.should.be.oneOf('http://www.disclose.tv/rss/posts', 'http://www.disclose.tv/rss/videos');
url.should.be.oneOf('https://yphil.bitbucket.io/rss/feedone', 'https://yphil.bitbucket.io/rss/feedtwo');
done();
});
});
......@@ -53,7 +61,7 @@ describe('feedrat', function() {
});
});
it('builds a YTube URL from the channels', function(done) {
it('builds a feed URL from a YouTube channel URL', function(done) {
feedrat('https://www.youtube.com/channel/UCeUNM9NqJqZXfRNeuW4_2sg', function(err, url) {
if (err) return done(err);
url.should.eql('https://www.youtube.com/feeds/videos.xml?channel_id=UCeUNM9NqJqZXfRNeuW4_2sg');
......@@ -61,7 +69,7 @@ describe('feedrat', function() {
});
});
it('builds a search feed from a non-URL string', function(done) {
it('builds a search feed URL from a search string', function(done) {
feedrat('bitcoin crash', function(err, url) {
if (err) return done(err);
url.should.eql('https://trouvons.org/?format=rss&categories=news&q=bitcoin,crash');
......