refactor: move common head stuff into own function for reuse

This commit is contained in:
dusk 2024-06-11 00:54:56 +03:00
parent fdb16dcb38
commit 19039168ae
Signed by: dusk
SSH Key Fingerprint: SHA256:Abmvag+juovVufZTxyWY8KcVgrznxvBjQpJesv071Aw
2 changed files with 14 additions and 13 deletions

View File

@ -34,16 +34,10 @@ where
impl IntoResponse for AppError { impl IntoResponse for AppError {
fn into_response(self) -> axum::response::Response { fn into_response(self) -> axum::response::Response {
let title = crate::get_conf("SITE_TITLE");
let pre_escaped = maud::html! { let pre_escaped = maud::html! {
(maud::DOCTYPE) (maud::DOCTYPE)
head { head {
meta charset="utf8"; (crate::get_page_head_common())
link rel="preconnect" href="https://fonts.googleapis.com";
link rel="preconnect" href="https://fonts.gstatic.com" crossorigin;
link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Kode+Mono&display=swap";
title { (title) }
} }
body style=(crate::BODY_STYLE) { body style=(crate::BODY_STYLE) {
p style=(format!("{} font-size: 1.3em;", crate::IMG_STYLE)) { p style=(format!("{} font-size: 1.3em;", crate::IMG_STYLE)) {

View File

@ -8,6 +8,7 @@ use dashmap::DashMap;
use data::{Art, ArtKind, Data}; use data::{Art, ArtKind, Data};
use error::AppResult; use error::AppResult;
use http::Uri; use http::Uri;
use maud::PreEscaped;
use std::{ use std::{
ops::Deref, ops::Deref,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
@ -68,8 +69,18 @@ const BODY_STYLE: &str =
const IMG_STYLE: &str = "display: block; margin: auto; max-height: 100vh; max-width: 100vw;"; const IMG_STYLE: &str = "display: block; margin: auto; max-height: 100vh; max-width: 100vw;";
const ABOUT_STYLE: &str = "position: absolute; bottom: 0; font-size: 0.75em; color: #ffffff; background-color: #0e0e0eaa;"; const ABOUT_STYLE: &str = "position: absolute; bottom: 0; font-size: 0.75em; color: #ffffff; background-color: #0e0e0eaa;";
fn render_page(art: &Art, image_link: &str) -> Html<String> { fn get_page_head_common() -> PreEscaped<String> {
let title = get_conf("SITE_TITLE"); let title = get_conf("SITE_TITLE");
maud::html! {
meta charset="utf8";
link rel="preconnect" href="https://fonts.googleapis.com";
link rel="preconnect" href="https://fonts.gstatic.com" crossorigin;
link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Kode+Mono&display=swap";
title { (title) }
}
}
fn render_page(art: &Art, image_link: &str) -> Html<String> {
let embed_title = get_conf("EMBED_TITLE"); let embed_title = get_conf("EMBED_TITLE");
let embed_content = get_conf("EMBED_DESC"); let embed_content = get_conf("EMBED_DESC");
let embed_color = get_conf("EMBED_COLOR"); let embed_color = get_conf("EMBED_COLOR");
@ -77,14 +88,10 @@ fn render_page(art: &Art, image_link: &str) -> Html<String> {
let content = maud::html! { let content = maud::html! {
(maud::DOCTYPE) (maud::DOCTYPE)
head { head {
meta charset="utf8"; (get_page_head_common())
meta property="og:title" content=(embed_title); meta property="og:title" content=(embed_title);
meta property="og:description" content=(embed_content); meta property="og:description" content=(embed_content);
meta name="theme-color" content=(embed_color); meta name="theme-color" content=(embed_color);
link rel="preconnect" href="https://fonts.googleapis.com";
link rel="preconnect" href="https://fonts.gstatic.com" crossorigin;
link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Kode+Mono&display=swap";
title { (title) }
} }
body style=(BODY_STYLE) { body style=(BODY_STYLE) {
img style=(IMG_STYLE) src=(image_link); img style=(IMG_STYLE) src=(image_link);