From 5de65ce3e89ba2f229170ed18933c99e5caa8dff Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 8 Jun 2021 15:59:55 -0500 Subject: [PATCH] Set the correct height/width if the data is available when generating twittercard metadata --- lib/pleroma/web/metadata/providers/twitter_card.ex | 7 +++++-- .../web/metadata/providers/twitter_card_test.exs | 11 ++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/metadata/providers/twitter_card.ex b/lib/pleroma/web/metadata/providers/twitter_card.ex index 12c372d77..e28f832d4 100644 --- a/lib/pleroma/web/metadata/providers/twitter_card.ex +++ b/lib/pleroma/web/metadata/providers/twitter_card.ex @@ -80,11 +80,14 @@ defp build_attachments(id, %{data: %{"attachment" => attachments}}) do # TODO: Need the true width and height values here or Twitter renders an iFrame with # a bad aspect ratio "video" -> + height = url["height"] || 480 + width = url["width"] || 480 + [ {:meta, [property: "twitter:card", content: "player"], []}, {:meta, [property: "twitter:player", content: player_url(id)], []}, - {:meta, [property: "twitter:player:width", content: "480"], []}, - {:meta, [property: "twitter:player:height", content: "480"], []}, + {:meta, [property: "twitter:player:width", content: "#{width}"], []}, + {:meta, [property: "twitter:player:height", content: "#{height}"], []}, {:meta, [property: "twitter:player:stream", content: url["href"]], []}, {:meta, [property: "twitter:player:stream:content_type", content: url["mediaType"]], []} diff --git a/test/pleroma/web/metadata/providers/twitter_card_test.exs b/test/pleroma/web/metadata/providers/twitter_card_test.exs index 196bca20a..6d761f4e4 100644 --- a/test/pleroma/web/metadata/providers/twitter_card_test.exs +++ b/test/pleroma/web/metadata/providers/twitter_card_test.exs @@ -123,7 +123,12 @@ test "it renders supported types of attachments and skips unknown types" do }, %{ "url" => [ - %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"} + %{ + "mediaType" => "video/webm", + "href" => "https://pleroma.gov/about/juche.webm", + "height" => 600, + "width" => 800 + } ] } ] @@ -143,8 +148,8 @@ test "it renders supported types of attachments and skips unknown types" do property: "twitter:player", content: Router.Helpers.o_status_url(Endpoint, :notice_player, activity.id) ], []}, - {:meta, [property: "twitter:player:width", content: "480"], []}, - {:meta, [property: "twitter:player:height", content: "480"], []}, + {:meta, [property: "twitter:player:width", content: "800"], []}, + {:meta, [property: "twitter:player:height", content: "600"], []}, {:meta, [ property: "twitter:player:stream",