From fcdc5c986436c70139f897c81205b850e1ee46fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ci=C4=99=C5=BCarkiewicz?= Date: Mon, 11 May 2020 11:39:54 -0700 Subject: [PATCH] Misc fixes --- src/index.rs | 11 +++++------ src/main.rs | 12 ++++++++++-- src/page.rs | 3 ++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/index.rs b/src/index.rs index 5154bcb..80dfb55 100644 --- a/src/index.rs +++ b/src/index.rs @@ -88,16 +88,15 @@ where } } - let unmatched_tags_set: HashSet = unmatched_tags.keys().cloned().collect(); - let mut pages: Vec = results .matching_pages .into_iter() .filter(|page_info| { - unmatched_tags_set - .intersection(&self.tags_by_page_id[&page_info.id]) - .next() - .is_none() + self.tags_by_page_id[&page_info.id] + .iter() + .filter(|page_tag| !matching_tags.contains(page_tag.as_str())) + .count() + < 5 }) .collect(); diff --git a/src/main.rs b/src/main.rs index c6ff108..2529bb2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -186,12 +186,12 @@ fn render_post_list( ul { @ for tag in unmatched_tags { li { - a(href=format!("./{}", tag.0)) : format!("{} ({})", tag.0, tag.1) + a(href=format!("./{}/", tag.0)) : format!("{} ({})", tag.0, tag.1) } } @ for post in posts { li { - a(href=format!("?id={}", post.id)) : post.title + a(href=format!("./?id={}", post.id)) : post.title } } } @@ -347,6 +347,14 @@ async fn handle_get( path: FullPath, query: GetParams, ) -> Result> { + // rediect anything that does not end with `/` + // This way relative links always work as expected. + if !path.as_str().ends_with('/') { + return Ok(Box::new(warp_temporary_redirect(&format!( + "{}/", + path.as_str() + )))); + } let tags = path_to_tags(&path); let read = state.page_store.read().await; diff --git a/src/page.rs b/src/page.rs index 36a15d5..34427b2 100644 --- a/src/page.rs +++ b/src/page.rs @@ -106,7 +106,8 @@ impl Headers { fn parse_tags(body: &str) -> Vec { lazy_static! { - static ref RE: regex::Regex = regex::Regex::new(r"#([a-zA-Z0-9]+)").expect("correct regex"); + static ref RE: regex::Regex = + regex::Regex::new(r"#([a-zA-Z0-9_\-]+)").expect("correct regex"); } RE.captures_iter(&body)