Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
d4ac9445
Commit
d4ac9445
authored
Jun 08, 2021
by
feld
Browse files
Twittercard metadata for images should also include dimensions if available
parent
5de65ce3
Pipeline
#36495
failed with stages
in 10 minutes and 35 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/metadata/providers/twitter_card.ex
View file @
d4ac9445
...
...
@@ -55,7 +55,9 @@ defp build_attachments(id, %{data: %{"attachment" => attachments}}) 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,16 +75,13 @@ defp build_attachments(id, %{data: %{"attachment" => attachments}}) 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"
->
height
=
url
[
"height"
]
||
480
width
=
url
[
"width"
]
||
480
[
{
:meta
,
[
property:
"twitter:card"
,
content:
"player"
],
[]},
{
:meta
,
[
property:
"twitter:player"
,
content:
player_url
(
id
)],
[]},
...
...
test/pleroma/web/metadata/providers/twitter_card_test.exs
View file @
d4ac9445
...
...
@@ -111,7 +111,14 @@ test "it renders supported types of attachments and skips unknown types" do
"content"
=>
"pleroma in a nutshell"
,
"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"
=>
[
...
...
@@ -142,6 +149,8 @@ test "it renders supported types of attachments and skips unknown types" do
{
:meta
,
[
property:
"twitter:description"
,
content:
"pleroma in a nutshell"
],
[]},
{
:meta
,
[
property:
"twitter:card"
,
content:
"summary_large_image"
],
[]},
{
: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
,
[
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment