Add feed name
This commit is contained in:
parent
c841e9ad9e
commit
ceab6a1482
27
src/main.rs
27
src/main.rs
@ -37,24 +37,37 @@ fn fetch_feed(url: impl IntoUrl) -> Result<Feed> {
|
|||||||
Ok(parse(&content[..])?)
|
Ok(parse(&content[..])?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_feed_file(path: &str) -> Result<Vec<Url>> {
|
struct FeedFile {
|
||||||
let mut out = Vec::new();
|
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() {
|
for line in std::fs::read_to_string(path)?.lines() {
|
||||||
let line = line.trim().to_string();
|
let line = line.trim().to_string();
|
||||||
if line == "" {
|
if line == "" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if line.starts_with("# name: ") {
|
||||||
|
name = String::from(&line[8..]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if line.starts_with("#") {
|
if line.starts_with("#") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let url = Url::parse(&line)?;
|
let url = Url::parse(&line)?;
|
||||||
println!("{}", url);
|
println!("{}", url);
|
||||||
|
|
||||||
out.push(url);
|
urls.push(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(out)
|
Ok(FeedFile{
|
||||||
|
name: name,
|
||||||
|
urls: urls,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
@ -62,9 +75,9 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
let mut feed_items = Vec::new();
|
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);
|
feed_items.extend(fetch_feed(feed_url)?.entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,8 +96,10 @@ fn main() -> Result<()> {
|
|||||||
out.push_str("<!DOCTYPE html>\n");
|
out.push_str("<!DOCTYPE html>\n");
|
||||||
out.push_str("<html>\n");
|
out.push_str("<html>\n");
|
||||||
out.push_str("<head>\n");
|
out.push_str("<head>\n");
|
||||||
|
out.push_str(&format!("<title>{} - rainbowrss</title>", feed_file.name));
|
||||||
out.push_str("</head>\n");
|
out.push_str("</head>\n");
|
||||||
out.push_str("<body>\n");
|
out.push_str("<body>\n");
|
||||||
|
out.push_str(&format!("<h1>{}</h1>", feed_file.name));
|
||||||
|
|
||||||
out.push_str("<ul>\n");
|
out.push_str("<ul>\n");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user