/* This file is part of jellything (https://codeberg.org/metamuffin/jellything) which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2023 metamuffin Copyright (C) 2023 tpart */ 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", "itempage.css", "directorypage.css", "forms.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"), include_str!("itempage.css"), include_str!("directorypage.css"), include_str!("forms.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() } } fn js_bundle() -> String { if cfg!(debug_assertions) { ["transition.js"] .into_iter() .map(|n| { read_to_string( PathBuf::from_str(file!()) .unwrap() .parent() .unwrap() .join(n), ) .unwrap() }) .collect::>() .join("\n") } else { include_str!("transition.js").to_string() } } #[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()) } #[get("/assets/bundle.js")] pub fn r_assets_js() -> (ContentType, String) { (ContentType::JavaScript, js_bundle()) }