From 0d23f8515cee780937da94d7498a3ea7c1bc8586 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 17 Feb 2025 20:05:01 +0200 Subject: [PATCH] collect titles, update headers format, remove `url` crate dependency --- Cargo.toml | 1 - src/main.rs | 28 +++++++++++----------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7cb3cf9..b6d07c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,3 @@ chrono = "0.4.39" clap = { version = "4.5.28", features = ["derive"] } reqwest = { version = "0.12.12", features = ["blocking"] } rss = "2.0.11" -url = "2.5.4" diff --git a/src/main.rs b/src/main.rs index d640313..2b4ce07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,6 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box> { fs::{metadata, read_dir, File}, io::{Read, Write}, }; - use url::Url; output.debug("feed update begin"); @@ -51,7 +50,7 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box> { let mut data = Vec::new(); - let destination = match item.pub_date() { + let (destination, pub_date) = match item.pub_date() { Some(pub_date) => { let destination = Destination::build(&argument.target, pub_date, true)?; if metadata(destination.item()).is_ok() { @@ -59,8 +58,15 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box> { continue; } - data.push(format!("# {pub_date}")); - destination + data.push(format!( + "# {}", + match item.title() { + Some(title) => title, + None => pub_date, + } + )); + + (destination, pub_date) } None => { output.warning("item skipped as `pub_date` required by application"); @@ -77,19 +83,7 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box> { } if let Some(link) = item.link() { - data.push(match Url::parse(link) { - Ok(url) => { - if let Some(host) = url.host_str() { - format!("=> {link} {host}") - } else { - format!("=> {link}") - } - } - Err(e) => { - output.warning(&e.to_string()); - format!("=> {link}") - } - }) + data.push(format!("=> {link} {pub_date}")) } File::create(destination.item())?.write_all(data.join("\n\n").as_bytes())?;