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
1 changed files with 3 additions and 2 deletions

View File

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