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())?;
let mut channel = Channel::default(); Ok(to_html(&contents))
channel.title = "MDF blog huge".to_string(); }).collect::<Result<Vec<String>, io::Error>>()?;
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::<Result<Vec<Item>, io::Error>>()?;
println!("{}", channel.to_string());
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(()) Ok(())
} }