Created
April 30, 2012 22:22
-
-
Save arahaya/2563220 to your computer and use it in GitHub Desktop.
[JavaScript] Extract feed urls from HTML document
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
function findFeeds() { | |
var FEED_CONTENT_TYPES = { | |
"application/rss+xml": 1, | |
"application/atom+xml": 1, | |
"application/rdf+xml": 1, | |
"text/xml": 1, | |
"application/x.atom+xml": 1, | |
"application/x-atom+xml": 1 | |
}; | |
function each(a, c) { | |
for (var i = 0, l = a.length; i < l; i++) { | |
c(a[i]); | |
} | |
} | |
function parse(doc) { | |
var feeds = []; | |
each(doc.getElementsByTagName('head'), function (head) { | |
each(head.getElementsByTagName('link'), function (link) { | |
if (link.rel === 'alternate' && FEED_CONTENT_TYPES[link.type] && link.href) { | |
feeds.push({ | |
href: link.href, | |
title: link.title | |
}); | |
} | |
}) | |
}); | |
return feeds; | |
} | |
return parse(document); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment