diff --git a/src/main.rs b/src/main.rs index 361c0d2..9ed09ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,8 @@ struct HomeContent { async fn main() { let app = Router::new() .route("/", routing::get(home)) - .route("/:url", routing::get(redirect)); + .route("/g/:url", routing::get(redirect_rubygems)) + .route("/:url", routing::get(redirect_cratesio)); tracing_subscriber::fmt().init(); info!("Starting server at http://localhost:3000"); @@ -35,6 +36,10 @@ async fn home() -> impl IntoResponse { Html(template.render(&content)) } -async fn redirect(Path(url): Path<String>) -> impl IntoResponse { +async fn redirect_cratesio(Path(url): Path<String>) -> impl IntoResponse { Redirect::permanent(&format!("https://crates.io/crates/{url}")) } + +async fn redirect_rubygems(Path(url): Path<String>) -> impl IntoResponse { + Redirect::permanent(&format!("https://rubygems.org/gems/{url}")) +} diff --git a/templates/home.html b/templates/home.html index 40b696a..56d9407 100644 --- a/templates/home.html +++ b/templates/home.html @@ -33,13 +33,13 @@ d8P' `P 88P' `d8P' ?88 88P d88 d8P' d8P' </pre> <p> - cra.tw -- a link shortener for <a href="https://crates.io">crates.io</a> + cra.tw -- a link shortener for <a href="https://crates.io">crates.io</a> and <a href="https://rubygems.com">rubygems</a> </p> <p> i refer to npm packages a lot, and i've always found npm.im, a url shortener so that you can type npm.im/mypackage instead of - npmjs.com/package/hello, very useful. the same thing goes for crates.io, + npmjs.com/package/hello, very useful. the same thing goes for crates.io and rubygems.com, which is unwieldy to type, and i can never remember whether it's crates.io/crate or crates.io/crates (it's the latter) </p> @@ -48,6 +48,8 @@ d8P' `P 88P' `d8P' ?88 88P d88 d8P' d8P' <p> <a href="https://cra.tw/serde">cra.tw/serde</a> ---> <a href="https://crates.io/crates/serde">crates.io/crates/serde</a> + <br /> + <a href="https://cra.tw/g/rails">cra.tw/g/rails</a> ---> <a href="https://rubygems.com/gems/rails">rubygems.com/gems/rails</a> </p> <p>