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

View file

@ -407,14 +407,18 @@ def canonicalise(json_data: dict, include_security: bool = False) -> dict:
""" """
if not isinstance(json_data, dict): if not isinstance(json_data, dict):
raise ValueError("Pass decoded JSON data into LDDocument") raise ValueError("Pass decoded JSON data into LDDocument")
context: str | list[str]
if include_security:
context = [ context = [
"https://www.w3.org/ns/activitystreams", "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: if include_security:
context = "https://www.w3.org/ns/activitystreams" context.append("https://w3id.org/security/v1")
if "@context" not in json_data: if "@context" not in json_data:
json_data["@context"] = context json_data["@context"] = context