projects
/
akkoma
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
47ff425
)
html.ex: optimize external url extraction
author
rinpatch
<rinpatch@sdf.org>
Wed, 2 Sep 2020 09:42:25 +0000
(12:42 +0300)
committer
rinpatch
<rinpatch@sdf.org>
Wed, 2 Sep 2020 09:45:20 +0000
(12:45 +0300)
By using a :not() selector and only extracting attributes from the
first match.
lib/pleroma/html.ex
patch
|
blob
|
history
diff --git
a/lib/pleroma/html.ex
b/lib/pleroma/html.ex
index dc1b9b840c006694b365cfea71eb288461fc5cac..20b02f091f52c2828c8c79f92101b85ab635f32c 100644
(file)
--- a/
lib/pleroma/html.ex
+++ b/
lib/pleroma/html.ex
@@
-109,8
+109,9
@@
defmodule Pleroma.HTML do
result =
content
|> Floki.parse_fragment!()
- |> Floki.filter_out("a.mention,a.hashtag,a.attachment,a[rel~=\"tag\"]")
- |> Floki.attribute("a", "href")
+ |> Floki.find("a:not(.mention,.hashtag,.attachment,[rel~=\"tag\"])")
+ |> Enum.take(1)
+ |> Floki.attribute("href")
|> Enum.at(0)
{:commit, {:ok, result}}