mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-21 21:48:21 -05:00
♻️ refactor(routes): serve new the maud files instead of handlebars files (#302)
This commit is contained in:
parent
0ec89146c8
commit
64c4d2c23a
@ -7,30 +7,30 @@ use crate::{
|
|||||||
handler::paths::{file_path, FileType},
|
handler::paths::{file_path, FileType},
|
||||||
};
|
};
|
||||||
use actix_web::{get, web, HttpRequest, HttpResponse};
|
use actix_web::{get, web, HttpRequest, HttpResponse};
|
||||||
use handlebars::Handlebars;
|
|
||||||
use std::fs::read_to_string;
|
use std::fs::read_to_string;
|
||||||
|
|
||||||
/// Handles the route of index page or main page of the `websurfx` meta search engine website.
|
/// Handles the route of index page or main page of the `websurfx` meta search engine website.
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
pub async fn index(
|
pub async fn index(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
||||||
hbs: web::Data<Handlebars<'_>>,
|
Ok(HttpResponse::Ok().body(
|
||||||
config: web::Data<Config>,
|
crate::templates::views::index::index(&config.style.colorscheme, &config.style.theme, "").0,
|
||||||
) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
))
|
||||||
let page_content: String = hbs.render("index", &config.style).unwrap();
|
|
||||||
Ok(HttpResponse::Ok().body(page_content))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the route of any other accessed route/page which is not provided by the
|
/// Handles the route of any other accessed route/page which is not provided by the
|
||||||
/// website essentially the 404 error page.
|
/// website essentially the 404 error page.
|
||||||
pub async fn not_found(
|
pub async fn not_found(
|
||||||
hbs: web::Data<Handlebars<'_>>,
|
|
||||||
config: web::Data<Config>,
|
config: web::Data<Config>,
|
||||||
) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
||||||
let page_content: String = hbs.render("404", &config.style)?;
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_type("text/html; charset=utf-8")
|
.content_type("text/html; charset=utf-8")
|
||||||
.body(page_content))
|
.body(
|
||||||
|
crate::templates::views::not_found::not_found(
|
||||||
|
&config.style.colorscheme,
|
||||||
|
&config.style.theme,
|
||||||
|
)
|
||||||
|
.0,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the route of robots.txt page of the `websurfx` meta search engine website.
|
/// Handles the route of robots.txt page of the `websurfx` meta search engine website.
|
||||||
@ -45,20 +45,27 @@ pub async fn robots_data(_req: HttpRequest) -> Result<HttpResponse, Box<dyn std:
|
|||||||
|
|
||||||
/// Handles the route of about page of the `websurfx` meta search engine website.
|
/// Handles the route of about page of the `websurfx` meta search engine website.
|
||||||
#[get("/about")]
|
#[get("/about")]
|
||||||
pub async fn about(
|
pub async fn about(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
||||||
hbs: web::Data<Handlebars<'_>>,
|
Ok(HttpResponse::Ok().body(
|
||||||
config: web::Data<Config>,
|
crate::templates::views::about::about(&config.style.colorscheme, &config.style.theme).0,
|
||||||
) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
))
|
||||||
let page_content: String = hbs.render("about", &config.style)?;
|
|
||||||
Ok(HttpResponse::Ok().body(page_content))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the route of settings page of the `websurfx` meta search engine website.
|
/// Handles the route of settings page of the `websurfx` meta search engine website.
|
||||||
#[get("/settings")]
|
#[get("/settings")]
|
||||||
pub async fn settings(
|
pub async fn settings(
|
||||||
hbs: web::Data<Handlebars<'_>>,
|
|
||||||
config: web::Data<Config>,
|
config: web::Data<Config>,
|
||||||
) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
||||||
let page_content: String = hbs.render("settings", &config.style)?;
|
Ok(HttpResponse::Ok().body(
|
||||||
Ok(HttpResponse::Ok().body(page_content))
|
crate::templates::views::settings::settings(
|
||||||
|
&config.style.colorscheme,
|
||||||
|
&config.style.theme,
|
||||||
|
&config
|
||||||
|
.upstream_search_engines
|
||||||
|
.iter()
|
||||||
|
.map(|(engine, _)| engine)
|
||||||
|
.collect::<Vec<&String>>(),
|
||||||
|
)?
|
||||||
|
.0,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user