Sfoglia il codice sorgente

Set the correct height/width if the data is available when generating twittercard metadata

warnings-as-errors
Mark Felder 3 anni fa
parent
commit
5de65ce3e8
2 ha cambiato i file con 13 aggiunte e 5 eliminazioni
  1. +5
    -2
      lib/pleroma/web/metadata/providers/twitter_card.ex
  2. +8
    -3
      test/pleroma/web/metadata/providers/twitter_card_test.exs

+ 5
- 2
lib/pleroma/web/metadata/providers/twitter_card.ex Vedi 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 # TODO: Need the true width and height values here or Twitter renders an iFrame with
# a bad aspect ratio # 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)], []},
{: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: url["href"]], []},
{:meta, {:meta,
[property: "twitter:player:stream:content_type", content: url["mediaType"]], []} [property: "twitter:player:stream:content_type", content: url["mediaType"]], []}


+ 8
- 3
test/pleroma/web/metadata/providers/twitter_card_test.exs Vedi File

@@ -123,7 +123,12 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
}, },
%{ %{
"url" => [ "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", property: "twitter:player",
content: Router.Helpers.o_status_url(Endpoint, :notice_player, activity.id) 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, {:meta,
[ [
property: "twitter:player:stream", property: "twitter:player:stream",


Loading…
Annulla
Salva