twitter card: handle case where image has no alt text
This commit is contained in:
parent
a1af122499
commit
8b390d27dc
|
@ -79,8 +79,7 @@ defp build_attachments(id, %{data: %{"attachment" => attachments}}) 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 @@ defp maybe_add_dimensions(metadata, url) 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
|
||||||
|
|
Loading…
Reference in New Issue