-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
41 lines (35 loc) · 898 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var request = require('request')
var htmlparser = require('htmlparser2')
function findRss (url, cb) {
request.get(url, function (err, res, body) {
if (err) return cb(err)
var feeds = []
var supportedFeeds = [
'application/rss+xml',
'application/atom+xml',
'application/rdf+xml',
'application/rss',
'application/atom',
'application/rdf',
'text/rss+xml',
'text/atom+xml',
'text/rdf+xml',
'text/rss',
'text/atom',
'text/rdf'
]
var parser = new htmlparser.Parser({
onopentag: function (name, attrs) {
if (name === 'link' && supportedFeeds.indexOf(attrs.type) > -1) {
feeds.push(attrs.href)
}
},
onend: function () {
return cb(null, feeds)
}
}, {decodeEntities: true})
parser.write(body)
parser.end()
})
}
module.exports = findRss