From 905564ce1532a3d9b63cc4dac087cbdc4bb8bfeb Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 3 Jul 2024 07:30:29 +0200 Subject: [PATCH] fix(web): variable width pretty uris and jank fix for lemmy inline posts, ughh --- web/src/components/object.rs | 4 ++-- web/src/components/user.rs | 2 +- web/src/lib.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/web/src/components/object.rs b/web/src/components/object.rs index 9dc42a7c..9afaab72 100644 --- a/web/src/components/object.rs +++ b/web/src/components/object.rs @@ -80,7 +80,7 @@ pub fn Attachment( view! {

- +

}.into_view(), @@ -136,7 +136,7 @@ pub fn Object(object: crate::Object) -> impl IntoView { > & - {Uri::pretty(&x)} + {Uri::pretty(&x, 30)} diff --git a/web/src/components/user.rs b/web/src/components/user.rs index 954c9b8e..d99bee79 100644 --- a/web/src/components/user.rs +++ b/web/src/components/user.rs @@ -20,7 +20,7 @@ pub fn ActorStrip(object: crate::Object) -> impl IntoView { pub fn ActorBanner(object: crate::Object) -> impl IntoView { match object.as_ref() { serde_json::Value::String(id) => view! { -
?" "{Uri::pretty(id)}
+
?" "{Uri::pretty(id, 50)}
}, serde_json::Value::Object(_) => { let uid = object.id().unwrap_or_default().to_string(); diff --git a/web/src/lib.rs b/web/src/lib.rs index dd5e5ed1..af53682c 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -204,12 +204,12 @@ impl Uri { uriproxy::uri(URL_BASE, kind, id) } - pub fn pretty(url: &str) -> String { + pub fn pretty(url: &str, len: usize) -> String { let bare = url.replace("https://", ""); - if bare.len() < 50 { + if bare.len() < len { bare } else { - format!("{}..", bare.get(..50).unwrap_or_default()) + format!("{}..", bare.get(..len).unwrap_or_default()) }.replace('/', "\u{200B}/\u{200B}") }