diff options
author | Eric Bailey <git@esb.lol> | 2024-06-03 20:07:01 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-04 02:07:01 +0100 |
commit | de93e8de746f3c8a7b1755aaa034043951371ae0 (patch) | |
tree | 71ede1691ff2f6c8bd5fa9b55e4d708ad876cdd3 /src/lib/strings | |
parent | da96fb1ef5a37018b6a238c3614e9b845d8e2686 (diff) | |
download | voidsky-de93e8de746f3c8a7b1755aaa034043951371ae0.tar.zst |
[🐴] Post embeds polish (#4339)
* Handle message cleanup * Handle last message in chat list * Memoize lastMessage
Diffstat (limited to 'src/lib/strings')
-rw-r--r-- | src/lib/strings/url-helpers.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/lib/strings/url-helpers.ts b/src/lib/strings/url-helpers.ts index 2a20373a4..4c75f47ad 100644 --- a/src/lib/strings/url-helpers.ts +++ b/src/lib/strings/url-helpers.ts @@ -3,6 +3,7 @@ import psl from 'psl' import TLDs from 'tlds' import {BSKY_SERVICE} from 'lib/constants' +import {isInvalidHandle} from 'lib/strings/handles' export const BSKY_APP_HOST = 'https://bsky.app' const BSKY_TRUSTED_HOSTS = [ @@ -83,6 +84,10 @@ export function toShareUrl(url: string): string { return url } +export function toBskyAppUrl(url: string): string { + return new URL(url, BSKY_APP_HOST).toString() +} + export function isBskyAppUrl(url: string): boolean { return url.startsWith('https://bsky.app/') } @@ -183,6 +188,22 @@ export function feedUriToHref(url: string): string { } } +export function postUriToRelativePath( + uri: string, + options?: {handle?: string}, +): string | undefined { + try { + const {hostname, rkey} = new AtUri(uri) + const handleOrDid = + options?.handle && !isInvalidHandle(options.handle) + ? options.handle + : hostname + return `/profile/${handleOrDid}/post/${rkey}` + } catch { + return undefined + } +} + /** * Checks if the label in the post text matches the host of the link facet. * |