Fix hashtag linking and API mentions of empty

This commit is contained in:
Andrew Godwin 2022-12-15 19:26:06 -07:00
parent e0f1bb629c
commit 1bcdff79e7
2 changed files with 12 additions and 6 deletions

View File

@ -179,10 +179,15 @@ class Hashtag(StatorModel):
return list(hashtags) return list(hashtags)
@classmethod @classmethod
def linkify_hashtags(cls, content) -> str: def linkify_hashtags(cls, content, domain=None) -> str:
def replacer(match): def replacer(match):
hashtag = match.group(1) hashtag = match.group(1)
return f'<a class="hashtag" href="/tags/{hashtag.lower()}/">#{hashtag}</a>' if domain:
return f'<a class="hashtag" href="https://{domain.uri_domain}/tags/{hashtag.lower()}/">#{hashtag}</a>'
else:
return (
f'<a class="hashtag" href="/tags/{hashtag.lower()}/">#{hashtag}</a>'
)
return mark_safe(Hashtag.hashtag_regex.sub(replacer, content)) return mark_safe(Hashtag.hashtag_regex.sub(replacer, content))

View File

@ -348,7 +348,8 @@ class Post(StatorModel):
Returns the content formatted for remote consumption Returns the content formatted for remote consumption
""" """
return Hashtag.linkify_hashtags( return Hashtag.linkify_hashtags(
self.linkify_mentions(sanitize_post(self.content)) self.linkify_mentions(sanitize_post(self.content)),
domain=self.author.domain,
) )
def safe_content_plain(self): def safe_content_plain(self):
@ -835,9 +836,9 @@ class Post(StatorModel):
"mentions": [ "mentions": [
{ {
"id": mention.id, "id": mention.id,
"username": mention.username, "username": mention.username or "",
"url": mention.absolute_profile_uri(), "url": mention.absolute_profile_uri() or "",
"acct": mention.handle, "acct": mention.handle or "",
} }
for mention in self.mentions.all() for mention in self.mentions.all()
if mention.username if mention.username