Twittercard metadata for images should also include dimensions if available
This commit is contained in:
parent
5de65ce3e8
commit
d4ac9445cd
@ -55,7 +55,9 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
|
|||||||
Enum.reduce(attachments, [], fn attachment, acc ->
|
Enum.reduce(attachments, [], fn attachment, acc ->
|
||||||
rendered_tags =
|
rendered_tags =
|
||||||
Enum.reduce(attachment["url"], [], fn url, acc ->
|
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
|
case Utils.fetch_media_type(@media_types, url["mediaType"]) do
|
||||||
"audio" ->
|
"audio" ->
|
||||||
[
|
[
|
||||||
@ -73,16 +75,13 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
|
|||||||
[
|
[
|
||||||
property: "twitter:player",
|
property: "twitter:player",
|
||||||
content: Utils.attachment_url(url["href"])
|
content: Utils.attachment_url(url["href"])
|
||||||
], []}
|
], []},
|
||||||
|
{:meta, [property: "twitter:player:width", content: "#{width}"], []},
|
||||||
|
{:meta, [property: "twitter:player:height", content: "#{height}"], []}
|
||||||
| acc
|
| acc
|
||||||
]
|
]
|
||||||
|
|
||||||
# TODO: Need the true width and height values here or Twitter renders an iFrame with
|
|
||||||
# a bad aspect ratio
|
|
||||||
"video" ->
|
"video" ->
|
||||||
height = url["height"] || 480
|
|
||||||
width = url["width"] || 480
|
|
||||||
|
|
||||||
[
|
[
|
||||||
{:meta, [property: "twitter:card", content: "player"], []},
|
{:meta, [property: "twitter:card", content: "player"], []},
|
||||||
{:meta, [property: "twitter:player", content: player_url(id)], []},
|
{:meta, [property: "twitter:player", content: player_url(id)], []},
|
||||||
|
@ -111,7 +111,14 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
|
|||||||
"content" => "pleroma in a nutshell",
|
"content" => "pleroma in a nutshell",
|
||||||
"attachment" => [
|
"attachment" => [
|
||||||
%{
|
%{
|
||||||
"url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
|
"url" => [
|
||||||
|
%{
|
||||||
|
"mediaType" => "image/png",
|
||||||
|
"href" => "https://pleroma.gov/tenshi.png",
|
||||||
|
"height" => 1024,
|
||||||
|
"width" => 1280
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
%{
|
%{
|
||||||
"url" => [
|
"url" => [
|
||||||
@ -142,6 +149,8 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
|
|||||||
{:meta, [property: "twitter:description", content: "pleroma in a nutshell"], []},
|
{:meta, [property: "twitter:description", content: "pleroma in a nutshell"], []},
|
||||||
{:meta, [property: "twitter:card", content: "summary_large_image"], []},
|
{:meta, [property: "twitter:card", content: "summary_large_image"], []},
|
||||||
{:meta, [property: "twitter:player", content: "https://pleroma.gov/tenshi.png"], []},
|
{:meta, [property: "twitter:player", content: "https://pleroma.gov/tenshi.png"], []},
|
||||||
|
{:meta, [property: "twitter:player:width", content: "1280"], []},
|
||||||
|
{:meta, [property: "twitter:player:height", content: "1024"], []},
|
||||||
{:meta, [property: "twitter:card", content: "player"], []},
|
{:meta, [property: "twitter:card", content: "player"], []},
|
||||||
{:meta,
|
{:meta,
|
||||||
[
|
[
|
||||||
|
Loading…
Reference in New Issue
Block a user