aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cantarell.woff2bin0 -> 93888 bytes
-rw-r--r--src/main.rs47
-rw-r--r--src/style.css9
-rw-r--r--src/web.rs5
4 files changed, 49 insertions, 12 deletions
diff --git a/src/cantarell.woff2 b/src/cantarell.woff2
new file mode 100644
index 0000000..76fd894
--- /dev/null
+++ b/src/cantarell.woff2
Binary files differ
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;
}
diff --git a/src/web.rs b/src/web.rs
index b0d2ca9..8aa7a2a 100644
--- a/src/web.rs
+++ b/src/web.rs
@@ -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!(