feat: Atom feed
This commit is contained in:
+2
-28
@@ -1,29 +1,3 @@
|
||||
use rss::{Channel, Guid, Item};
|
||||
use std::error::Error;
|
||||
|
||||
pub mod discord;
|
||||
|
||||
pub async fn get_content(source: &str) -> Result<Channel, Box<dyn Error>> {
|
||||
let content = reqwest::get(source)
|
||||
.await?
|
||||
.bytes()
|
||||
.await?;
|
||||
let channel = Channel::read_from(&content[..])?;
|
||||
Ok(channel)
|
||||
}
|
||||
|
||||
pub fn get_latest(rss: &Channel) -> Option<&Item> {
|
||||
rss.items().first()
|
||||
}
|
||||
|
||||
pub fn get_new<'a>(rss: &'a Channel, latest: &Guid) -> &'a [Item] {
|
||||
match rss
|
||||
.items()
|
||||
.iter()
|
||||
.position(|item| item.guid().map(|guid| guid == latest).unwrap_or(false))
|
||||
.map(|i| &rss.items()[0..i])
|
||||
{
|
||||
None => rss.items(),
|
||||
Some(list) => list,
|
||||
}
|
||||
}
|
||||
pub mod rss;
|
||||
pub mod atom;
|
||||
Reference in New Issue
Block a user