//! Compiled-in static assets: the stylesheet, fonts and icons. use axum::extract::Path; use axum::http::{header, StatusCode}; use axum::response::{IntoResponse, Response}; const CSS: &str = include_str!("../../../../templates/style.css"); const FAVICON: &str = include_str!("../../../../assets/icons/oxygenhub.svg"); struct Asset { path: &'static str, mime: &'static str, bytes: &'static [u8], } const ASSETS: &[Asset] = &[ Asset { path: "fonts/Barlow-300.woff2", mime: "font/woff2", bytes: include_bytes!("../../../../assets/fonts/Barlow-300.woff2") }, Asset { path: "fonts/Barlow-400.woff2", mime: "font/woff2", bytes: include_bytes!("../../../../assets/fonts/Barlow-400.woff2") }, Asset { path: "fonts/Barlow-500.woff2", mime: "font/woff2", bytes: include_bytes!("../../../../assets/fonts/Barlow-500.woff2") }, Asset { path: "fonts/Barlow-600.woff2", mime: "font/woff2", bytes: include_bytes!("../../../../assets/fonts/Barlow-600.woff2") }, Asset { path: "fonts/PressStart2P-400.woff2", mime: "font/woff2", bytes: include_bytes!("../../../../assets/fonts/PressStart2P-400.woff2"), }, Asset { path: "hub.js", mime: "text/javascript; charset=utf-8", bytes: include_bytes!("../../../../assets/hub.js") }, ]; const CACHE: &str = "public, max-age=86400"; pub async fn style() -> Response { ([(header::CONTENT_TYPE, "text/css; charset=utf-8"), (header::CACHE_CONTROL, CACHE)], CSS).into_response() } pub async fn favicon() -> Response { ([(header::CONTENT_TYPE, "image/svg+xml"), (header::CACHE_CONTROL, CACHE)], FAVICON).into_response() } pub async fn asset(Path(path): Path) -> Response { match ASSETS.iter().find(|a| a.path == path) { Some(a) => { ([(header::CONTENT_TYPE, a.mime), (header::CACHE_CONTROL, "public, max-age=31536000, immutable")], a.bytes).into_response() } None => StatusCode::NOT_FOUND.into_response(), } }