twitter card: handle case where image has no alt text

This commit is contained in:
faried nawaz 2023-05-18 03:20:44 +05:00
parent a1af122499
commit 8b390d27dc
No known key found for this signature in database
GPG key ID: C8EBC3669D3539B4

View file

@ -79,8 +79,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
name: "twitter:image", name: "twitter:image",
content: MediaProxy.url(url["href"]) content: MediaProxy.url(url["href"])
], []}, ], []},
{:meta, [property: "twitter:image:alt", content: truncate(attachment["name"])], {:meta, [name: "twitter:image:alt", content: truncate(attachment["name"])], []}
[]}
| acc | acc
] ]
|> maybe_add_dimensions(url) |> maybe_add_dimensions(url)
@ -133,6 +132,8 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
end end
end end
defp truncate(nil), do: ""
defp truncate(text) do defp truncate(text) do
# truncate to 420 characters # truncate to 420 characters
# see https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/markup # see https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/markup