34 lines
1.2 KiB
Rust
34 lines
1.2 KiB
Rust
use std::io;
|
|
use markdown::to_html;
|
|
use rss::{Channel, ItemBuilder};
|
|
|
|
fn main() -> io::Result<()> {
|
|
let posts = std::env::args().skip(2).map(|f| {
|
|
let contents = std::fs::read_to_string(f.clone())?;
|
|
Ok(to_html(&contents))
|
|
}).collect::<Result<Vec<String>, 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!("<div>{p}</div>")).collect::<Vec<String>>().concat())
|
|
},
|
|
_ => eprintln!("need to specify 'rss' or 'html'"),
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
|