aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/style/mod.rs
blob: 07e92ddd679903a975f0b121e3f74f2114bac63a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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"]
            .into_iter()
            .map(|n| {
                read_to_string(
                    PathBuf::from_str(file!())
                        .unwrap()
                        .parent()
                        .unwrap()
                        .join(n),
                )
                .unwrap()
            })
            .collect::<Vec<_>>()
            .join("\n")
    } else {
        concat!(include_str!("layout.css"), include_str!("player.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())
}