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
15 let about_markdown = markdown_parser::read_file("content/pages/about.md").expect("Could no find about.md file in content/pages/ folder");
16
17 let about_content = parse_markdown(about_markdown.content());
18 let page_content = AboutTemplate{about_content: &about_content};
19 page_content.to_string()
20}
21
22
23pub fn blog(blog_path:String) -> String {
24
25 match get_blog_entry_markdown(&blog_path){
26 Ok(markdown) =>
27 BlogTemplate{
28 blog_content: &parse_markdown(markdown.content()),
29 front_matter:&serde_yaml::from_str(markdown.front_matter()).unwrap()}.to_string()
30 ,
31 Err(..) => not_found(),
32 }
33
34}
35
36pub fn not_found() -> String {
37 NotFoundTemplate{}.to_string()
38}
39
40
41fn parse_markdown(content: &str) -> String {
42 let mut options = comrak::Options::default();
43
44 options.extension.underline = true;
45 options.extension.strikethrough = true;
46 let mut plugins = comrak::Plugins::default();
47 let adapter = comrak::plugins::syntect::SyntectAdapterBuilder::new()
48 .theme("base16-mocha.dark")
49 .build();
50
51 plugins.render.codefence_syntax_highlighter = Some(&adapter);
52 comrak::markdown_to_html_with_plugins(content, &options, &plugins)
53}