diff --git a/src/main.rs b/src/main.rs index 0140c5b..9aa38ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,12 @@ struct Cli { out: String, } +struct FeedItem { + link: String, + title: String, + time: Option>, +} + fn fetch_feed(url: impl IntoUrl) -> Result { let content = reqwest::blocking::get(url)?.bytes()?; Ok(parse(&content[..])?) @@ -62,7 +68,15 @@ fn main() -> Result<()> { feed_items.extend(fetch_feed(feed_url)?.entries); } - feed_items.sort_by(|a, b| a.published.unwrap_or(chrono::DateTime::UNIX_EPOCH).cmp(&b.published.unwrap_or(chrono::DateTime::UNIX_EPOCH)).reverse()); + let mut items: Vec = feed_items.into_iter().map(|item| FeedItem { + link: item.links.first().unwrap().href.clone(), + title: item.title.unwrap().content.clone(), + time: match item.published { + Some(time) => Some(time), + None => item.updated, + }, + }).collect(); + items.sort_by(|a, b| a.time.unwrap_or(chrono::DateTime::UNIX_EPOCH).cmp(&b.time.unwrap_or(chrono::DateTime::UNIX_EPOCH)).reverse()); let mut out = String::new(); @@ -74,8 +88,11 @@ fn main() -> Result<()> { out.push_str("
    \n"); - for item in feed_items { - out.push_str(&format!("
  • {} ({})
  • \n", item.links.first().context("No link found")?.href, item.title.context("No title found")?.content, item.published.context("No publishing time")?)); + for item in items { + out.push_str(&format!("
  • {} {}
  • \n", item.link, item.title, match item.time{ + Some(time) => format!("({})", time), + None => "".to_string(), + })); } out.push_str("
\n");