From 64c4d2c23a3eb8355191f2efdab71bb0aeabb882 Mon Sep 17 00:00:00 2001 From: neon_arch Date: Fri, 17 Nov 2023 22:12:25 +0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20refactor(routes):=20ser?= =?UTF-8?q?ve=20new=20the=20maud=20files=20instead=20of=20handlebars=20fil?= =?UTF-8?q?es=20(#302)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/router.rs | 47 +++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/server/router.rs b/src/server/router.rs index 69a3ede..48f0d77 100644 --- a/src/server/router.rs +++ b/src/server/router.rs @@ -7,30 +7,30 @@ use crate::{ handler::paths::{file_path, FileType}, }; use actix_web::{get, web, HttpRequest, HttpResponse}; -use handlebars::Handlebars; use std::fs::read_to_string; /// Handles the route of index page or main page of the `websurfx` meta search engine website. #[get("/")] -pub async fn index( - hbs: web::Data>, - config: web::Data, -) -> Result> { - let page_content: String = hbs.render("index", &config.style).unwrap(); - Ok(HttpResponse::Ok().body(page_content)) +pub async fn index(config: web::Data) -> Result> { + Ok(HttpResponse::Ok().body( + crate::templates::views::index::index(&config.style.colorscheme, &config.style.theme, "").0, + )) } /// Handles the route of any other accessed route/page which is not provided by the /// website essentially the 404 error page. pub async fn not_found( - hbs: web::Data>, config: web::Data, ) -> Result> { - let page_content: String = hbs.render("404", &config.style)?; - Ok(HttpResponse::Ok() .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. @@ -45,20 +45,27 @@ pub async fn robots_data(_req: HttpRequest) -> Result>, - config: web::Data, -) -> Result> { - let page_content: String = hbs.render("about", &config.style)?; - Ok(HttpResponse::Ok().body(page_content)) +pub async fn about(config: web::Data) -> Result> { + Ok(HttpResponse::Ok().body( + crate::templates::views::about::about(&config.style.colorscheme, &config.style.theme).0, + )) } /// Handles the route of settings page of the `websurfx` meta search engine website. #[get("/settings")] pub async fn settings( - hbs: web::Data>, config: web::Data, ) -> Result> { - let page_content: String = hbs.render("settings", &config.style)?; - Ok(HttpResponse::Ok().body(page_content)) + Ok(HttpResponse::Ok().body( + crate::templates::views::settings::settings( + &config.style.colorscheme, + &config.style.theme, + &config + .upstream_search_engines + .iter() + .map(|(engine, _)| engine) + .collect::>(), + )? + .0, + )) }