Skip to content

Commit d7f0ace

Browse files
committed
improvement: return the bluesky post url if possible #17
$page->icGetBlueskyUrl() will return the url to the post or the did as a fallback
1 parent a4991bc commit d7f0ace

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

plugin/page-methods.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99
},
1010
'icGetBlueskyUrl' => function () {
1111
$mastodonSender = new BlueskySender();
12-
return $mastodonSender->getPostTargetUrl('bluesky', $this);
12+
$atUri = $mastodonSender->getPostTargetUrl('bluesky', $this);
13+
14+
// Regular expression to match the DID and RKEY
15+
$regex = '/^at:\/\/(did:plc:[a-zA-Z0-9]+)\/app\.bsky\.feed\.post\/([a-zA-Z0-9]+)$/';
16+
17+
// Check if the AT-URI matches the pattern
18+
if (preg_match($regex, $atUri, $matches)) {
19+
// Extract DID and RKEY from the matched groups
20+
$did = $matches[1]; // Group 1: DID
21+
$rkey = $matches[2]; // Group 2: RKEY
22+
23+
// Generate the Bluesky post URL
24+
return "https://bsky.app/profile/$did/post/$rkey";
25+
}
26+
27+
return $atUri;
1328
},
1429
];

0 commit comments

Comments
 (0)