Skip to content

Commit

Permalink
Canonicalise AT URIs to bsky.app URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelOtter authored and snarfed committed Oct 31, 2023
1 parent bd4eeb3 commit 87038d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 5 additions & 1 deletion bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ def button_html(cls, feature, **kwargs):
def canonicalize_url(self, url, **kwargs):
"""Canonicalizes a post or object URL.
Overrides :class:`Source`'s to convert ``staging.bsky.app`` to ``bsky.app``.
Overrides :class:`Source`'s to convert ``staging.bsky.app`` to ``bsky.app``,
and to convert at:// URIs to bsky.app URLs.
"""
if url.startswith('at://'):
url = gr_bluesky.at_uri_to_web_url(url, handle=self.username)

url = url.replace('https://staging.bsky.app/', 'https://bsky.app/')
return super().canonicalize_url(url)

Expand Down
7 changes: 2 additions & 5 deletions tests/test_bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ def test_new(self):
def test_format_for_source_url(self):
self.assertEqual('at%253A%252F%252Fid', self.bsky.format_for_source_url('at://id'))

def test_canonicalize_url(self):
good = 'https://bsky.app/profile/alice.com'
self.assertEqual(good, self.bsky.canonicalize_url(good))
self.assertEqual(good, self.bsky.canonicalize_url('http://bsky.app/profile/alice.com'))

def test_post_id(self):
good = 'at://did:web:alice.com/app.bsky.feed.post/123'
self.assertEqual(good, self.bsky.post_id(good))
Expand All @@ -64,5 +59,7 @@ def test_canonicalize_url(self):
('https://bsky.app/foo', 'https://bsky.app/foo'),
('http://bsky.app/foo', 'https://bsky.app/foo'),
('https://staging.bsky.app/foo', 'https://bsky.app/foo'),
('at://did:web:alice.com', 'https://bsky.app/profile/alice.com'),
('at://did:web:alice.com/app.bsky.feed.post/123', 'https://bsky.app/profile/alice.com/post/123'),
]:
self.assertEqual(expected, self.bsky.canonicalize_url(input))

0 comments on commit 87038d3

Please sign in to comment.