This commit is contained in:
Rakarake 2026-03-26 13:48:48 +01:00
parent c3071a0476
commit 12dc33b5db
2 changed files with 26 additions and 18 deletions

2
run.sh
View file

@ -1,5 +1,5 @@
#/bin/sh #/bin/sh
cargo run "$@" > blog-tmp.html cargo run -- "$@" > blog-tmp.html
sed template.html -e '/INSERT_HERE/{ sed template.html -e '/INSERT_HERE/{
r blog-tmp.html r blog-tmp.html
d d

View file

@ -3,24 +3,32 @@ use markdown::to_html;
use rss::{Channel, Item, ItemBuilder}; use rss::{Channel, Item, ItemBuilder};
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
// takes directory of markdown files as only argument, outputs let posts = std::env::args().skip(2).map(|f| {
// html output into stdout (TODO make ) 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(); let mut channel = Channel::default();
channel.title = "MDF blog huge".to_string(); channel.title = "MDF blog huge".to_string();
channel.link = "rakarake.xyz".to_string(); channel.link = "rakarake.xyz".to_string();
channel.description = "morbius text wow".to_string(); channel.description = "morbius text wow".to_string();
channel.items = std::env::args().skip(1).map(|f| { channel.items = posts.iter().enumerate().map(|(i, p)| {
let contents = std::fs::read_to_string(f.clone())?; ItemBuilder::default()
let html = to_html(&contents); .title(format!("Blog post {i}"))
// TODO get the title from the document, read other metadata .description(Some(p.clone()))
Ok(ItemBuilder::default()
.title(f)
.description(html)
.build() .build()
) }).collect();
}).collect::<Result<Vec<Item>, io::Error>>()?; print!("{}", channel);
println!("{}", channel.to_string()); },
"html" => {
print!("{}", posts.iter().map(|p| format!("<div>{p}</div>")).collect::<Vec<String>>().concat())
},
_ => eprintln!("need to specify 'rss' or 'html'"),
}
}
Ok(()) Ok(())
} }