use crate::structs::*; use crate::rand_quote::get_quote; use crate::blog_entries::{get_all_markdowns, get_blog_entry_markdown}; pub fn index() -> String { let all_entries = get_all_markdowns(); let quote = get_quote(); let new_page = IndexTemplate { random_quote: quote, index_post_entries:&all_entries}; new_page.to_string() } pub fn about() -> String { let about_markdown = markdown_parser::read_file("content/pages/about.md").expect("Could no find about.md file in content/pages/ folder"); let about_content = parse_markdown(about_markdown.content()); let page_content = AboutTemplate{about_content: &about_content}; page_content.to_string() } pub fn blog(blog_path:String) -> String { match get_blog_entry_markdown(&blog_path){ Ok(markdown) => BlogTemplate{ blog_content: &parse_markdown(markdown.content()), front_matter:&serde_yaml::from_str(markdown.front_matter()).unwrap()}.to_string() , Err(..) => not_found(), } } pub fn not_found() -> String { NotFoundTemplate{}.to_string() } fn parse_markdown(content: &str) -> String { let mut options = comrak::Options::default(); options.extension.underline = true; options.extension.strikethrough = true; let mut plugins = comrak::Plugins::default(); let adapter = comrak::plugins::syntect::SyntectAdapterBuilder::new() .theme("base16-mocha.dark") .build(); plugins.render.codefence_syntax_highlighter = Some(&adapter); comrak::markdown_to_html_with_plugins(content, &options, &plugins) }