Twittercard metadata for images should also include dimensions if available
[akkoma] / lib / pleroma / web / metadata / providers / twitter_card.ex
index 589989a9da561dadf0785e6cadfb6438ef75b673..bf6d4bcbeefd1744c237b5278e84c278bd5971b9 100644 (file)
@@ -55,7 +55,9 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
     Enum.reduce(attachments, [], fn attachment, acc ->
       rendered_tags =
         Enum.reduce(attachment["url"], [], fn url, acc ->
-          # TODO: Add additional properties to objects when we have the data available.
+          height = url["height"] || 480
+          width = url["width"] || 480
+
           case Utils.fetch_media_type(@media_types, url["mediaType"]) do
             "audio" ->
               [
@@ -73,20 +75,21 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
                  [
                    property: "twitter:player",
                    content: Utils.attachment_url(url["href"])
-                 ], []}
+                 ], []},
+                {:meta, [property: "twitter:player:width", content: "#{width}"], []},
+                {:meta, [property: "twitter:player:height", content: "#{height}"], []}
                 | acc
               ]
 
-            # TODO: Need the true width and height values here or Twitter renders an iFrame with
-            # a bad aspect ratio
             "video" ->
               [
                 {: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"]], []}
+                {:meta,
+                 [property: "twitter:player:stream:content_type", content: url["mediaType"]], []}
                 | acc
               ]