minor changes, comments, and formatting + better error handling
This commit is contained in:
parent
f9bc5cdfa8
commit
7fd5232de7
6 changed files with 36 additions and 30 deletions
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -831,19 +831,6 @@ dependencies = [
|
|||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rusty_duck"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"askama",
|
||||
"comrak",
|
||||
"markdown-parser",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_yaml 0.9.34+deprecated",
|
||||
"syntect",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.18"
|
||||
|
@ -938,6 +925,19 @@ dependencies = [
|
|||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "staticrustator"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"askama",
|
||||
"comrak",
|
||||
"markdown-parser",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_yaml 0.9.34+deprecated",
|
||||
"syntect",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "rusty_duck"
|
||||
name = "staticrustator"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ pub fn get_all_markdowns() -> Vec<IndexPostEntry> {
|
|||
Ok(iter) => iter,
|
||||
Err(err) => panic!("couldnt ls files, err {err}")
|
||||
};
|
||||
|
||||
for entry in mr_dir_iter {
|
||||
if let Ok(entry) = entry {
|
||||
|
||||
|
|
|
@ -10,10 +10,7 @@ pub fn index() -> 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()
|
||||
|
@ -21,12 +18,11 @@ pub fn about() -> String {
|
|||
|
||||
|
||||
pub fn blog(blog_path:String) -> String {
|
||||
|
||||
match get_blog_entry_markdown(&blog_path){
|
||||
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()
|
||||
BlogTemplate{
|
||||
blog_content: &parse_markdown(markdown.content()),
|
||||
front_matter:&serde_yaml::from_str(markdown.front_matter()).unwrap()}.to_string()
|
||||
,
|
||||
Err(..) => not_found(),
|
||||
}
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -12,25 +12,31 @@ fn main() {
|
|||
match DirBuilder::new()
|
||||
.recursive(true)
|
||||
.create(output_path) {
|
||||
Ok(_) => (),
|
||||
Err(_) => (),
|
||||
Ok(()) => (),
|
||||
Err(err) => if err.kind() == std::io::ErrorKind::AlreadyExists {
|
||||
() // if folder already exists we can continue
|
||||
} else {
|
||||
panic!("Error detected: {err}")
|
||||
}
|
||||
}
|
||||
|
||||
match copy_dir_all("assets", format!("{output_path}/assets")) {
|
||||
Ok(_) => (),
|
||||
Ok(()) => (),
|
||||
Err(err) => println!("Couldnt copy assets directory, err: {err}"),
|
||||
}
|
||||
|
||||
|
||||
|
||||
write(format!("{output_path}/index.html"), handlers::index().as_bytes()).expect("Couldnt write index file");
|
||||
write(format!("{output_path}/about.html"), handlers::about().as_bytes()).expect("Couldnt write about file");
|
||||
write(format!("{output_path}/404.html"), handlers::not_found().as_bytes()).expect("Couldnt write 404 file");
|
||||
|
||||
match DirBuilder::new()
|
||||
.create(format!("{output_path}/blog")) {
|
||||
Ok(_) => (),
|
||||
Err(err) => println!("Error detected: {err}"),
|
||||
Ok(()) => (),
|
||||
Err(err) => if err.kind() == std::io::ErrorKind::AlreadyExists {
|
||||
() // if folder already exists we can continue
|
||||
} else {
|
||||
panic!("Error detected: {err}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
use rand::Rng;
|
||||
|
||||
/// Generates a random quote from a vec of &str present in the function body.
|
||||
pub fn get_quote() -> &'static str {
|
||||
// originally while dynamically server it would generate a new quote every time index would be
|
||||
// reloaded, but with static serve nature a new quote is written every new build.
|
||||
// Maybe not worth it.
|
||||
// feel free to remove
|
||||
let vs = vec![
|
||||
"Silliness and tomfooler are afoot, and who am I to stop it.",
|
||||
"Low entropy self replicating phenomenon that generates a binding force called compassion.",
|
||||
|
|
Loading…
Reference in a new issue