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!("content/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("content/posts") {
15 Ok(iter) => iter,
16 Err(err) => panic!("couldnt ls files, err {err}")
17 };
18 for entry in mr_dir_iter {
19 if let Ok(entry) = entry {
20
21 let filename = entry.file_name().into_string().unwrap().split(".").collect::<Vec<_>>()[0].to_string();
22
23
24 let front_matter_string = get_blog_entry_markdown(&filename).unwrap();
25
26 let front_matter:BlogInfo = serde_yaml::from_str(&front_matter_string.front_matter()).unwrap();
27
28 post_vec.push(IndexPostEntry{
29 title: front_matter.title,
30 date: front_matter.date,
31 path: format!("/blog/{filename}.html"),
32 });
33
34 }
35 }
36 post_vec.sort_by_key(|e| e.path.clone() );
37 post_vec.reverse();
38 post_vec
39}