use http::header::{CACHE_CONTROL, CONTENT_TYPE}; use topcoat::{ Result, context::Cx, router::{Body, content::Css, error::not_found, path_param, route}, }; path_param!(file); #[route(GET "/main.css")] pub async fn stylesheet(cx: &Cx) -> Result> { Ok(Css(include_str!("../../assets/main.css"))) } #[route(GET "/favicon.ico")] pub async fn favicon(cx: &Cx) -> Result> { Ok(http::Response::builder() .header(CONTENT_TYPE, "image/x-icon") .body(Body::from(&include_bytes!("../../assets/favicon.ico")[..]))?) } #[route(GET "/nav.js")] pub async fn nav(cx: &Cx) -> Result> { Ok(http::Response::builder() .header(CONTENT_TYPE, "text/javascript; charset=utf-8") .body(Body::from(include_str!("../../assets/nav.js")))?) } #[route(GET "/fonts/{file}")] pub async fn font(cx: &Cx) -> Result> { let bytes: &'static [u8] = match file(cx) { "inter-latin-wght.woff2" => include_bytes!("../../assets/fonts/inter-latin-wght.woff2"), "inter-latin-ext-wght.woff2" => include_bytes!("../../assets/fonts/inter-latin-ext-wght.woff2"), "jetbrains-mono-latin-wght.woff2" => include_bytes!("../../assets/fonts/jetbrains-mono-latin-wght.woff2"), "jetbrains-mono-latin-ext-wght.woff2" => include_bytes!("../../assets/fonts/jetbrains-mono-latin-ext-wght.woff2"), _ => return Err(not_found().into()), }; Ok(http::Response::builder() .header(CONTENT_TYPE, "font/woff2") .header(CACHE_CONTROL, "public, max-age=31536000, immutable") .body(Body::from(bytes))?) }