use std::borrow::Cow; use askama_rocket::Template; use rocket::http::Status; use rust_embed::RustEmbed; #[derive(RustEmbed)] #[folder = "public/"] pub struct PublicAssets; #[derive(Responder)] #[response(status = 200, content_type = "font/woff2")] pub struct RawWoff2Font(pub Cow<'static, [u8]>); #[derive(Responder)] #[response(status = 200, content_type = "font/woff")] pub struct RawWoffFont(pub Cow<'static, [u8]>); #[derive(Template)] #[template(path = "error.html")] pub struct ErrorTemplate<'a> { pub error: &'a str, pub error_description: &'a str } #[derive(Responder)] pub struct ErrorTemplateResponder<'a> { template: ErrorTemplate<'a> } #[get("/style.css")] pub fn style() -> Result, Status> { let style = PublicAssets::get("style.css").unwrap(); match std::str::from_utf8(&style.data) { Ok(style) => Ok(rocket::response::content::RawCss::(style.to_string())), Err(_) => Err(Status::InternalServerError), } } #[get("/woff2/")] pub fn woff2_font(font: &str) -> Result { let latin = "atkinson-hyperlegible-latin-400-normal.woff2"; let latin_ext = "atkinson-hyperlegible-latin-ext-400-normal.woff2"; if font == latin { Ok(RawWoff2Font(PublicAssets::get(latin).unwrap().data)) } else if font == latin_ext { Ok(RawWoff2Font(PublicAssets::get(latin_ext).unwrap().data)) } else { Err(Status::NotFound) } } #[get("/woff/")] pub fn woff_font(font: &str) -> Result { let all = "atkinson-hyperlegible-all-400-normal.woff"; if font == all { Ok(RawWoffFont(PublicAssets::get(all).unwrap().data)) } else { Err(Status::NotFound) } }