Shorten rendered URLs in posts
This commit is contained in:
parent
27db820a9d
commit
ce56d4e34e
2 changed files with 20 additions and 2 deletions
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue