diff options
-rw-r--r-- | src/animation.rs | 50 | ||||
-rw-r--r-- | src/layout.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 3 |
3 files changed, 55 insertions, 0 deletions
diff --git a/src/animation.rs b/src/animation.rs new file mode 100644 index 0000000..bfb17a4 --- /dev/null +++ b/src/animation.rs @@ -0,0 +1,50 @@ +use rocket::{ + get, + http::{Cookie, CookieJar, Header}, + response::{self, Responder}, + Request, +}; + +pub struct Reload<T>(f64, pub T); + +#[rocket::async_trait] +impl<'r, T: Responder<'r, 'static>> Responder<'r, 'static> for Reload<T> { + fn respond_to(self, request: &'r Request<'_>) -> response::Result<'static> { + let mut resp = self.1.respond_to(request); + if let Ok(resp) = &mut resp { + resp.set_header(Header::new("refresh", format!("{}", self.0))); + } + resp + } +} + +const TEXT: &'static str = include_str!("../COPYING"); +const END_FRAME: isize = TEXT.len() as isize / 100 + 5; + +#[get("/wubbel")] +pub fn r_wubbel(jar: &CookieJar) -> Reload<String> { + let frame = jar + .get("frame") + .and_then(|c| c.value().parse().ok()) + .unwrap_or(0isize); + jar.add(Cookie::build("frame", format!("{}", (frame + 1) % (END_FRAME + 1))).finish()); + + let text = TEXT + .chars() + .enumerate() + .map(|(i, e)| { + if e == '\n' || frag(i as isize, frame) { + e + } else { + ' ' + } + }) + .collect::<String>(); + + Reload(if frame >= END_FRAME { 60.0 } else { 0.1 }, text) +} + +#[inline] +fn frag(i: isize, frame: isize) -> bool { + i % 5 < (frame - i / 100) +} diff --git a/src/layout.rs b/src/layout.rs index d7b06f2..b5ad682 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -5,6 +5,7 @@ */ use crate::pages::*; use crate::uri; +use crate::animation::*; use markup::Render; use rocket::{ http::ContentType, @@ -29,6 +30,7 @@ markup::define! { a[href=uri!(r_contact())] { "Contact" } " " a[href="https://codeberg.org/metamuffin"] { "Codeberg" } " " a[href=uri!(r_pgp_key())] { "PGP-Key" } " " + a[href=uri!(r_wubbel())] { i {"wubbel"} } " " } hr; section { @main } diff --git a/src/main.rs b/src/main.rs index 24f2c61..86e427d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,10 +3,12 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2023 metamuffin <metamuffin.org> */ +pub mod animation; pub mod layout; pub mod pages; pub mod wellknown; +use animation::*; use pages::*; use rocket::{catchers, fairing::AdHoc, http::Header, routes}; use wellknown::*; @@ -28,6 +30,7 @@ async fn main() { r_contact, r_projects, r_pgp_key, + r_wubbel, r_wellknown_security, r_wellknown_matrix_server, r_wellknown_matrix_client, |