Static site generator + my presonnal website written in rust for some reason.
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
14 let about_content = parse_markdown("about");
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
22 match get_blog_entry_markdown(&blog_path){
23 Ok(markdown) =>
24 BlogTemplate{
25 blog_content: &parse_markdown(markdown.content()),
26 front_matter:&serde_yaml::from_str(markdown.front_matter()).unwrap()}.to_string()
27 ,
28 Err(..) => not_found(),
29 }
30
31}
32
33pub fn not_found() -> String {
34 NotFoundTemplate{}.to_string()
35}
36
37
38fn parse_markdown(content: &str) -> String {
39 let mut options = comrak::Options::default();
40
41 options.extension.underline = true;
42 options.extension.strikethrough = true;
43 let mut plugins = comrak::Plugins::default();
44 let adapter = comrak::plugins::syntect::SyntectAdapterBuilder::new()
45 .theme("base16-ocean.dark")
46 .build();
47
48 plugins.render.codefence_syntax_highlighter = Some(&adapter);
49 comrak::markdown_to_html_with_plugins(content, &options, &plugins)
50}