From ff12471308e9ea52b8a723db0d05d8c689a89efe Mon Sep 17 00:00:00 2001 From: jakubmanczak Date: Thu, 9 Oct 2025 12:02:37 +0200 Subject: [PATCH] add alternate link redirects --- src/router/redirects.rs | 49 ++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/router/redirects.rs b/src/router/redirects.rs index 423d257..cf2165a 100644 --- a/src/router/redirects.rs +++ b/src/router/redirects.rs @@ -1,21 +1,34 @@ use axum::{Router, response::Redirect, routing::get}; -pub fn redirects() -> Router { - Router::new() - .route( - "/discord", - get(Redirect::temporary("https://discord.gg/NBXq95C")), - ) - .route( - "/github", - get(Redirect::temporary("https://github.com/gractwo")), - ) - .route( - "/youtube", - get(Redirect::temporary("https://www.youtube.com/@gractwopl")), - ) - .route( - "/bsky", - get(Redirect::temporary("https://bsky.app/profile/gractwo.pl")), - ) +#[rustfmt::skip] +const REDIRECTS: &[(&[&str], &str)] = &[ + ( + &["/discord", "/dsc", "/dc"], + "https://discord.gg/NBXq95C" + ),( + &["/github", "/gh"], + "https://github.com/gractwo" + ),( + &["/youtube", "/yt"], + "https://www.youtube.com/@gractwopl" + ),( + &["/bsky", "/bluesky"], + "https://bsky.app/profile/gractwo.pl", + ), +]; + +macro_rules! build_redirects { + ($redirects:expr) => {{ + let mut router = Router::new(); + for (paths, url) in $redirects { + for path in *paths { + router = router.route(path, get(Redirect::temporary(*url))); + } + } + router + }}; +} + +pub fn redirects() -> Router { + build_redirects!(REDIRECTS) }