From b337306799756470ac69d4c446cda63b8babf22f Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Wed, 8 Apr 2020 17:56:36 +0800 Subject: [PATCH] utils: also kill punctuations when generating URLs --- src/utils.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index bd5dc43..867edd9 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -42,9 +42,9 @@ macro_rules! headers( ); // Remove all non-ascii characters from string -pub fn filter_non_ascii(s: &str) -> String { +pub fn filter_non_ascii_alphanumeric(s: &str) -> String { s.chars().into_iter() - .filter(|c| c.is_ascii()) + .filter(|c| c.is_ascii_alphanumeric() || c.is_whitespace()) .collect() } @@ -53,7 +53,7 @@ pub fn filter_non_ascii(s: &str) -> String { // articles have the same URL by having the same title when // all non-ASCII characters are removed pub fn title_to_url(uuid: &str, title: &str) -> String { - let title_part = filter_non_ascii(title) + let title_part = filter_non_ascii_alphanumeric(title) .split_whitespace() .collect::>() .join("-")