Skip to content

Commit 0d23f85

Browse files
author
yggverse
committed
collect titles, update headers format, remove url crate dependency
1 parent 5201fb9 commit 0d23f85

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ chrono = "0.4.39"
1414
clap = { version = "4.5.28", features = ["derive"] }
1515
reqwest = { version = "0.12.12", features = ["blocking"] }
1616
rss = "2.0.11"
17-
url = "2.5.4"

src/main.rs

+11-17
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box<dyn Error>> {
3030
fs::{metadata, read_dir, File},
3131
io::{Read, Write},
3232
};
33-
use url::Url;
3433

3534
output.debug("feed update begin");
3635

@@ -51,16 +50,23 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box<dyn Error>> {
5150

5251
let mut data = Vec::new();
5352

54-
let destination = match item.pub_date() {
53+
let (destination, pub_date) = match item.pub_date() {
5554
Some(pub_date) => {
5655
let destination = Destination::build(&argument.target, pub_date, true)?;
5756
if metadata(destination.item()).is_ok() {
5857
exist += 1;
5958
continue;
6059
}
6160

62-
data.push(format!("# {pub_date}"));
63-
destination
61+
data.push(format!(
62+
"# {}",
63+
match item.title() {
64+
Some(title) => title,
65+
None => pub_date,
66+
}
67+
));
68+
69+
(destination, pub_date)
6470
}
6571
None => {
6672
output.warning("item skipped as `pub_date` required by application");
@@ -77,19 +83,7 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box<dyn Error>> {
7783
}
7884

7985
if let Some(link) = item.link() {
80-
data.push(match Url::parse(link) {
81-
Ok(url) => {
82-
if let Some(host) = url.host_str() {
83-
format!("=> {link} {host}")
84-
} else {
85-
format!("=> {link}")
86-
}
87-
}
88-
Err(e) => {
89-
output.warning(&e.to_string());
90-
format!("=> {link}")
91-
}
92-
})
86+
data.push(format!("=> {link} {pub_date}"))
9387
}
9488

9589
File::create(destination.item())?.write_all(data.join("\n\n").as_bytes())?;

0 commit comments

Comments
 (0)