Revert "Only run Floki if title is missing from the map"

This reverts commit 97d2b1a45a.
This commit is contained in:
Mark Felder 2019-06-12 18:32:28 -05:00
parent 97d2b1a45a
commit 7363a0ea8a

View file

@ -1,14 +1,15 @@
defmodule Pleroma.Web.RichMedia.Parsers.MetaTagsParser do defmodule Pleroma.Web.RichMedia.Parsers.MetaTagsParser do
def parse(html, data, prefix, error_message, key_name, value_name \\ "content") do def parse(html, data, prefix, error_message, key_name, value_name \\ "content") do
with elements = [_ | _] <- get_elements(html, key_name, prefix), with elements = [_ | _] <- get_elements(html, key_name, prefix),
page_title = get_page_title(html),
meta_data = meta_data =
Enum.reduce(elements, data, fn el, acc -> Enum.reduce(elements, data, fn el, acc ->
attributes = normalize_attributes(el, prefix, key_name, value_name) attributes = normalize_attributes(el, prefix, key_name, value_name)
Map.merge(acc, attributes) Map.merge(acc, attributes)
end) do end)
rich_meta_data = maybe_use_page_title(meta_data, html) |> Map.put_new(:title, page_title) do
{:ok, rich_meta_data} {:ok, meta_data}
else else
_e -> {:error, error_message} _e -> {:error, error_message}
end end
@ -29,10 +30,7 @@ defp normalize_attributes(html_node, prefix, key_name, value_name) do
%{String.to_atom(data[key_name]) => data[value_name]} %{String.to_atom(data[key_name]) => data[value_name]}
end end
defp maybe_use_page_title(meta_data, html) do defp get_page_title(html) do
if !Map.has_key?(meta_data, :title) do Floki.find(html, "title") |> Floki.text()
page_title = Floki.find(html, "title") |> Floki.text()
Map.put_new(meta_data, :title, page_title)
end
end end
end end