Figure out item times better
This commit is contained in:
parent
d86df2a44b
commit
a2f1e29c36
23
src/main.rs
23
src/main.rs
@ -26,6 +26,12 @@ struct Cli {
|
||||
out: String,
|
||||
}
|
||||
|
||||
struct FeedItem {
|
||||
link: String,
|
||||
title: String,
|
||||
time: Option<chrono::DateTime<chrono::Utc>>,
|
||||
}
|
||||
|
||||
fn fetch_feed(url: impl IntoUrl) -> Result<Feed> {
|
||||
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<FeedItem> = 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("<ul>\n");
|
||||
|
||||
for item in feed_items {
|
||||
out.push_str(&format!("<li><a href=\"{}\">{}</a> ({})</li>\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!("<li><a href=\"{}\">{}</a> {}</li>\n", item.link, item.title, match item.time{
|
||||
Some(time) => format!("({})", time),
|
||||
None => "".to_string(),
|
||||
}));
|
||||
}
|
||||
|
||||
out.push_str("</ul>\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user