1 defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
2 alias Pleroma.Web.Metadata.Providers.Provider
7 def build_tags(%{activity: activity}) do
8 if Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) or
9 activity.data["object"]["attachment"] == [] do
12 case find_first_acceptable_media_type(activity) do
14 [{:meta, [property: "twitter:card", content: "summary_large_image"], []}]
17 [{:meta, [property: "twitter:card", content: "player"], []}]
20 [{:meta, [property: "twitter:card", content: "player"], []}]
30 [{:meta, [property: "twitter:card", content: "summary"], []}]
33 def find_first_acceptable_media_type(%{data: %{"object" => %{"attachment" => attachment}}}) do
34 Enum.find_value(attachment, fn attachment ->
35 Enum.find_value(attachment["url"], fn url ->
36 Enum.find(["image", "audio", "video"], fn media_type ->
37 String.starts_with?(url["mediaType"], media_type)