Bluesky app fork with some witchin' additions 馃挮
at main 63 lines 1.8 kB view raw
1import {type AppBskyGraphDefs, AtUri} from '@atproto/api' 2 3import {isInvalidHandle, isValidHandle} from '#/lib/strings/handles' 4import * as persisted from '#/state/persisted' 5 6export function makeProfileLink( 7 info: { 8 did: string 9 handle: string 10 }, 11 ...segments: string[] 12) { 13 const useHandle = persisted.get('useHandleInLinks') ?? false 14 const identifier = 15 useHandle && 16 info.handle && 17 !isInvalidHandle(info.handle) && 18 isValidHandle(info.handle) 19 ? info.handle 20 : info.did 21 return [`/profile`, identifier, ...segments].join('/') 22} 23 24export function makeCustomFeedLink( 25 did: string, 26 rkey: string, 27 segment?: string | undefined, 28 feedCacheKey?: 'discover' | 'explore' | undefined, 29) { 30 return ( 31 [`/profile`, did, 'feed', rkey, ...(segment ? [segment] : [])].join('/') + 32 (feedCacheKey ? `?feedCacheKey=${encodeURIComponent(feedCacheKey)}` : '') 33 ) 34} 35 36export function makeListLink(did: string, rkey: string, ...segments: string[]) { 37 return [`/profile`, did, 'lists', rkey, ...segments].join('/') 38} 39 40export function makeTagLink(did: string) { 41 return `/search?q=${encodeURIComponent(did)}` 42} 43 44export function makeSearchLink(props: {query: string; from?: 'me' | string}) { 45 return `/search?q=${encodeURIComponent( 46 props.query + (props.from ? ` from:${props.from}` : ''), 47 )}` 48} 49 50export function makeStarterPackLink( 51 starterPackOrName: 52 | AppBskyGraphDefs.StarterPackViewBasic 53 | AppBskyGraphDefs.StarterPackView 54 | string, 55 rkey?: string, 56) { 57 if (typeof starterPackOrName === 'string') { 58 return `https://bsky.app/start/${starterPackOrName}/${rkey}` 59 } else { 60 const uriRkey = new AtUri(starterPackOrName.uri).rkey 61 return `https://bsky.app/start/${starterPackOrName.creator.handle}/${uriRkey}` 62 } 63}