X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fmetadata%2Fopengraph.ex;h=b158569748d5559da9833e10201d59728a35f63f;hb=ff01fd3c4fe1edb45098a7730b97b9424b1222cc;hp=2eac04ae77699a0421742e4841ec0dbca43d11b1;hpb=410fd9d774fb3437a38adfe405ff45d4950b51a9;p=akkoma diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 2eac04ae7..b15856974 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -7,8 +7,9 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do @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) + [ {:meta, [ @@ -16,12 +17,18 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do 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"], []} - ] ++ if attachments == [] do [ - {: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], []} ] else attachments end + {:meta, [property: "og:description", content: truncated_content], []} + ] ++ + 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:image:height", content: 120], []} + ] + else + attachments + end end end @@ -38,8 +45,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do {: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 @@ -65,7 +71,16 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do 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//, " ") + |> 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() @@ -79,7 +94,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do end defp user_name_string(user) do - "#{user.name}" <> + "#{user.name} " <> if user.local do "(@#{user.nickname}@#{Pleroma.Web.Endpoint.host()})" else