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