+41
src/lib/strings/url-helpers.ts
+41
src/lib/strings/url-helpers.ts
···
99
99
return url
100
100
}
101
101
102
+
export function toShareUrlAturi(url: string): string {
103
+
// Convert witchsky URL to aturi.to format
104
+
// Expected input format: /profile/handle/post/rkey
105
+
try {
106
+
if (!url.startsWith('https')) {
107
+
const urlp = new URL('https://witchsky.app')
108
+
urlp.pathname = url
109
+
url = urlp.toString()
110
+
}
111
+
112
+
const urlp = new URL(url)
113
+
const pathname = urlp.pathname
114
+
115
+
// Extract components from /profile/identifier/post/rkey
116
+
if (pathname.startsWith('/profile/')) {
117
+
const parts = pathname.substring(9).split('/') // Remove "/profile/"
118
+
119
+
if (parts.length === 3 && parts[1] === 'post') {
120
+
// Post: /profile/identifier/post/rkey
121
+
const identifier = parts[0]
122
+
const rkey = parts[2]
123
+
return `https://aturi.to/${identifier}/app.bsky.feed.post/${rkey}`
124
+
} else if (parts.length === 3 && parts[1] === 'lists') {
125
+
// List: /profile/identifier/lists/rkey
126
+
const identifier = parts[0]
127
+
const rkey = parts[2]
128
+
return `https://aturi.to/${identifier}/app.bsky.graph.list/${rkey}`
129
+
} else if (parts.length === 1) {
130
+
// Profile only: /profile/identifier
131
+
return `https://aturi.to/${parts[0]}`
132
+
}
133
+
}
134
+
135
+
// Fallback to original URL if we can't parse it
136
+
return url
137
+
} catch (e) {
138
+
console.error('Error converting to aturi.to URL:', e)
139
+
return url
140
+
}
141
+
}
142
+
102
143
export function toBskyAppUrl(url: string): string {
103
144
return new URL(url, BSKY_APP_HOST).toString()
104
145
}