Be more strict with publishing dates and skip feed items that don't have any

This commit is contained in:
2025-04-26 13:23:20 +02:00
parent 43b866d798
commit 1419f96a3e

View File

@@ -34,7 +34,7 @@ struct Cli {
struct FeedItem { struct FeedItem {
link: String, link: String,
title: String, title: String,
time: Option<chrono::DateTime<chrono::Utc>>, time: chrono::DateTime<chrono::Utc>,
} }
fn fetch_feed(url: impl IntoUrl) -> Result<Feed> { fn fetch_feed(url: impl IntoUrl) -> Result<Feed> {
@@ -98,8 +98,9 @@ fn make_feed_item(entry: Entry) -> Result<FeedItem> {
.content .content
.clone(), .clone(),
time: match entry.published { time: match entry.published {
Some(time) => Some(time), Some(time) => time,
None => entry.updated, None => entry.updated
.context("Unable to retrieve publishing time from feed entry")?,
}, },
}) })
} }
@@ -134,7 +135,7 @@ fn main() -> Result<()> {
} }
} }
items.sort_by(|a, b| a.time.unwrap_or(chrono::DateTime::UNIX_EPOCH).cmp(&b.time.unwrap_or(chrono::DateTime::UNIX_EPOCH)).reverse()); items.sort_by(|a, b| a.time.cmp(&b.time).reverse());
let mut out = String::new(); let mut out = String::new();
@@ -149,10 +150,7 @@ fn main() -> Result<()> {
out.push_str("<ul>\n"); out.push_str("<ul>\n");
for item in items { for item in items {
out.push_str(&format!("<li><a href=\"{}\">[l]</a> {} {}</li>\n", item.link, item.title, match item.time{ out.push_str(&format!("<li><a href=\"{}\">[l]</a> {} {}</li>\n", item.link, item.title, item.time));
Some(time) => format!("({})", time),
None => "".to_string(),
}));
} }
out.push_str("</ul>\n"); out.push_str("</ul>\n");