diff --git a/src/routes/search.rs b/src/routes/search.rs index 8811925b..f0f1b280 100644 --- a/src/routes/search.rs +++ b/src/routes/search.rs @@ -29,13 +29,11 @@ pub struct SearchQuery { macro_rules! param_to_query { ( $query:ident, $parsed_query:ident; normal: $($field:ident),*; date: $($date:ident),*) => { $( - if let Some(ref field) = $query.$field { - let mut rest = field.as_str(); - while !rest.is_empty() { - let (token, r) = Query::get_first_token(rest); - rest = r; - $parsed_query.$field(token, None); - } + let mut rest = $query.$field.as_ref().map(String::as_str).unwrap_or_default(); + while !rest.is_empty() { + let (token, r) = Query::get_first_token(rest); + rest = r; + $parsed_query.$field(token, None); } )* $( diff --git a/src/template_utils.rs b/src/template_utils.rs index 7e38ba5d..67277534 100644 --- a/src/template_utils.rs +++ b/src/template_utils.rs @@ -75,18 +75,36 @@ pub fn tabs(links: &[(&str, &str, bool)]) -> Html { } pub fn paginate(catalog: &Catalog, page: i32, total: i32) -> Html { + paginate_param(catalog, page, total, None) +} +pub fn paginate_param(catalog: &Catalog, page: i32, total: i32, param: Option) -> Html { let mut res = String::new(); + let param = param.map(|mut p| {p.push('&'); p}).unwrap_or_default(); res.push_str(r#""); Html(res) } +pub fn encode_query_param(param: &str) -> String { + param.chars().map(|c| match c { + '+' => Ok("%2B"), + ' ' => Err('+'), + c => Err(c), + }).fold(String::new(), |mut s,r| { + match r { + Ok(r) => s.push_str(r), + Err(r) => s.push(r), + }; + s + }) +} + #[macro_export] macro_rules! icon { ($name:expr) => { diff --git a/templates/search/result.rs.html b/templates/search/result.rs.html index d17b6729..d94f0888 100644 --- a/templates/search/result.rs.html +++ b/templates/search/result.rs.html @@ -23,5 +23,5 @@ } } - @paginate(ctx.1, page, n_pages) + @paginate_param(ctx.1, page, n_pages, Some(format!("q={}", encode_query_param(query_str)))) })