Merge branch 'fix/metadata-tags' into 'develop'
static frontend: fix meta tags See merge request pleroma/pleroma!3885
This commit is contained in:
commit
16313af7eb
|
@ -0,0 +1 @@
|
||||||
|
Fix opengraph and twitter card meta tags
|
|
@ -76,9 +76,10 @@ defp build_attachments(id, %{data: %{"attachment" => attachments}}) do
|
||||||
{:meta, [name: "twitter:card", content: "summary_large_image"], []},
|
{:meta, [name: "twitter:card", content: "summary_large_image"], []},
|
||||||
{:meta,
|
{:meta,
|
||||||
[
|
[
|
||||||
name: "twitter:player",
|
name: "twitter:image",
|
||||||
content: MediaProxy.url(url["href"])
|
content: MediaProxy.url(url["href"])
|
||||||
], []}
|
], []},
|
||||||
|
{:meta, [name: "twitter:image:alt", content: truncate(attachment["name"])], []}
|
||||||
| acc
|
| acc
|
||||||
]
|
]
|
||||||
|> maybe_add_dimensions(url)
|
|> maybe_add_dimensions(url)
|
||||||
|
@ -130,4 +131,12 @@ defp maybe_add_dimensions(metadata, url) do
|
||||||
metadata
|
metadata
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp truncate(nil), do: ""
|
||||||
|
|
||||||
|
defp truncate(text) do
|
||||||
|
# truncate to 420 characters
|
||||||
|
# see https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/markup
|
||||||
|
Pleroma.Formatter.truncate(text, 420)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,7 +25,15 @@ def show(%{assigns: %{notice_id: notice_id}} = conn, _params) do
|
||||||
true <- Visibility.is_public?(activity.object),
|
true <- Visibility.is_public?(activity.object),
|
||||||
{_, true} <- {:visible?, Visibility.visible_for_user?(activity, _reading_user = nil)},
|
{_, true} <- {:visible?, Visibility.visible_for_user?(activity, _reading_user = nil)},
|
||||||
%User{} = user <- User.get_by_ap_id(activity.object.data["actor"]) do
|
%User{} = user <- User.get_by_ap_id(activity.object.data["actor"]) do
|
||||||
meta = Metadata.build_tags(%{activity_id: notice_id, object: activity.object, user: user})
|
url = Helpers.url(conn) <> conn.request_path
|
||||||
|
|
||||||
|
meta =
|
||||||
|
Metadata.build_tags(%{
|
||||||
|
activity_id: notice_id,
|
||||||
|
object: activity.object,
|
||||||
|
user: user,
|
||||||
|
url: url
|
||||||
|
})
|
||||||
|
|
||||||
timeline =
|
timeline =
|
||||||
activity.object.data["context"]
|
activity.object.data["context"]
|
||||||
|
|
|
@ -182,7 +182,8 @@ test "it renders supported types of attachments and skips unknown types" do
|
||||||
{:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
|
{:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
|
||||||
{:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []},
|
{:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []},
|
||||||
{:meta, [name: "twitter:card", content: "summary_large_image"], []},
|
{:meta, [name: "twitter:card", content: "summary_large_image"], []},
|
||||||
{:meta, [name: "twitter:player", content: "https://pleroma.gov/tenshi.png"], []},
|
{:meta, [name: "twitter:image", content: "https://pleroma.gov/tenshi.png"], []},
|
||||||
|
{:meta, [name: "twitter:image:alt", content: ""], []},
|
||||||
{:meta, [name: "twitter:player:width", content: "1280"], []},
|
{:meta, [name: "twitter:player:width", content: "1280"], []},
|
||||||
{:meta, [name: "twitter:player:height", content: "1024"], []},
|
{:meta, [name: "twitter:player:height", content: "1024"], []},
|
||||||
{:meta, [name: "twitter:card", content: "player"], []},
|
{:meta, [name: "twitter:card", content: "player"], []},
|
||||||
|
|
Loading…
Reference in New Issue