1
0
mirror of https://github.com/dpc/tagwiki synced 2024-11-15 21:24:50 +00:00

Misc fixes

This commit is contained in:
Dawid Ciężarkiewicz 2020-05-11 11:39:54 -07:00
parent f28a73a301
commit fcdc5c9864
3 changed files with 17 additions and 9 deletions

View File

@ -88,16 +88,15 @@ where
}
}
let unmatched_tags_set: HashSet<Tag> = unmatched_tags.keys().cloned().collect();
let mut pages: Vec<PageInfo> = 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();

View File

@ -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<Box<dyn warp::Reply>> {
// 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;

View File

@ -106,7 +106,8 @@ impl Headers {
fn parse_tags(body: &str) -> Vec<String> {
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)