Commit 2e630bea authored by rinpatch's avatar rinpatch
Browse files

Add twitter card, filter nsfw

parent 70f14068
......@@ -17,10 +17,9 @@ def build_tags(%{activity: activity, user: user}) 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"], []}
{: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], []},
......@@ -45,8 +44,7 @@ def build_tags(%{user: user}) 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
......
defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
def build_tags(%{activity: activity}) do
if Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) or
activity.data["object"]["attachment"] == [] do
build_tags(nil)
else
case find_first_acceptable_media_type(activity) do
"image" ->
[{:meta, [property: "twitter:card", content: "summary_large_image"], []}]
"audio" ->
[{:meta, [property: "twitter:card", content: "player"], []}]
"video" ->
[{:meta, [property: "twitter:card", content: "player"], []}]
_ ->
build_tags(nil)
end
end
end
def build_tags(_) do
[{:meta, [property: "twitter:card", content: "summary"], []}]
end
def find_first_acceptable_media_type(%{data: %{"object" => %{"attachment" => attachment}}}) do
Enum.find_value(attachment, fn attachment ->
Enum.find_value(attachment["url"], fn url ->
Enum.find(["image", "audio", "video"], fn media_type ->
String.starts_with?(url["mediaType"], media_type)
end)
end)
end)
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment