Various refactoring and typespec improvements
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -192,7 +192,7 @@ defmodule Mobilizon.Service.RichMedia.Parser do
|
||||
end
|
||||
end
|
||||
|
||||
@spec maybe_parse(String.t()) :: {:halt, map()} | {:cont, map()}
|
||||
@spec maybe_parse(String.t()) :: map()
|
||||
defp maybe_parse(html) do
|
||||
Enum.reduce_while(parsers(), %{}, fn parser, acc ->
|
||||
case parser.parse(html, acc) do
|
||||
@@ -286,7 +286,7 @@ defmodule Mobilizon.Service.RichMedia.Parser do
|
||||
end
|
||||
end
|
||||
|
||||
@spec check_remote_picture_path(map()) :: map()
|
||||
@spec check_remote_picture_path(map()) :: {:ok, map()}
|
||||
defp check_remote_picture_path(%{image_remote_url: image_remote_url, url: url} = data)
|
||||
when is_binary(image_remote_url) and is_binary(url) do
|
||||
Logger.debug("Checking image_remote_url #{image_remote_url}")
|
||||
|
||||
@@ -73,9 +73,6 @@ defmodule Mobilizon.Service.RichMedia.Parsers.MetaTagsParser do
|
||||
"" ->
|
||||
meta
|
||||
|
||||
descriptions when is_list(descriptions) and length(descriptions) > 0 ->
|
||||
Map.put_new(meta, :description, hd(descriptions))
|
||||
|
||||
description ->
|
||||
Map.put_new(meta, :description, description)
|
||||
end
|
||||
@@ -99,8 +96,8 @@ defmodule Mobilizon.Service.RichMedia.Parsers.MetaTagsParser do
|
||||
with {:ok, document} <- Floki.parse_document(html),
|
||||
elem when not is_nil(elem) <-
|
||||
document |> Floki.find("html head meta[name='description']") |> List.first(),
|
||||
description when is_binary(description) <- Floki.attribute(elem, "content") do
|
||||
description
|
||||
[_ | _] = descriptions <- Floki.attribute(elem, "content") do
|
||||
hd(descriptions)
|
||||
else
|
||||
_ -> ""
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user