From 127a10da35a83221a20db4197d0e836c02324b00 Mon Sep 17 00:00:00 2001 From: liv Date: Sun, 16 Jul 2023 12:48:45 +0200 Subject: [PATCH] add rubygems support --- src/main.rs | 9 +++++++-- templates/home.html | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) 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) -> impl IntoResponse { +async fn redirect_cratesio(Path(url): Path) -> impl IntoResponse { Redirect::permanent(&format!("https://crates.io/crates/{url}")) } + +async fn redirect_rubygems(Path(url): Path) -> 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'

- cra.tw -- a link shortener for crates.io + cra.tw -- a link shortener for crates.io and rubygems

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)

@@ -48,6 +48,8 @@ d8P' `P 88P' `d8P' ?88 88P d88 d8P' d8P'

cra.tw/serde ---> crates.io/crates/serde +
+ cra.tw/g/rails ---> rubygems.com/gems/rails