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
1 changed files with 14 additions and 0 deletions

View File

@ -58,6 +58,20 @@ defp generate_scrubber_signature(scrubbers) do
"#{signature}#{to_string(scrubber)}"
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
defmodule Pleroma.HTML.Scrubber.TwitterText do