aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/style/mod.rs
blob: f3d751bbd7f50e4c7a52d24d775783680d66ea6b (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
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) {
        read_to_string(
            PathBuf::from_str(file!())
                .unwrap()
                .parent()
                .unwrap()
                .join("layout.css"),
        )
        .unwrap()
    } else {
        include_str!("layout.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())
}