diff options
Diffstat (limited to 'src/lib/strings.ts')
-rw-r--r-- | src/lib/strings.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/lib/strings.ts b/src/lib/strings.ts index 8f2c3a3ea..c8a9171a3 100644 --- a/src/lib/strings.ts +++ b/src/lib/strings.ts @@ -141,6 +141,23 @@ export function toNiceDomain(url: string): string { } } +export function toShortUrl(url: string): string { + try { + const urlp = new URL(url) + const shortened = + urlp.host + + (urlp.pathname === '/' ? '' : urlp.pathname) + + urlp.search + + urlp.hash + if (shortened.length > 20) { + return shortened.slice(0, 17) + '...' + } + return shortened + } catch (e) { + return url + } +} + export function toShareUrl(url: string) { if (!url.startsWith('https')) { const urlp = new URL('https://bsky.app') |