get posted date via trait method
This commit is contained in:
parent
fd258b4d23
commit
98239fd8f7
1 changed files with 12 additions and 4 deletions
16
src/lib.rs
16
src/lib.rs
|
|
@ -251,6 +251,16 @@ impl BlogdorTheAggregator {
|
|||
}
|
||||
}
|
||||
|
||||
trait Posted {
|
||||
fn posted(&self) -> DateTime<Utc>;
|
||||
}
|
||||
|
||||
impl Posted for feed_rs::model::Entry {
|
||||
fn posted(&self) -> DateTime<Utc> {
|
||||
self.published.or(self.updated).unwrap_or(LAST_FETCHED)
|
||||
}
|
||||
}
|
||||
|
||||
// takes args by value because it's meant to be called from inside a spawned
|
||||
// tokio task scope
|
||||
async fn check_feed(
|
||||
|
|
@ -281,11 +291,9 @@ async fn check_feed(
|
|||
.map_err(|e| format!("could not get bytes from response from {url}, got {e}"))?;
|
||||
let mut feed =
|
||||
parse(feed.reader()).map_err(|e| format!("could not parse feed from {url}, got {e}"))?;
|
||||
feed.entries
|
||||
.sort_by_key(|e| e.published.or(e.updated).unwrap_or(last_fetched));
|
||||
feed.entries.sort_by_key(|e| e.posted());
|
||||
for post in feed.entries.into_iter().rev().take(5) {
|
||||
let last_year = now - ONE_YEAR;
|
||||
if post.published.unwrap_or(last_year) > last_fetched {
|
||||
if post.posted() > last_fetched {
|
||||
let entry = FeedEntry {
|
||||
post_url: post
|
||||
.links
|
||||
|
|
|
|||
Loading…
Reference in a new issue