1 defmodule Pleroma.Web.Metadata.Providers.OpenGraph do
2 alias Pleroma.Web.Metadata.Providers.Provider
3 alias Pleroma.{HTML, Formatter, User}
4 alias Pleroma.Web.MediaProxy
9 def build_tags(%{activity: activity, user: user}) do
10 with truncated_content = scrub_html_and_truncate(activity.data["object"]["content"]) do
15 content: user_name_string(user)
17 {:meta, [property: "og:url", content: activity.data["id"]], []},
18 {:meta, [property: "og:description", content: truncated_content], []},
19 {:meta, [property: "og:image", content: user_avatar_url(user)], []},
20 {:meta, [property: "og:image:width", content: 120], []},
21 {:meta, [property: "og:image:height", content: 120], []},
22 {:meta, [property: "twitter:card", content: "summary"], []}
28 def build_tags(%{user: user}) do
29 with truncated_bio = scrub_html_and_truncate(user.bio || "") do
34 content: user_name_string(user)
36 {:meta, [property: "og:url", content: User.profile_url(user)], []},
37 {:meta, [property: "og:description", content: truncated_bio], []},
38 {:meta, [property: "og:image", content: user_avatar_url(user)], []},
39 {:meta, [property: "og:image:width", content: 120], []},
40 {:meta, [property: "og:image:height", content: 120], []},
41 {:meta, [property: "twitter:card", content: "summary"], []}
46 defp scrub_html_and_truncate(content) do
48 # html content comes from DB already encoded, decode first and scrub after
49 |> HtmlEntities.decode()
51 |> Formatter.truncate()
54 defp user_avatar_url(user) do
55 User.avatar_url(user) |> MediaProxy.url()
58 defp user_name_string(user) do
61 "(@#{user.nickname}@#{Pleroma.Web.Endpoint.host()})"