Add extractor for finertech.com

This commit is contained in:
Shadowfacts 2019-10-31 19:04:15 -04:00
parent 118de4ae53
commit 8c96a94cd3
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,39 @@
defmodule Frenzy.Pipeline.Extractor.FinerTech do
@moduledoc """
Extractor for https://finertech.com
"""
alias Frenzy.Pipeline.Extractor
@behaviour Extractor
@impl Extractor
def extract(html_tree) do
case Floki.find(html_tree, ".entry-content") do
[content_elem | _] ->
# remove patreon button
content_elem = Floki.traverse_and_update(content_elem, &remove_patreon_banner/1)
{:ok, content_elem}
_ ->
{:error, "no matching element"}
end
end
@patreon_class_regex ~r/[a-z0-9_]patreon_button/i
defp remove_patreon_banner({"div", attrs, _children} = elem) do
case Enum.find(attrs, fn {attr, _val} -> attr == "class" end) do
nil ->
elem
{"class", class} ->
if Regex.match?(@patreon_class_regex, class) do
nil
else
elem
end
end
end
defp remove_patreon_banner(elem), do: elem
end