diff --git a/run.sh b/run.sh index 0b0f004..7bb6b7c 100755 --- a/run.sh +++ b/run.sh @@ -1,5 +1,5 @@ #/bin/sh -cargo run "$@" > blog-tmp.html +cargo run -- "$@" > blog-tmp.html sed template.html -e '/INSERT_HERE/{ r blog-tmp.html d diff --git a/src/main.rs b/src/main.rs index 314de82..243b244 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,24 +3,32 @@ use markdown::to_html; use rss::{Channel, Item, ItemBuilder}; fn main() -> io::Result<()> { - // takes directory of markdown files as only argument, outputs - // html output into stdout (TODO make ) - let mut channel = Channel::default(); - channel.title = "MDF blog huge".to_string(); - channel.link = "rakarake.xyz".to_string(); - channel.description = "morbius text wow".to_string(); - channel.items = std::env::args().skip(1).map(|f| { - let contents = std::fs::read_to_string(f.clone())?; - let html = to_html(&contents); - // TODO get the title from the document, read other metadata - Ok(ItemBuilder::default() - .title(f) - .description(html) - .build() - ) - }).collect::, io::Error>>()?; - println!("{}", channel.to_string()); + let posts = std::env::args().skip(2).map(|f| { + let contents = std::fs::read_to_string(f.clone())?; + Ok(to_html(&contents)) + }).collect::, io::Error>>()?; + if let Some(mode) = std::env::args().skip(1).next() { + match mode.as_str() { + "rss" => { + let mut channel = Channel::default(); + channel.title = "MDF blog huge".to_string(); + channel.link = "rakarake.xyz".to_string(); + channel.description = "morbius text wow".to_string(); + channel.items = posts.iter().enumerate().map(|(i, p)| { + ItemBuilder::default() + .title(format!("Blog post {i}")) + .description(Some(p.clone())) + .build() + }).collect(); + print!("{}", channel); + }, + "html" => { + print!("{}", posts.iter().map(|p| format!("
{p}
")).collect::>().concat()) + }, + _ => eprintln!("need to specify 'rss' or 'html'"), + } + } Ok(()) }