use rocket::{get, http::ContentType}; use std::{ fs::{read_to_string, File}, io::Read, path::PathBuf, str::FromStr, }; fn css_bundle() -> String { if cfg!(debug_assertions) { ["layout.css", "player.css"] .into_iter() .map(|n| { read_to_string( PathBuf::from_str(file!()) .unwrap() .parent() .unwrap() .join(n), ) .unwrap() }) .collect::>() .join("\n") } else { concat!(include_str!("layout.css"), include_str!("player.css")).to_string() } } fn font_bundle() -> Vec { if cfg!(debug_assertions) { let mut woff = Vec::new(); File::open( PathBuf::from_str(file!()) .unwrap() .parent() .unwrap() .join("cantarell.woff2"), ) .unwrap() .read_to_end(&mut woff) .unwrap(); woff } else { include_bytes!("cantarell.woff2").to_vec() } } #[get("/assets/style.css")] pub fn r_assets_style() -> (ContentType, String) { (ContentType::CSS, css_bundle()) } #[get("/assets/cantarell.woff2")] pub fn r_assets_font() -> (ContentType, Vec) { (ContentType::WOFF2, font_bundle()) }