fix: invisible url when only a protocol (#1059)
* fix: invisible url when only a protocol - Fixes https://github.com/bluesky-social/social-app/issues/1058 * fix: handle more cases when url is not http/https
This commit is contained in:
parent
44b3929240
commit
5a0899b989
1 changed files with 4 additions and 1 deletions
|
@ -39,6 +39,9 @@ export function toNiceDomain(url: string): string {
|
||||||
export function toShortUrl(url: string): string {
|
export function toShortUrl(url: string): string {
|
||||||
try {
|
try {
|
||||||
const urlp = new URL(url)
|
const urlp = new URL(url)
|
||||||
|
if (urlp.protocol !== 'http:' && urlp.protocol !== 'https:') {
|
||||||
|
return url
|
||||||
|
}
|
||||||
const shortened =
|
const shortened =
|
||||||
urlp.host +
|
urlp.host +
|
||||||
(urlp.pathname === '/' ? '' : urlp.pathname) +
|
(urlp.pathname === '/' ? '' : urlp.pathname) +
|
||||||
|
@ -47,7 +50,7 @@ export function toShortUrl(url: string): string {
|
||||||
if (shortened.length > 30) {
|
if (shortened.length > 30) {
|
||||||
return shortened.slice(0, 27) + '...'
|
return shortened.slice(0, 27) + '...'
|
||||||
}
|
}
|
||||||
return shortened
|
return shortened ? shortened : url
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue