diff --git a/src/main.rs b/src/main.rs index 430a203..7f19f09 100644 --- a/src/main.rs +++ b/src/main.rs @@ -196,7 +196,7 @@ async fn render( // If the path is not a markdown file (e.g. photos), just return it as it is. if full_path.exists() && !path.ends_with(".md") { - return Ok(NamedFile::open(full_path)?.into_response(&request)?); + return NamedFile::open(full_path)?.into_response(&request); } // Otherwise, retrieve it and check backlinks @@ -230,7 +230,7 @@ async fn render( }; let page = if path.as_str() != "!graph" { - cache.pages.get(path.as_ref()).clone() + cache.pages.get(path.as_ref()) } else { let mut context = Context::new(); @@ -239,7 +239,7 @@ async fn render( let page_ids: Vec = cache.pages.keys().map(|n| normalize_name(n)).collect(); - &cache.pages.iter().for_each(|(path, page)| { + cache.pages.iter().for_each(|(path, page)| { let normalized_path = normalize_name(path); nodes.push( [("id".to_string(), normalized_path.clone())] @@ -280,9 +280,9 @@ async fn render( .pages .clone() .into_iter() - .filter_map(|(path, page)| match page.timestamp { - Some(ts) => Some((path, SystemTime::now().duration_since(ts).unwrap())), - None => None, + .filter_map(|(path, page)| { + page.timestamp + .map(|ts| (path, SystemTime::now().duration_since(ts).unwrap())) }) .collect::>(); recently_changed.sort_by_key(|i| i.1); @@ -430,7 +430,7 @@ fn update_garden>( ); } - let result = GardenCache { files, pages }; + let result = GardenCache { pages, files }; trace!("{:#?}", result); Ok(result) } @@ -576,5 +576,5 @@ fn postprocess_html>(document: T) -> anyhow::Result { fn normalize_name(filename: &str) -> String { let decoded = percent_decode_str(filename).decode_utf8_lossy(); let result = decoded.strip_suffix(".md"); - String::from(result.unwrap_or(decoded.as_ref())) + String::from(result.unwrap_or_else(|| decoded.as_ref())) }