From 0e6ee4cb22f37125e97d787c2011cbb6f5d6404c Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 23 Oct 2025 01:06:28 +0300 Subject: [PATCH] remove extra lines --- Cargo.toml | 1 + src/main.rs | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 386d4ce..7f2929f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ anyhow = "1.0" chrono = "^0.4.20" clap = { version = "4.5", features = ["derive"] } log = "0.4" +regex = "1.12" reqwest = { version = "0.12", features = ["blocking"] } rss = "2.0" serde = { version = "1.0", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index 52f82d1..df594e3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,6 +61,7 @@ fn crawl(feed: &Feed) -> Result<()> { let channel = Channel::read_from(&get(feed.url.as_str())?.bytes()?[..])?; let channel_items = channel.items(); let channel_items_limit = feed.list_items_limit.unwrap_or(channel_items.len()); + let regex = regex::Regex::new(r"\n{2,}").unwrap(); for template in &feed.templates { let root = PathBuf::from(template); @@ -106,14 +107,25 @@ fn crawl(feed: &Feed) -> Result<()> { .iter() .take(channel_items_limit) .map(|i| { - index_item - .replace("{title}", &strip_tags(i.title().unwrap_or_default())) - .replace( - "{description}", - &strip_tags(i.description().unwrap_or_default()), + regex + .replace_all( + &index_item + .replace( + "{title}", + &strip_tags(i.title().unwrap_or_default()), + ) + .replace( + "{description}", + &strip_tags(i.description().unwrap_or_default()), + ) + .replace("{link}", i.link().unwrap_or_default()) + .replace( + "{pub_date}", + &time(i.pub_date(), &feed.pub_date_format), + ), + "\n", ) - .replace("{link}", i.link().unwrap_or_default()) - .replace("{pub_date}", &time(i.pub_date(), &feed.pub_date_format)) + .to_string() }) .collect::(), )