morb
This commit is contained in:
parent
c3071a0476
commit
12dc33b5db
2 changed files with 26 additions and 18 deletions
2
run.sh
2
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
|
||||
|
|
|
|||
34
src/main.rs
34
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 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 = 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)
|
||||
channel.items = posts.iter().enumerate().map(|(i, p)| {
|
||||
ItemBuilder::default()
|
||||
.title(format!("Blog post {i}"))
|
||||
.description(Some(p.clone()))
|
||||
.build()
|
||||
)
|
||||
}).collect::<Result<Vec<Item>, io::Error>>()?;
|
||||
println!("{}", channel.to_string());
|
||||
|
||||
}).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(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue