This commit is contained in:
JMARyA 2023-09-14 19:02:13 +02:00
parent 3b9d6fbd89
commit a87c3f3ad3
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 11 additions and 25 deletions

2
Cargo.lock generated
View file

@ -1788,7 +1788,7 @@ checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
[[package]] [[package]]
name = "web-base" name = "web-base"
version = "0.2.0" 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 = [ dependencies = [
"actix-files", "actix-files",
"actix-web", "actix-web",

View file

@ -1,6 +1,6 @@
use crate::config::Config; use crate::config::Config;
use actix_web::web::Data;
use actix_web::HttpResponse; use actix_web::HttpResponse;
use actix_web::{web::Data, HttpRequest};
use maud::{html, PreEscaped}; use maud::{html, PreEscaped};
pub(crate) async fn build_site( pub(crate) async fn build_site(
@ -9,13 +9,8 @@ pub(crate) async fn build_site(
disable_color: bool, disable_color: bool,
shadow: bool, shadow: bool,
config: &Data<Config>, config: &Data<Config>,
r: &HttpRequest,
) -> HttpResponse<String> { ) -> HttpResponse<String> {
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_class = "bg-dark text-white justify-content-center text-center".to_string();
let mut c_style = String::new(); let mut c_style = String::new();
let mut g_style = "a {text-decoration: none; font-weight: bold; color: white}".to_string(); 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;"); c_style.push_str("text-shadow: 1px 1px 3px black;");
} }
let r = html! { let body = html! {
(maud::DOCTYPE)
html {
head {
title {
(title)
};
(bootstrap)
};
body style=(c_style) class=(c_class) { body style=(c_style) class=(c_class) {
style { (g_style) }; style { (g_style) };
(PreEscaped(content)) (PreEscaped(content))
} };
};
}; };
HttpResponse::Ok() web_base::func::build_site_from_body(r, title, &body.into_string())
.message_body(r.into_string())
.expect("could not build page")
} }

View file

@ -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")] #[get("/mirrors.txt")]
@ -63,6 +63,7 @@ pub async fn mirrors(r: HttpRequest) -> Result<impl Responder, Error> {
false, false,
true, true,
config, config,
&r,
) )
.await); .await);
} }
@ -104,6 +105,7 @@ pub async fn public_key(r: HttpRequest) -> Result<impl Responder, Error> {
true, true,
false, false,
config, config,
&r,
) )
.await); .await);
} }
@ -181,7 +183,7 @@ fn build_donation_block(conf: &web::Data<config::Config>) -> String {
} }
#[get("/")] #[get("/")]
pub(crate) async fn index(conf: web::Data<config::Config>) -> impl Responder { pub(crate) async fn index(conf: web::Data<config::Config>, r: HttpRequest) -> impl Responder {
let information_block = build_information_block(&conf); let information_block = build_information_block(&conf);
let contact_block = build_contact_block(&conf); let contact_block = build_contact_block(&conf);
let donation_block = build_donation_block(&conf); let donation_block = build_donation_block(&conf);
@ -192,5 +194,5 @@ pub(crate) async fn index(conf: web::Data<config::Config>) -> impl Responder {
{donation_block} {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
} }