use axum::{extract::Path,response::Html};
use crate::structs::*;
use crate::rand_quote::get_quote;
use crate::blog_entries::{get_all_markdowns, get_blog_entry_markdown};
pub async fn index() -> Html {
let all_entries = get_all_markdowns();
let quote = get_quote();
let new_page = IndexTemplate { random_quote: quote, index_post_entries:&all_entries};
Html(new_page.to_string())
}
pub async fn about() -> Html {
let about_content = comrak::markdown_to_html("about", &comrak::Options::default());
let page_content = AboutTemplate{about_content: &about_content};
Html(page_content.to_string())
}
pub async fn blog(Path(blog_path):Path) -> Html {
match get_blog_entry_markdown(&blog_path){
Ok(markdown) => Html(
BlogTemplate{
blog_content: &comrak::markdown_to_html(markdown.content(), &comrak::Options::default()),
front_matter:&serde_yaml::from_str(markdown.front_matter()).unwrap()}.to_string()
),
Err(..) => not_found().await,
}
}
pub async fn not_found() -> Html {
Html(NotFoundTemplate{}.to_string())
}