Static site generator + my presonnal website written in rust for some reason.
1use std::{fs::read_dir, path::Path}; 2 3use markdown_parser::*; 4 5use crate::structs::{BlogInfo, IndexPostEntry}; 6 7pub fn get_blog_entry_markdown(path:&String) -> Result<Markdown,Error> { 8 let location = format!("posts/{path}.md").to_string(); 9 read_file(Path::new(&location)) 10} 11 12pub fn get_all_markdowns() -> Vec<IndexPostEntry> { 13 let mut post_vec:Vec<IndexPostEntry> = Vec::new(); 14 let mr_dir_iter = match read_dir("posts/") { 15 Ok(iter) => iter, 16 Err(err) => panic!("could ls files, err {err}") 17 }; 18 19 for entry in mr_dir_iter { 20 if let Ok(entry) = entry { 21 22 let filename = entry.file_name().into_string().unwrap().split(".").collect::<Vec<_>>()[0].to_string(); 23 24 25 let front_matter_string = get_blog_entry_markdown(&filename).unwrap(); 26 27 let front_matter:BlogInfo = serde_yaml::from_str(&front_matter_string.front_matter()).unwrap(); 28 29 post_vec.push(IndexPostEntry{ 30 title: front_matter.title, 31 date: front_matter.date, 32 path: format!("/blog/{filename}"), 33 }); 34 35 } 36 } 37 post_vec.sort_by_key(|e| e.path.clone() ); 38 post_vec.reverse(); 39 post_vec 40}