OXYGENHUB
# 34beb1a7e376 oxygenhub / crates / hub / src / web / statics.rs
2.4 KiB · Rust · last changed Web edits and browser conflict resolution; landing under a policy 1 month ago source blame history raw
1
//! Compiled-in static assets: the stylesheet, fonts and icons.
2
3
use axum::extract::Path;
4
use axum::http::{header, StatusCode};
5
use axum::response::{IntoResponse, Response};
6
7
const CSS: &str = include_str!("../../../../templates/style.css");
8
const FAVICON: &str = include_str!("../../../../assets/icons/oxygenhub.svg");
9
10
struct Asset {
11
    path: &'static str,
12
    mime: &'static str,
13
    bytes: &'static [u8],
14
}
15
16
const ASSETS: &[Asset] = &[
17
    Asset { path: "fonts/Barlow-300.woff2", mime: "font/woff2", bytes: include_bytes!("../../../../assets/fonts/Barlow-300.woff2") },
18
    Asset { path: "fonts/Barlow-400.woff2", mime: "font/woff2", bytes: include_bytes!("../../../../assets/fonts/Barlow-400.woff2") },
19
    Asset { path: "fonts/Barlow-500.woff2", mime: "font/woff2", bytes: include_bytes!("../../../../assets/fonts/Barlow-500.woff2") },
20
    Asset { path: "fonts/Barlow-600.woff2", mime: "font/woff2", bytes: include_bytes!("../../../../assets/fonts/Barlow-600.woff2") },
21
    Asset {
22
        path: "fonts/PressStart2P-400.woff2",
23
        mime: "font/woff2",
24
        bytes: include_bytes!("../../../../assets/fonts/PressStart2P-400.woff2"),
25
    },
26
    Asset { path: "hub.js", mime: "text/javascript; charset=utf-8", bytes: include_bytes!("../../../../assets/hub.js") },
27
    Asset {
28
        path: "vendor/editor.js",
29
        mime: "text/javascript; charset=utf-8",
30
        bytes: include_bytes!("../../../../assets/vendor/editor.js"),
31
    },
32
    Asset {
33
        path: "vendor/easymde.min.js",
34
        mime: "text/javascript; charset=utf-8",
35
        bytes: include_bytes!("../../../../assets/vendor/easymde.min.js"),
36
    },
37
    Asset {
38
        path: "vendor/easymde.min.css",
39
        mime: "text/css; charset=utf-8",
40
        bytes: include_bytes!("../../../../assets/vendor/easymde.min.css"),
41
    },
42
];
43
44
const CACHE: &str = "public, max-age=86400";
45
46
pub async fn style() -> Response {
47
    ([(header::CONTENT_TYPE, "text/css; charset=utf-8"), (header::CACHE_CONTROL, CACHE)], CSS).into_response()
48
}
49
50
pub async fn favicon() -> Response {
51
    ([(header::CONTENT_TYPE, "image/svg+xml"), (header::CACHE_CONTROL, CACHE)], FAVICON).into_response()
52
}
53
54
pub async fn asset(Path(path): Path<String>) -> Response {
55
    match ASSETS.iter().find(|a| a.path == path) {
56
        Some(a) => {
57
            ([(header::CONTENT_TYPE, a.mime), (header::CACHE_CONTROL, "public, max-age=31536000, immutable")], a.bytes).into_response()
58
        }
59
        None => StatusCode::NOT_FOUND.into_response(),
60
    }
61
}