diff options
author | metamuffin <metamuffin@disroot.org> | 2023-10-01 10:14:20 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-10-01 10:14:20 +0200 |
commit | 3fa55dba1b0ca408a10e7456a6d4308dd114c2f6 (patch) | |
tree | f1f378662406a5f091816ca97c3f1ccfb5210eef /server/src/routes/ui/style.rs | |
parent | d857684dd6358fb5ff979ca09ac78b5649b0f411 (diff) | |
download | jellything-3fa55dba1b0ca408a10e7456a6d4308dd114c2f6.tar jellything-3fa55dba1b0ca408a10e7456a6d4308dd114c2f6.tar.bz2 jellything-3fa55dba1b0ca408a10e7456a6d4308dd114c2f6.tar.zst |
move stylesheets and refactor js bundler
Diffstat (limited to 'server/src/routes/ui/style.rs')
-rw-r--r-- | server/src/routes/ui/style.rs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/server/src/routes/ui/style.rs b/server/src/routes/ui/style.rs new file mode 100644 index 0000000..9a7fc48 --- /dev/null +++ b/server/src/routes/ui/style.rs @@ -0,0 +1,67 @@ +/* + 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 <metamuffin.org> + Copyright (C) 2023 tpart +*/ +use rocket::{get, http::ContentType}; + +macro_rules! concat_files { + ([$base: expr], $($files:literal),*) => {{ + #[cfg(debug_assertions)] + { + use std::{fs::read_to_string, path::PathBuf, str::FromStr}; + [ $($files),* ] + .into_iter() + .map(|n| { + read_to_string( + PathBuf::from_str(file!()).unwrap() + .parent().unwrap() + .parent().unwrap() + .parent().unwrap() + .join(n), + ) + .unwrap() + }) + .collect::<Vec<_>>() + .join("\n") + } + #[cfg(not(debug_assertions))] + concat!($(include_str!(concat!($base, "/", $files))),*).to_string() + }}; +} + +fn css_bundle() -> String { + concat_files!(["../../../../web"], + "layout.css", + "player.css", + "nodepage.css", + "nodecard.css", + "js-player.css", + "forms.css" + ) +} + +fn js_bundle() -> String { + concat_files!([env!("OUT_DIR")], + "bundle.js" + ) +} + +#[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, &'static [u8]) { + ( + ContentType::WOFF2, + include_bytes!("../../../../web/cantarell.woff2"), + ) +} + +#[get("/assets/bundle.js")] +pub fn r_assets_js() -> (ContentType, String) { + (ContentType::JavaScript, js_bundle()) +} |