frenzy/lib/frenzy/pipeline/extractor/whatever_scalzi.ex

31 lines
700 B
Elixir

defmodule Frenzy.Pipeline.Extractor.WhateverScalzi do
@moduledoc """
Extractor for https://whatever.scalzi.com
"""
alias Frenzy.Pipeline.Extractor
@behaviour Extractor
@impl Extractor
def extract(html_tree) do
case get_article_content(html_tree) do
nil ->
{:error, "no matching elements"}
elem ->
{:ok, elem}
end
end
defp get_article_content(html_tree) do
case Floki.find(html_tree, "article.post > div.entry-content") do
[content_elem | _] ->
# remove social media buttons that are included in the .entry-content element
Floki.filter_out(content_elem, "div#jp-post-flair")
_ ->
nil
end
end
end