Static site generator + my presonnal website written in rust for some reason.
at main 1.6 kB view raw
1use crate::structs::*; 2use crate::rand_quote::get_quote; 3use crate::blog_entries::{get_all_markdowns, get_blog_entry_markdown}; 4 5pub fn index() -> String { 6 let all_entries = get_all_markdowns(); 7 let quote = get_quote(); 8 let new_page = IndexTemplate { random_quote: quote, index_post_entries:&all_entries}; 9 new_page.to_string() 10} 11 12pub fn about() -> String { 13 let about_markdown = markdown_parser::read_file("content/pages/about.md").expect("Could no find about.md file in content/pages/ folder"); 14 let about_content = parse_markdown(about_markdown.content()); 15 let page_content = AboutTemplate{about_content: &about_content}; 16 page_content.to_string() 17} 18 19 20pub fn blog(blog_path:String) -> String { 21 match get_blog_entry_markdown(&blog_path){ 22 Ok(markdown) => 23 BlogTemplate{ 24 blog_content: &parse_markdown(markdown.content()), 25 front_matter:&serde_yaml::from_str(markdown.front_matter()).unwrap()}.to_string() 26 , 27 Err(..) => not_found(), 28 } 29 30} 31 32pub fn not_found() -> String { 33 NotFoundTemplate{}.to_string() 34} 35 36 37fn parse_markdown(content: &str) -> String { 38 let mut options = comrak::Options::default(); 39 40 options.extension.underline = true; 41 options.extension.strikethrough = true; 42 let mut plugins = comrak::Plugins::default(); 43 let adapter = comrak::plugins::syntect::SyntectAdapterBuilder::new() 44 .theme("base16-mocha.dark") 45 .build(); 46 47 plugins.render.codefence_syntax_highlighter = Some(&adapter); 48 comrak::markdown_to_html_with_plugins(content, &options, &plugins) 49}