Some hashtag json-ld fiddling

This commit is contained in:
Andrew Godwin 2022-12-15 18:58:11 -07:00
parent 31dc08ad0d
commit c0cd5a5553
2 changed files with 17 additions and 11 deletions

View File

@ -347,7 +347,9 @@ class Post(StatorModel):
"""
Returns the content formatted for remote consumption
"""
return self.linkify_mentions(sanitize_post(self.content))
return Hashtag.linkify_hashtags(
self.linkify_mentions(sanitize_post(self.content))
)
def safe_content_plain(self):
"""
@ -515,14 +517,14 @@ class Post(StatorModel):
Returns the AP JSON for this object
"""
value = {
"to": "as:Public",
"to": "Public",
"cc": [],
"type": "Note",
"id": self.object_uri,
"published": format_ld_date(self.published),
"attributedTo": self.author.actor_uri,
"content": self.safe_content_remote(),
"as:sensitive": self.sensitive,
"sensitive": self.sensitive,
"url": self.absolute_object_uri(),
"tag": [],
"attachment": [],
@ -543,7 +545,7 @@ class Post(StatorModel):
{
"href": f"https://{self.author.domain.uri_domain}/tags/{hashtag}/",
"name": f"#{hashtag}",
"type": "as:Hashtag",
"type": "Hashtag",
}
)
# Emoji

View File

@ -407,14 +407,18 @@ def canonicalise(json_data: dict, include_security: bool = False) -> dict:
"""
if not isinstance(json_data, dict):
raise ValueError("Pass decoded JSON data into LDDocument")
context: str | list[str]
if include_security:
context = [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
{
"sensitive": "as:sensitive",
"toot": "http://joinmastodon.org/ns#",
"votersCount": "toot:votersCount",
"Hashtag": "as:Hashtag",
"Public": "as:Public",
},
]
else:
context = "https://www.w3.org/ns/activitystreams"
if include_security:
context.append("https://w3id.org/security/v1")
if "@context" not in json_data:
json_data["@context"] = context