Set the correct height/width if the data is available when generating twittercard...
authorMark Felder <feld@feld.me>
Tue, 8 Jun 2021 20:59:55 +0000 (15:59 -0500)
committerMark Felder <feld@feld.me>
Tue, 8 Jun 2021 20:59:55 +0000 (15:59 -0500)
lib/pleroma/web/metadata/providers/twitter_card.ex
test/pleroma/web/metadata/providers/twitter_card_test.exs

index 12c372d77f7d349d6c7f0fd3c54301cefc7028e2..e28f832d46a512e97fff4e617113aed6251389de 100644 (file)
@@ -80,11 +80,14 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard 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"]], []}
index 196bca20a254629c8bf12937cb220783a4a7452d..6d761f4e446e2b32a19cb189c20d698faf5a8c32 100644 (file)
@@ -123,7 +123,12 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest 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 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest 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",