40 lines
1 KiB
Rust
40 lines
1 KiB
Rust
use std::fs;
|
|
|
|
use pulldown_cmark::{Options, Parser};
|
|
|
|
pub fn prep(blogPath: String) -> Vec<BlogPost>{
|
|
let blogPaths = fs::read_dir(&blogPath);
|
|
|
|
let parsed = match blogPaths {
|
|
Ok(paths) => paths
|
|
.into_iter()
|
|
.map(|x| x.unwrap().path().to_str().unwrap().to_string())
|
|
.collect::<Vec<String>>(),
|
|
Err(_) => panic!("Could not load directory of blog"),
|
|
};
|
|
|
|
dbg!(&parsed);
|
|
|
|
let mut options = Options::empty();
|
|
|
|
|
|
let compiled_html = parsed.into_iter().map(|mdFilePath| {
|
|
let fileContents = fs::read_to_string(&mdFilePath).unwrap();
|
|
let name = mdFilePath.strip_prefix(&format!("{}/", &blogPath)).unwrap().to_string();
|
|
let parser = Parser::new_ext(&fileContents, options);
|
|
|
|
let mut html = String::new();
|
|
pulldown_cmark::html::push_html(&mut html, parser);
|
|
BlogPost{
|
|
name,
|
|
html
|
|
}
|
|
}).collect::<Vec<_>>();
|
|
|
|
compiled_html
|
|
}
|
|
|
|
pub struct BlogPost {
|
|
pub name: String,
|
|
pub html: String,
|
|
}
|