forge
Explore
Log in

Don't you dare go Hollow

personality

Clone
★ 0

0 watching0 forksRustGPL-3.0460.1 KiB4de8815Tahinli7 days ago22 commits

assets.rs43 lines, 1.6 KiBHistoryRawDownload
1use http::header::{CACHE_CONTROL, CONTENT_TYPE};
2use topcoat::{
3 Result,
4 context::Cx,
5 router::{Body, content::Css, error::not_found, path_param, route},
6};
7
8path_param!(file);
9
10#[route(GET "/main.css")]
11pub async fn stylesheet(cx: &Cx) -> Result<Css<&'static str>> {
12 Ok(Css(include_str!("../../assets/main.css")))
13}
14
15#[route(GET "/favicon.ico")]
16pub async fn favicon(cx: &Cx) -> Result<http::Response<Body>> {
17 Ok(http::Response::builder()
18 .header(CONTENT_TYPE, "image/x-icon")
19 .body(Body::from(&include_bytes!("../../assets/favicon.ico")[..]))?)
20}
21
22#[route(GET "/nav.js")]
23pub async fn nav(cx: &Cx) -> Result<http::Response<Body>> {
24 Ok(http::Response::builder()
25 .header(CONTENT_TYPE, "text/javascript; charset=utf-8")
26 .body(Body::from(include_str!("../../assets/nav.js")))?)
27}
28
29#[route(GET "/fonts/{file}")]
30pub async fn font(cx: &Cx) -> Result<http::Response<Body>> {
31 let bytes: &'static [u8] = match file(cx) {
32 "inter-latin-wght.woff2" => include_bytes!("../../assets/fonts/inter-latin-wght.woff2"),
33 "inter-latin-ext-wght.woff2" => include_bytes!("../../assets/fonts/inter-latin-ext-wght.woff2"),
34 "jetbrains-mono-latin-wght.woff2" => include_bytes!("../../assets/fonts/jetbrains-mono-latin-wght.woff2"),
35 "jetbrains-mono-latin-ext-wght.woff2" => include_bytes!("../../assets/fonts/jetbrains-mono-latin-ext-wght.woff2"),
36 _ => return Err(not_found().into()),
37 };
38
39 Ok(http::Response::builder()
40 .header(CONTENT_TYPE, "font/woff2")
41 .header(CACHE_CONTROL, "public, max-age=31536000, immutable")
42 .body(Body::from(bytes))?)
43}