aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/style.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-04-27 19:25:11 +0200
committermetamuffin <metamuffin@disroot.org>2025-04-27 19:25:11 +0200
commit11a585b3dbe620dcc8772e713b22f1d9ba80d598 (patch)
tree44f8d97137412aefc79a2425a489c34fa3e5f6c5 /server/src/routes/ui/style.rs
parentd871aa7c5bba49ff55170b5d2dac9cd440ae7170 (diff)
downloadjellything-11a585b3dbe620dcc8772e713b22f1d9ba80d598.tar
jellything-11a585b3dbe620dcc8772e713b22f1d9ba80d598.tar.bz2
jellything-11a585b3dbe620dcc8772e713b22f1d9ba80d598.tar.zst
move files around
Diffstat (limited to 'server/src/routes/ui/style.rs')
-rw-r--r--server/src/routes/ui/style.rs90
1 files changed, 0 insertions, 90 deletions
diff --git a/server/src/routes/ui/style.rs b/server/src/routes/ui/style.rs
deleted file mode 100644
index c935c8a..0000000
--- a/server/src/routes/ui/style.rs
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- 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) 2025 metamuffin <metamuffin.org>
- Copyright (C) 2023 tpart
-*/
-use rocket::{
- get,
- http::{ContentType, Header},
- response::Responder,
-};
-
-macro_rules! concat_files {
- ([$base: expr], $($files:literal),*) => {{
- #[cfg(any(debug_assertions, feature = "hot-css"))]
- {
- use std::{fs::read_to_string, path::PathBuf, str::FromStr};
- [ $($files),* ]
- .into_iter()
- .map(|n| {
- read_to_string({
- let p = PathBuf::from_str(file!()).unwrap().parent().unwrap().join($base).join(n);
- log::info!("load {p:?}");
- p
- })
- .unwrap()
- })
- .collect::<Vec<_>>()
- .join("\n")
- }
- #[cfg(not(any(debug_assertions, feature = "hot-css")))]
- concat!($(include_str!(concat!($base, "/", $files))),*).to_string()
- }};
-}
-
-fn css_bundle() -> String {
- concat_files!(
- ["../../../../web/style"],
- "layout.css",
- "player.css",
- "nodepage.css",
- "nodecard.css",
- "js-player.css",
- "js-transition.css",
- "forms.css",
- "props.css",
- "themes.css",
- "navbar.css"
- )
-}
-
-pub struct CachedAsset<T>(pub T);
-impl<'r, 'o: 'r, T: Responder<'r, 'o>> Responder<'r, 'o> for CachedAsset<T> {
- fn respond_to(self, request: &'r rocket::Request<'_>) -> rocket::response::Result<'o> {
- let mut res = self.0.respond_to(request)?;
- if cfg!(not(debug_assertions)) {
- res.set_header(Header::new("cache-control", "max-age=86400"));
- }
- Ok(res)
- }
-}
-
-fn js_bundle() -> String {
- concat_files!([env!("OUT_DIR")], "bundle.js")
-}
-fn js_bundle_map() -> String {
- concat_files!([env!("OUT_DIR")], "bundle.js.map")
-}
-
-#[get("/assets/style.css")]
-pub fn r_assets_style() -> CachedAsset<(ContentType, String)> {
- CachedAsset((ContentType::CSS, css_bundle()))
-}
-
-#[get("/assets/cantarell.woff2")]
-pub fn r_assets_font() -> CachedAsset<(ContentType, &'static [u8])> {
- CachedAsset((
- ContentType::WOFF2,
- include_bytes!("../../../../web/cantarell.woff2"),
- ))
-}
-
-#[get("/assets/bundle.js")]
-pub fn r_assets_js() -> CachedAsset<(ContentType, String)> {
- CachedAsset((ContentType::JavaScript, js_bundle()))
-}
-#[get("/assets/bundle.js.map")]
-pub fn r_assets_js_map() -> CachedAsset<(ContentType, String)> {
- CachedAsset((ContentType::JSON, js_bundle_map()))
-}