mirror of
https://github.com/redlib-org/redlib.git
synced 2025-06-24 18:10:58 +00:00
Fix search pages
This commit is contained in:
parent
5d26b5c764
commit
a3384cbaa6
3 changed files with 33 additions and 18 deletions
|
@ -4,20 +4,26 @@ use actix_web::{HttpRequest, HttpResponse};
|
|||
use askama::Template;
|
||||
|
||||
// STRUCTS
|
||||
struct SearchParams {
|
||||
q: String,
|
||||
sort: String,
|
||||
t: String,
|
||||
before: String,
|
||||
after: String,
|
||||
restrict_sr: String,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "search.html", escape = "none")]
|
||||
struct SearchTemplate {
|
||||
posts: Vec<Post>,
|
||||
query: String,
|
||||
sub: String,
|
||||
sort: (String, String),
|
||||
ends: (String, String),
|
||||
params: SearchParams,
|
||||
}
|
||||
|
||||
// SERVICES
|
||||
pub async fn find(req: HttpRequest) -> HttpResponse {
|
||||
let path = format!("{}.json?{}", req.path(), req.query_string());
|
||||
let q = param(&path, "q");
|
||||
let sort = if param(&path, "sort").is_empty() {
|
||||
"relevance".to_string()
|
||||
} else {
|
||||
|
@ -29,10 +35,15 @@ pub async fn find(req: HttpRequest) -> HttpResponse {
|
|||
Ok(posts) => HttpResponse::Ok().content_type("text/html").body(
|
||||
SearchTemplate {
|
||||
posts: posts.0,
|
||||
query: q,
|
||||
sub,
|
||||
sort: (sort, param(&path, "t")),
|
||||
ends: (param(&path, "after"), posts.1),
|
||||
params: SearchParams {
|
||||
q: param(&path, "q"),
|
||||
sort,
|
||||
t: param(&path, "t"),
|
||||
before: param(&path, "after"),
|
||||
after: posts.1,
|
||||
restrict_sr: param(&path, "restrict_sr"),
|
||||
},
|
||||
}
|
||||
.render()
|
||||
.unwrap(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue