From a87c3f3ad3fdf22f42d0b01857e4a3e7a4741cd4 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Thu, 14 Sep 2023 19:02:13 +0200 Subject: [PATCH] update --- Cargo.lock | 2 +- src/pages/html_fn.rs | 26 +++++--------------------- src/pages/index.rs | 8 +++++--- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3307f12..04837f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1788,7 +1788,7 @@ checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "web-base" version = "0.2.0" -source = "git+https://git.hydrar.de/jmarya/web-base#dc5c22175bb58e554ebfd19a493be3631c9be40c" +source = "git+https://git.hydrar.de/jmarya/web-base#3331a088cb4afab6596dca120825d76ce5be6a62" dependencies = [ "actix-files", "actix-web", diff --git a/src/pages/html_fn.rs b/src/pages/html_fn.rs index 28d697e..1f5b173 100644 --- a/src/pages/html_fn.rs +++ b/src/pages/html_fn.rs @@ -1,6 +1,6 @@ use crate::config::Config; -use actix_web::web::Data; use actix_web::HttpResponse; +use actix_web::{web::Data, HttpRequest}; use maud::{html, PreEscaped}; pub(crate) async fn build_site( @@ -9,13 +9,8 @@ pub(crate) async fn build_site( disable_color: bool, shadow: bool, config: &Data, + r: &HttpRequest, ) -> HttpResponse { - let bootstrap = html! { - link href="/bootstrap.min.css" rel="stylesheet"; - link href="/bootstrap-icons.css" rel="stylesheet"; - link href="/bootstrap.bundle.min.js" rel="stylesheet"; - }; - let mut c_class = "bg-dark text-white justify-content-center text-center".to_string(); let mut c_style = String::new(); let mut g_style = "a {text-decoration: none; font-weight: bold; color: white}".to_string(); @@ -33,23 +28,12 @@ pub(crate) async fn build_site( c_style.push_str("text-shadow: 1px 1px 3px black;"); } - let r = html! { - (maud::DOCTYPE) - html { - head { - title { - (title) - }; - (bootstrap) - }; + let body = html! { body style=(c_style) class=(c_class) { style { (g_style) }; (PreEscaped(content)) - } - }; + }; }; - HttpResponse::Ok() - .message_body(r.into_string()) - .expect("could not build page") + web_base::func::build_site_from_body(r, title, &body.into_string()) } diff --git a/src/pages/index.rs b/src/pages/index.rs index effb0a5..c0d3f67 100644 --- a/src/pages/index.rs +++ b/src/pages/index.rs @@ -41,7 +41,7 @@ pub async fn message_page(r: HttpRequest) -> impl Responder { } }; - pages::html_fn::build_site(resp.into_string(), "Message", false, true, config).await + pages::html_fn::build_site(resp.into_string(), "Message", false, true, config, &r).await } #[get("/mirrors.txt")] @@ -63,6 +63,7 @@ pub async fn mirrors(r: HttpRequest) -> Result { false, true, config, + &r, ) .await); } @@ -104,6 +105,7 @@ pub async fn public_key(r: HttpRequest) -> Result { true, false, config, + &r, ) .await); } @@ -181,7 +183,7 @@ fn build_donation_block(conf: &web::Data) -> String { } #[get("/")] -pub(crate) async fn index(conf: web::Data) -> impl Responder { +pub(crate) async fn index(conf: web::Data, r: HttpRequest) -> impl Responder { let information_block = build_information_block(&conf); let contact_block = build_contact_block(&conf); let donation_block = build_donation_block(&conf); @@ -192,5 +194,5 @@ pub(crate) async fn index(conf: web::Data) -> impl Responder { {donation_block} " ); - crate::pages::html_fn::build_site(content, "About Me", false, true, &conf).await + crate::pages::html_fn::build_site(content, "About Me", false, true, &conf, &r).await }