Merge branch 'meta-tags-parser' into 'develop'

Title parsing improvement

See merge request pleroma/pleroma!2159
This commit is contained in:
lain 2020-01-29 10:07:26 +00:00
commit 9e0c2413b4
3 changed files with 244 additions and 1 deletions

View file

@ -48,6 +48,6 @@ defp maybe_put_title(meta, html) when meta != %{} do
defp maybe_put_title(meta, _), do: meta defp maybe_put_title(meta, _), do: meta
defp get_page_title(html) do defp get_page_title(html) do
Floki.find(html, "title") |> List.first() |> Floki.text() Floki.find(html, "html head title") |> List.first() |> Floki.text()
end end
end end

File diff suppressed because one or more lines are too long

View file

@ -85,4 +85,19 @@ test "respect only first title tag on the page" do
image: image_path image: image_path
}} }}
end end
test "takes first founded title in html head if there is html markup error" do
html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers4.html")
assert TwitterCard.parse(html, %{}) ==
{:ok,
%{
site: nil,
title:
"She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database. - The New York Times",
"app:id:googleplay": "com.nytimes.android",
"app:name:googleplay": "NYTimes",
"app:url:googleplay": "nytimes://reader/id/100000006583622"
}}
end
end end