diff options
Diffstat (limited to 'server/src/ui/style.rs')
| -rw-r--r-- | server/src/ui/style.rs | 47 |
1 files changed, 5 insertions, 42 deletions
diff --git a/server/src/ui/style.rs b/server/src/ui/style.rs index 5226b6a..2b7d2de 100644 --- a/server/src/ui/style.rs +++ b/server/src/ui/style.rs @@ -4,50 +4,13 @@ Copyright (C) 2026 metamuffin <metamuffin.org> Copyright (C) 2023 tpart */ +use jellyui::{css_bundle, js_bundle, js_bundle_map}; use rocket::{ get, http::{ContentType, Header}, response::Responder, }; - -macro_rules! concat_files { - ([$base: expr], $($files:literal),*) => {{ - #[cfg(any(debug_assertions, feature = "hot-css"))] - { - use std::{fs::read_to_string, path::PathBuf, str::FromStr}; - [ $($files),* ] - .into_iter() - .map(|n| { - read_to_string({ - let p = PathBuf::from_str(file!()).unwrap().parent().unwrap().join($base).join(n); - log::info!("load {p:?}"); - p - }) - .unwrap() - }) - .collect::<Vec<_>>() - .join("\n") - } - #[cfg(not(any(debug_assertions, feature = "hot-css")))] - concat!($(include_str!(concat!($base, "/", $files))),*).to_string() - }}; -} - -fn css_bundle() -> String { - concat_files!( - ["../../../web/style"], - "layout.css", - "player.css", - "nodepage.css", - "nodecard.css", - "js-player.css", - "js-transition.css", - "forms.css", - "props.css", - "themes.css", - "navbar.css" - ) -} +use std::borrow::Cow; pub struct CachedAsset<T>(pub T); impl<'r, 'o: 'r, T: Responder<'r, 'o>> Responder<'r, 'o> for CachedAsset<T> { @@ -61,7 +24,7 @@ impl<'r, 'o: 'r, T: Responder<'r, 'o>> Responder<'r, 'o> for CachedAsset<T> { } #[get("/assets/style.css")] -pub fn r_assets_style() -> CachedAsset<(ContentType, String)> { +pub fn r_assets_style() -> CachedAsset<(ContentType, Cow<'static, str>)> { CachedAsset((ContentType::CSS, css_bundle())) } @@ -74,10 +37,10 @@ pub fn r_assets_font() -> CachedAsset<(ContentType, &'static [u8])> { } #[get("/assets/bundle.js")] -pub fn r_assets_js() -> CachedAsset<(ContentType, String)> { +pub fn r_assets_js() -> CachedAsset<(ContentType, Cow<'static, str>)> { CachedAsset((ContentType::JavaScript, js_bundle())) } #[get("/assets/bundle.js.map")] -pub fn r_assets_js_map() -> CachedAsset<(ContentType, String)> { +pub fn r_assets_js_map() -> CachedAsset<(ContentType, Cow<'static, str>)> { CachedAsset((ContentType::JSON, js_bundle_map())) } |