summaryrefslogtreecommitdiff
path: root/postgresqleu/util
diff options
context:
space:
mode:
authorMagnus Hagander2025-02-20 17:46:09 +0000
committerMagnus Hagander2025-02-20 17:46:09 +0000
commit0dcb292a9a53dc172b3f3d150be84da4607e7940 (patch)
tree40a3d787793058f63fcc0eb7864c22cdccd491e6 /postgresqleu/util
parent4bd3443bd03f1d1b4d0b009a34b7861d69d300b9 (diff)
Add proper facets for hashtags when posting to bluesky
Diffstat (limited to 'postgresqleu/util')
-rw-r--r--postgresqleu/util/messaging/bluesky.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/postgresqleu/util/messaging/bluesky.py b/postgresqleu/util/messaging/bluesky.py
index 4ee37fb8..e722b691 100644
--- a/postgresqleu/util/messaging/bluesky.py
+++ b/postgresqleu/util/messaging/bluesky.py
@@ -277,6 +277,18 @@ class Bluesky(object):
)
return spans
+ def _parse_hashtags(self, text: str):
+ hashtags_regex = re.compile(rb'[$|\W](#\w+)')
+ text_bytes = text.encode("UTF-8")
+ for m in hashtags_regex.finditer(text_bytes):
+ yield {
+ "index": {
+ "byteStart": m.start(1),
+ "byteEnd": m.end(1),
+ },
+ "features": [{"$type": "app.bsky.richtext.facet#tag", "tag": m.group(1).decode("UTF-8")}],
+ }
+
def _parse_facets(self, text: str):
"""
parses post text and returns a list of app.bsky.richtext.facet objects for any mentions (@handle.example.com) or URLs (https://example.com)
@@ -303,6 +315,9 @@ class Bluesky(object):
"features": [{"$type": "app.bsky.richtext.facet#mention", "did": did}],
}
)
+
+ facets.extend(self._parse_hashtags(text))
+
newtext, urls = self._parse_urls(text)
for u in urls: