Static site generator + my presonnal website written in rust for some reason.

minor changes, comments, and formatting + better error handling

+36 -30
+13 -13
Cargo.lock
··· 832 832 ] 833 833 834 834 [[package]] 835 - name = "rusty_duck" 836 - version = "0.1.0" 837 - dependencies = [ 838 - "askama", 839 - "comrak", 840 - "markdown-parser", 841 - "rand", 842 - "serde", 843 - "serde_yaml 0.9.34+deprecated", 844 - "syntect", 845 - ] 846 - 847 - [[package]] 848 835 name = "ryu" 849 836 version = "1.0.18" 850 837 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 936 923 dependencies = [ 937 924 "deunicode", 938 925 "wasm-bindgen", 926 + ] 927 + 928 + [[package]] 929 + name = "staticrustator" 930 + version = "0.1.0" 931 + dependencies = [ 932 + "askama", 933 + "comrak", 934 + "markdown-parser", 935 + "rand", 936 + "serde", 937 + "serde_yaml 0.9.34+deprecated", 938 + "syntect", 939 939 ] 940 940 941 941 [[package]]
+1 -1
Cargo.toml
··· 1 1 [package] 2 - name = "rusty_duck" 2 + name = "staticrustator" 3 3 version = "0.1.0" 4 4 edition = "2021" 5 5
-1
src/blog_entries.rs
··· 15 15 Ok(iter) => iter, 16 16 Err(err) => panic!("couldnt ls files, err {err}") 17 17 }; 18 - 19 18 for entry in mr_dir_iter { 20 19 if let Ok(entry) = entry { 21 20
+4 -8
src/handlers.rs
··· 10 10 } 11 11 12 12 pub fn about() -> String { 13 - 14 - 15 13 let about_markdown = markdown_parser::read_file("content/pages/about.md").expect("Could no find about.md file in content/pages/ folder"); 16 - 17 14 let about_content = parse_markdown(about_markdown.content()); 18 15 let page_content = AboutTemplate{about_content: &about_content}; 19 16 page_content.to_string() ··· 21 18 22 19 23 20 pub fn blog(blog_path:String) -> String { 24 - 25 - match get_blog_entry_markdown(&blog_path){ 21 + match get_blog_entry_markdown(&blog_path){ 26 22 Ok(markdown) => 27 - BlogTemplate{ 28 - blog_content: &parse_markdown(markdown.content()), 29 - front_matter:&serde_yaml::from_str(markdown.front_matter()).unwrap()}.to_string() 23 + BlogTemplate{ 24 + blog_content: &parse_markdown(markdown.content()), 25 + front_matter:&serde_yaml::from_str(markdown.front_matter()).unwrap()}.to_string() 30 26 , 31 27 Err(..) => not_found(), 32 28 }
+13 -7
src/main.rs
··· 12 12 match DirBuilder::new() 13 13 .recursive(true) 14 14 .create(output_path) { 15 - Ok(_) => (), 16 - Err(_) => (), 15 + Ok(()) => (), 16 + Err(err) => if err.kind() == std::io::ErrorKind::AlreadyExists { 17 + () // if folder already exists we can continue 18 + } else { 19 + panic!("Error detected: {err}") 20 + } 17 21 } 18 22 19 23 match copy_dir_all("assets", format!("{output_path}/assets")) { 20 - Ok(_) => (), 24 + Ok(()) => (), 21 25 Err(err) => println!("Couldnt copy assets directory, err: {err}"), 22 26 } 23 27 24 - 25 - 26 28 write(format!("{output_path}/index.html"), handlers::index().as_bytes()).expect("Couldnt write index file"); 27 29 write(format!("{output_path}/about.html"), handlers::about().as_bytes()).expect("Couldnt write about file"); 28 30 write(format!("{output_path}/404.html"), handlers::not_found().as_bytes()).expect("Couldnt write 404 file"); 29 31 30 32 match DirBuilder::new() 31 33 .create(format!("{output_path}/blog")) { 32 - Ok(_) => (), 33 - Err(err) => println!("Error detected: {err}"), 34 + Ok(()) => (), 35 + Err(err) => if err.kind() == std::io::ErrorKind::AlreadyExists { 36 + () // if folder already exists we can continue 37 + } else { 38 + panic!("Error detected: {err}") 39 + } 34 40 } 35 41 36 42
+5
src/rand_quote.rs
··· 1 1 use rand::Rng; 2 2 3 + /// Generates a random quote from a vec of &str present in the function body. 3 4 pub fn get_quote() -> &'static str { 5 + // originally while dynamically server it would generate a new quote every time index would be 6 + // reloaded, but with static serve nature a new quote is written every new build. 7 + // Maybe not worth it. 8 + // feel free to remove 4 9 let vs = vec![ 5 10 "Silliness and tomfooler are afoot, and who am I to stop it.", 6 11 "Low entropy self replicating phenomenon that generates a binding force called compassion.",