1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
6 alias Pleroma.Web.Metadata.Providers.Provider
7 alias Pleroma.Web.Metadata
12 def build_tags(%{object: object}) do
13 if Metadata.activity_nsfw?(object) or object.data["attachment"] == [] do
16 case find_first_acceptable_media_type(object) do
18 [{:meta, [property: "twitter:card", content: "summary_large_image"], []}]
21 [{:meta, [property: "twitter:card", content: "player"], []}]
24 [{:meta, [property: "twitter:card", content: "player"], []}]
34 [{:meta, [property: "twitter:card", content: "summary"], []}]
37 def find_first_acceptable_media_type(%{data: %{"attachment" => attachment}}) do
38 Enum.find_value(attachment, fn attachment ->
39 Enum.find_value(attachment["url"], fn url ->
40 Enum.find(["image", "audio", "video"], fn media_type ->
41 String.starts_with?(url["mediaType"], media_type)