aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/style/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/routes/ui/style/mod.rs')
-rw-r--r--server/src/routes/ui/style/mod.rs112
1 files changed, 37 insertions, 75 deletions
diff --git a/server/src/routes/ui/style/mod.rs b/server/src/routes/ui/style/mod.rs
index 93b6708..e1ba17b 100644
--- a/server/src/routes/ui/style/mod.rs
+++ b/server/src/routes/ui/style/mod.rs
@@ -5,86 +5,48 @@
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()
+macro_rules! concat_files {
+ ($($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()
+ .join(n),
+ )
.unwrap()
- .join(n),
- )
- .unwrap()
- })
- .collect::<Vec<_>>()
- .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()
- }
+ })
+ .collect::<Vec<_>>()
+ .join("\n")
+ }
+ #[cfg(not(debug_assertions))]
+ concat!($(include_str!($files)),*).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()
- }
+fn css_bundle() -> String {
+ concat_files!(
+ "layout.css",
+ "player.css",
+ "itempage.css",
+ "directorypage.css",
+ "js-player.css",
+ "forms.css"
+ )
}
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::<Vec<_>>()
- .join("\n")
- } else {
- include_str!("transition.js").to_string()
- }
+ concat_files!(
+ // "transition.js",
+ "js-player.js"
+ )
}
#[get("/assets/style.css")]
@@ -93,8 +55,8 @@ pub fn r_assets_style() -> (ContentType, String) {
}
#[get("/assets/cantarell.woff2")]
-pub fn r_assets_font() -> (ContentType, Vec<u8>) {
- (ContentType::WOFF2, font_bundle())
+pub fn r_assets_font() -> (ContentType, &'static [u8]) {
+ (ContentType::WOFF2, include_bytes!("cantarell.woff2"))
}
#[get("/assets/bundle.js")]