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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*
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};
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()
.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()
}
}
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 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()
}
}
#[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())
}
#[get("/assets/bundle.js")]
pub fn r_assets_js() -> (ContentType, String) {
(ContentType::JavaScript, js_bundle())
}
|