From ba5d5e9f862096de541bf74284ec3f39138722d4 Mon Sep 17 00:00:00 2001 From: wonfen Date: Tue, 18 Mar 2025 00:18:26 +0800 Subject: [PATCH] feat: limit max url lenght on home profile card --- src/components/home/home-profile-card.tsx | 27 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/components/home/home-profile-card.tsx b/src/components/home/home-profile-card.tsx index 20f776fa..cc5adc5c 100644 --- a/src/components/home/home-profile-card.tsx +++ b/src/components/home/home-profile-card.tsx @@ -35,10 +35,19 @@ const round = keyframes` `; // 辅助函数解析URL和过期时间 -const parseUrl = (url?: string) => { +const parseUrl = (url?: string, maxLength: number = 25) => { if (!url) return "-"; - if (url.startsWith("http")) return new URL(url).host; - return "local"; + let parsedUrl = ""; + if (url.startsWith("http")) { + parsedUrl = new URL(url).host; + } else { + parsedUrl = "local"; + } + + if (parsedUrl.length > maxLength) { + return parsedUrl.substring(0, maxLength - 3) + "..."; + } + return parsedUrl; }; const parseExpire = (expire?: number) => { @@ -107,16 +116,22 @@ const ProfileDetails = ({ current, onUpdateProfile, updating }: { component="button" fontWeight="medium" onClick={() => current.home && openWebUrl(current.home)} - sx={{ display: "inline-flex", alignItems: "center" }} + sx={{ + display: "inline-flex", + alignItems: "center" + }} > {parseUrl(current.url)} ) : ( - + {parseUrl(current.url)} )}