diff options
author | William Pitcock <nenolod@dereferenced.org> | 2019-01-26 14:55:12 +0000 |
---|---|---|
committer | William Pitcock <nenolod@dereferenced.org> | 2019-01-26 14:55:12 +0000 |
commit | be9abb2cc5fc219ca49ac6b32afed3eac323bf7a (patch) | |
tree | 8955e3368c35ac5a3f7201248755286bb6091d1f /lib | |
parent | 78047d57bf52e53c5f073435928983922f9538f5 (diff) | |
download | pleroma-be9abb2cc5fc219ca49ac6b32afed3eac323bf7a.tar.gz |
html: add utility function to extract first URL from an object and cache the result
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/html.ex | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index f5c6e5033..fb602d6b6 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -58,6 +58,20 @@ defmodule Pleroma.HTML 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 |