html: add utility function to extract first URL from an object and cache the result

This commit is contained in:
William Pitcock 2019-01-26 14:55:12 +00:00
parent 78047d57bf
commit be9abb2cc5

View file

@ -58,6 +58,20 @@ defmodule Pleroma.HTML do
"#{signature}#{to_string(scrubber)}" "#{signature}#{to_string(scrubber)}"
end) end)
end end
def extract_first_external_url(object, content) do
key = "URL|#{object.id}"
Cachex.fetch!(:scrubber_cache, key, fn _key ->
result =
content
|> Floki.filter_out("a.mention")
|> Floki.attribute("a", "href")
|> Enum.at(0)
{:commit, result}
end)
end
end end
defmodule Pleroma.HTML.Scrubber.TwitterText do defmodule Pleroma.HTML.Scrubber.TwitterText do