@impl Provider
def build_tags(%{activity: activity, user: user}) do
- with truncated_content = scrub_html_and_truncate(activity.data["object"]["content"]) do
+ with truncated_content = scrub_html_and_truncate(activity) do
attachments = build_attachments(activity)
[
content: user_name_string(user)
], []},
{:meta, [property: "og:url", content: activity.data["id"]], []},
- {:meta, [property: "og:description", content: truncated_content], []},
- {:meta, [property: "twitter:card", content: "summary"], []}
+ {:meta, [property: "og:description", content: truncated_content], []}
] ++
- if attachments == [] do
+ if attachments == [] or
+ Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) do
[
{:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []},
{:meta, [property: "og:image:width", content: 120], []},
{:meta, [property: "og:description", content: truncated_bio], []},
{:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []},
{:meta, [property: "og:image:width", content: 120], []},
- {:meta, [property: "og:image:height", content: 120], []},
- {:meta, [property: "twitter:card", content: "summary"], []}
+ {:meta, [property: "og:image:height", content: 120], []}
]
end
end
end)
end
- defp scrub_html_and_truncate(content) do
+ defp scrub_html_and_truncate(%{data: %{"object" => %{"content" => content}}} = activity) do
+ content
+ # html content comes from DB already encoded, decode first and scrub after
+ |> HtmlEntities.decode()
+ |> String.replace(~r/<br\s?\/?>/, " ")
+ |> HTML.get_cached_stripped_html_for_object(activity, __MODULE__)
+ |> Formatter.truncate()
+ end
+
+ defp scrub_html_and_truncate(content) when is_binary(content) do
content
# html content comes from DB already encoded, decode first and scrub after
|> HtmlEntities.decode()
end
defp user_name_string(user) do
- "#{user.name}" <>
+ "#{user.name} " <>
if user.local do
"(@#{user.nickname}@#{Pleroma.Web.Endpoint.host()})"
else