From 4eb1ae540207ede5416d90543a0f6b56d00de9cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Sun, 25 Jul 2021 14:08:51 +0200 Subject: [PATCH] comments --- src/main.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8d4c77c..e3cd885 100644 --- a/src/main.rs +++ b/src/main.rs @@ -194,10 +194,12 @@ async fn render( .finish()); } + // 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)?); } + // Otherwise, retrieve it and check backlinks let filename = full_path .components() .last() @@ -208,17 +210,6 @@ async fn render( let normalized_name = normalize_name(filename); - let mut recently_changed = cache - .pages - .clone() - .into_iter() - .filter_map(|i| match i.1.timestamp { - Some(ts) => Some((i.0, SystemTime::now().duration_since(ts).unwrap())), - None => None, - }) - .collect::>(); - recently_changed.sort_by_key(|i| i.1); - let mut backlinks: Vec = vec![]; for (path, page) in cache.pages.iter() { if page @@ -232,8 +223,21 @@ async fn render( let page = cache.pages.get(path.as_ref()); + // Recently changed + let mut recently_changed = cache + .pages + .clone() + .into_iter() + .filter_map(|i| match i.1.timestamp { + Some(ts) => Some((i.0, SystemTime::now().duration_since(ts).unwrap())), + None => None, + }) + .collect::>(); + recently_changed.sort_by_key(|i| i.1); + let timeago = timeago::Formatter::new(); + // Render context generation let mut context = Context::new(); context.insert("version", VERSION); context.insert(