use std::{fs::read_dir, path::Path}; use markdown_parser::*; use crate::structs::{BlogInfo, IndexPostEntry}; pub fn get_blog_entry_markdown(path:&String) -> Result { let location = format!("content/posts/{path}.md").to_string(); read_file(Path::new(&location)) } pub fn get_all_markdowns() -> Vec { let mut post_vec:Vec = Vec::new(); let mr_dir_iter = match read_dir("content/posts") { Ok(iter) => iter, Err(err) => panic!("couldnt ls files, err {err}") }; for entry in mr_dir_iter { if let Ok(entry) = entry { let filename = entry.file_name().into_string().unwrap().split(".").collect::>()[0].to_string(); let front_matter_string = get_blog_entry_markdown(&filename).unwrap(); let front_matter:BlogInfo = serde_yaml::from_str(&front_matter_string.front_matter()).unwrap(); post_vec.push(IndexPostEntry{ title: front_matter.title, date: front_matter.date, path: format!("/blog/{filename}.html"), }); } } post_vec.sort_by_key(|e| e.path.clone() ); post_vec.reverse(); post_vec }