Function feedfinder::detect_feeds [−][src]
Expand description
Find feeds in the supplied content.
The detect_feeds
function will look for feeds:
- Linked via the
<link>
tag in the HTML - Linked via
<a>
tag in the HTML - By guessing from the software used to generate the page:
- Tumblr
- WordPress
- Hugo
- Jekyll
- Ghost
- From YouTube:
- channels
- playlists
- users
Parameters
detect_feeds
takes a String of HTML content and the URL that content was retrieved
from. The function will not fetch the URL itself. This needs to be done by the caller
using a library like reqwest or
hyper.
Return value
detect_feeds
does not access the network so the returned list of feed candidates
should be tested to see:
- If they actually exist.
- If they look like they are a feed (by checking for an XML or JSON MIME type).
The return value is wrapped in a Result, errors can occur if a candidate URL is invalid or there is a problem parsing or traversing the HTML content.
Example
use feedfinder::detect_feeds;
use url::Url;
fn main() {
let url = Url::parse("https://example.com/example").expect("unable to parse url");
let html = r#"
<html>
<head>
<title>Example</title>
<link rel="alternate" href="/posts.rss" type="application/rss+xml" />
</head>
<body>
My fun page with a feed.
</body>
</html>"#;
match detect_feeds(&url, html) {
Ok(feeds) => {
println!("Possible feeds for {}", url);
for feed in feeds {
println!("{:?}", feed);
}
}
Err(err) => println!("Unable to find feeds due to error: {}", err),
}
}