diff options
Diffstat (limited to 'server/src/routes/ui/style/mod.rs')
-rw-r--r-- | server/src/routes/ui/style/mod.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/server/src/routes/ui/style/mod.rs b/server/src/routes/ui/style/mod.rs new file mode 100644 index 0000000..f3d751b --- /dev/null +++ b/server/src/routes/ui/style/mod.rs @@ -0,0 +1,51 @@ +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) { + read_to_string( + PathBuf::from_str(file!()) + .unwrap() + .parent() + .unwrap() + .join("layout.css"), + ) + .unwrap() + } else { + include_str!("layout.css").to_string() + } +} +fn font_bundle() -> Vec<u8> { + 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<u8>) { + (ContentType::WOFF2, font_bundle()) +} |