diff options
author | metamuffin <metamuffin@disroot.org> | 2024-05-04 14:15:24 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-05-04 14:15:24 +0200 |
commit | a4d49095d1fa40fc7152d069006d1121300235bb (patch) | |
tree | 22577936ef637df2c859be2259d004ba29b6ae2b /src | |
parent | 24b10f4d389fcc5c23406eceef5d6e9a35551d21 (diff) | |
download | statuspage-a4d49095d1fa40fc7152d069006d1121300235bb.tar statuspage-a4d49095d1fa40fc7152d069006d1121300235bb.tar.bz2 statuspage-a4d49095d1fa40fc7152d069006d1121300235bb.tar.zst |
embed font
Diffstat (limited to 'src')
-rw-r--r-- | src/cantarell.woff2 | bin | 0 -> 93888 bytes | |||
-rw-r--r-- | src/main.rs | 47 | ||||
-rw-r--r-- | src/style.css | 9 | ||||
-rw-r--r-- | src/web.rs | 5 |
4 files changed, 49 insertions, 12 deletions
diff --git a/src/cantarell.woff2 b/src/cantarell.woff2 Binary files differnew file mode 100644 index 0000000..76fd894 --- /dev/null +++ b/src/cantarell.woff2 diff --git a/src/main.rs b/src/main.rs index 7f55089..e5cfb31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,14 +6,18 @@ pub mod web; use ::log::error; use anyhow::{anyhow, Result}; -use axum::{routing::get, Router}; +use axum::{response::Html, routing::get, Router}; use check::{check_loop, Check}; use chrono::{DateTime, Utc}; use mail::MailConfig; +use reqwest::{ + header::{CACHE_CONTROL, CONTENT_TYPE, REFRESH}, + StatusCode, +}; use serde::Deserialize; use std::{collections::BTreeMap, net::SocketAddr, process::exit, sync::Arc}; use tokio::{fs::read_to_string, sync::RwLock}; -use web::send_html_page; +use web::make_html_page; pub static GLOBAL_ERROR: RwLock<Option<anyhow::Error>> = RwLock::const_new(None); @@ -63,13 +67,38 @@ async fn run() -> anyhow::Result<()> { tokio::task::spawn(check_loop(config.clone(), i)); } - let app = Router::new().route( - "/", - get({ - let config = config.clone(); - move || send_html_page(config.clone()) - }), - ); + let app = Router::new() + .route( + "/", + get({ + let config = config.clone(); + move || async move { + ( + [ + ( + CACHE_CONTROL, + format!("max-age={}, public", config.interval), + ), + (REFRESH, format!("{}", config.interval)), + ], + Html(make_html_page(config.clone()).await), + ) + } + }), + ) + .route( + "/font.woff2", + get(|| async { + ( + [ + (CONTENT_TYPE, "font/woff2"), + (CACHE_CONTROL, "public, immutable"), + ], + include_bytes!("cantarell.woff2"), + ) + }), + ) + .route("/favicon.ico", get(|| async { StatusCode::NO_CONTENT })); let listener = tokio::net::TcpListener::bind(config.bind).await?; axum::serve(listener, app).await?; Ok(()) diff --git a/src/style.css b/src/style.css index 9c2cb52..4d6abc2 100644 --- a/src/style.css +++ b/src/style.css @@ -1,3 +1,12 @@ +@font-face { + font-family: Cantarell; + src: url(/font.woff2); +} + +* { + font-family: Cantarell; +} + body { background-color: white; } @@ -1,10 +1,9 @@ use crate::{log::LOG, Check, Config, Service, Status, STATUS}; -use axum::response::Html; use chrono::SubsecRound; use markup::{doctype, Render}; use std::{collections::BTreeMap, ops::Deref, sync::Arc}; -pub async fn send_html_page(config: Arc<Config>) -> Html<String> { +pub async fn make_html_page(config: Arc<Config>) -> String { let mut out = String::new(); let status = STATUS.read().await; let status = status.deref(); @@ -54,7 +53,7 @@ pub async fn send_html_page(config: Arc<Config>) -> Html<String> { } .render(&mut out) .unwrap(); - Html(out) + out } markup::define!( |