mirror of
https://github.com/YGGverse/pulsarss.git
synced 2026-03-31 09:05:29 +00:00
collect titles, update headers format, remove url crate dependency
This commit is contained in:
parent
5201fb9cf7
commit
0d23f8515c
2 changed files with 11 additions and 18 deletions
|
|
@ -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"
|
||||
|
|
|
|||
28
src/main.rs
28
src/main.rs
|
|
@ -30,7 +30,6 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box<dyn Error>> {
|
|||
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<dyn Error>> {
|
|||
|
||||
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<dyn Error>> {
|
|||
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<dyn Error>> {
|
|||
}
|
||||
|
||||
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())?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue