Add nice html formatting for search
This commit is contained in:
@@ -56,8 +56,21 @@ fn search(req: &Request) -> Response {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if let Some(_) = req.get_param("pretty") {
|
||||||
|
return Response::html(search_to_html(response)).with_status_code(200);
|
||||||
|
}
|
||||||
Response::json(&response).with_status_code(200)
|
Response::json(&response).with_status_code(200)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn search_to_html(results: Vec<SearchResult>) -> String {
|
||||||
|
let res_html = results
|
||||||
|
.iter()
|
||||||
|
.map(|res| res.to_html())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join("\n");
|
||||||
|
let body = format!("<ul>{}</ul>", res_html);
|
||||||
|
HTML_TEMPLATE.replace("{body}", &body)
|
||||||
|
}
|
||||||
fn redirect(req: &Request) -> Response {
|
fn redirect(req: &Request) -> Response {
|
||||||
info!("Redirecting request: {:?}", req);
|
info!("Redirecting request: {:?}", req);
|
||||||
|
|
||||||
@@ -184,3 +197,19 @@ mod test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HTML_TEMPLATE: &'static str = r#"
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
<title>AWESM Search Results</title>
|
||||||
|
<link rel="stylesheet" href="/style/search.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{body}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"#;
|
||||||
|
|||||||
Reference in New Issue
Block a user