diff options
author | Minseo Lee <itoupluk427@gmail.com> | 2024-03-10 22:50:48 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-10 22:50:48 +0900 |
commit | 236223d02aa61d8f9011c7484c4e8827d336ecb6 (patch) | |
tree | 2e4ac0c8581a942332447a041b28dd5fa608e283 /src/lib/strings/url-helpers.ts | |
parent | e74c46e9ab480959c4416f83a78289e460bdeec7 (diff) | |
parent | 1aaed1cc0d59ecafa1bb3c7f57f0a323940e6317 (diff) | |
download | voidsky-236223d02aa61d8f9011c7484c4e8827d336ecb6.tar.zst |
Merge branch 'bluesky-social:main' into patch-3
Diffstat (limited to 'src/lib/strings/url-helpers.ts')
-rw-r--r-- | src/lib/strings/url-helpers.ts | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/lib/strings/url-helpers.ts b/src/lib/strings/url-helpers.ts index 7729e4a38..820311e4e 100644 --- a/src/lib/strings/url-helpers.ts +++ b/src/lib/strings/url-helpers.ts @@ -3,6 +3,8 @@ import {BSKY_SERVICE} from 'lib/constants' import TLDs from 'tlds' import psl from 'psl' +export const BSKY_APP_HOST = 'https://bsky.app' + export function isValidDomain(str: string): boolean { return !!TLDs.find(tld => { let i = str.lastIndexOf(tld) @@ -67,8 +69,21 @@ export function isBskyAppUrl(url: string): boolean { return url.startsWith('https://bsky.app/') } +export function isRelativeUrl(url: string): boolean { + return /^\/[^/]/.test(url) +} + +export function isBskyRSSUrl(url: string): boolean { + return ( + (url.startsWith('https://bsky.app/') || isRelativeUrl(url)) && + /\/rss\/?$/.test(url) + ) +} + export function isExternalUrl(url: string): boolean { - return !isBskyAppUrl(url) && url.startsWith('http') + const external = !isBskyAppUrl(url) && url.startsWith('http') + const rss = isBskyRSSUrl(url) + return external || rss } export function isBskyPostUrl(url: string): boolean { @@ -149,7 +164,7 @@ export function linkRequiresWarning(uri: string, label: string) { const labelDomain = labelToDomain(label) // If the uri started with a / we know it is internal. - if (uri.startsWith('/')) { + if (isRelativeUrl(uri)) { return false } @@ -222,3 +237,8 @@ export function splitApexDomain(hostname: string): [string, string] { hostnamep.domain, ] } + +export function createBskyAppAbsoluteUrl(path: string): string { + const sanitizedPath = path.replace(BSKY_APP_HOST, '').replace(/^\/+/, '') + return `${BSKY_APP_HOST.replace(/\/$/, '')}/${sanitizedPath}` +} |