aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/style.rs
blob: 9a7fc48740862b14fe7237a1258044b7509b9049 (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
59
60
61
62
63
64
65
66
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())
}