Add feed name

This commit is contained in:
clerie 2025-01-05 15:34:31 +01:00
parent c841e9ad9e
commit ceab6a1482

View File

@ -37,24 +37,37 @@ fn fetch_feed(url: impl IntoUrl) -> Result<Feed> {
Ok(parse(&content[..])?)
}
fn read_feed_file(path: &str) -> Result<Vec<Url>> {
let mut out = Vec::new();
struct FeedFile {
name: String,
urls: Vec<Url>,
}
fn read_feed_file(path: &str) -> Result<FeedFile> {
let mut name = String::from(path);
let mut urls = Vec::new();
for line in std::fs::read_to_string(path)?.lines() {
let line = line.trim().to_string();
if line == "" {
continue;
}
if line.starts_with("# name: ") {
name = String::from(&line[8..]);
continue;
}
if line.starts_with("#") {
continue;
}
let url = Url::parse(&line)?;
println!("{}", url);
out.push(url);
urls.push(url);
}
Ok(out)
Ok(FeedFile{
name: name,
urls: urls,
})
}
fn main() -> Result<()> {
@ -62,9 +75,9 @@ fn main() -> Result<()> {
let mut feed_items = Vec::new();
let feeds = read_feed_file(&cli.feeds)?;
let feed_file = read_feed_file(&cli.feeds)?;
for feed_url in feeds {
for feed_url in feed_file.urls {
feed_items.extend(fetch_feed(feed_url)?.entries);
}
@ -83,8 +96,10 @@ fn main() -> Result<()> {
out.push_str("<!DOCTYPE html>\n");
out.push_str("<html>\n");
out.push_str("<head>\n");
out.push_str(&format!("<title>{} - rainbowrss</title>", feed_file.name));
out.push_str("</head>\n");
out.push_str("<body>\n");
out.push_str(&format!("<h1>{}</h1>", feed_file.name));
out.push_str("<ul>\n");