| 1 | use http::header::{CACHE_CONTROL, CONTENT_TYPE}; |
| 2 | use topcoat::{ |
| 3 | Result, |
| 4 | context::Cx, |
| 5 | router::{Body, content::Css, error::not_found, path_param, route}, |
| 6 | }; |
| 7 | |
| 8 | path_param!(file); |
| 9 | |
| 10 | #[route(GET "/main.css")] |
| 11 | pub async fn stylesheet(cx: &Cx) -> Result<Css<&'static str>> { |
| 12 | Ok(Css(include_str!("../../assets/main.css"))) |
| 13 | } |
| 14 | |
| 15 | #[route(GET "/favicon.ico")] |
| 16 | pub async fn favicon(cx: &Cx) -> Result<http::Response<Body>> { |
| 17 | Ok(http::Response::builder() |
| 18 | .header(CONTENT_TYPE, "image/x-icon") |
| 19 | .body(Body::from(&include_bytes!("../../assets/favicon.ico")[..]))?) |
| 20 | } |
| 21 | |
| 22 | #[route(GET "/nav.js")] |
| 23 | pub async fn nav(cx: &Cx) -> Result<http::Response<Body>> { |
| 24 | Ok(http::Response::builder() |
| 25 | .header(CONTENT_TYPE, "text/javascript; charset=utf-8") |
| 26 | .body(Body::from(include_str!("../../assets/nav.js")))?) |
| 27 | } |
| 28 | |
| 29 | #[route(GET "/fonts/{file}")] |
| 30 | pub async fn font(cx: &Cx) -> Result<http::Response<Body>> { |
| 31 | let bytes: &'static [u8] = match file(cx) { |
| 32 | "inter-latin-wght.woff2" => include_bytes!("../../assets/fonts/inter-latin-wght.woff2"), |
| 33 | "inter-latin-ext-wght.woff2" => include_bytes!("../../assets/fonts/inter-latin-ext-wght.woff2"), |
| 34 | "jetbrains-mono-latin-wght.woff2" => include_bytes!("../../assets/fonts/jetbrains-mono-latin-wght.woff2"), |
| 35 | "jetbrains-mono-latin-ext-wght.woff2" => include_bytes!("../../assets/fonts/jetbrains-mono-latin-ext-wght.woff2"), |
| 36 | _ => return Err(not_found().into()), |
| 37 | }; |
| 38 | |
| 39 | Ok(http::Response::builder() |
| 40 | .header(CONTENT_TYPE, "font/woff2") |
| 41 | .header(CACHE_CONTROL, "public, max-age=31536000, immutable") |
| 42 | .body(Body::from(bytes))?) |
| 43 | } |