Add extractor for macstories.net

This commit is contained in:
Shadowfacts 2019-10-31 18:48:36 -04:00
parent 957f271425
commit 118de4ae53
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
defmodule Frenzy.Pipeline.Extractor.MacStories do
@moduledoc """
Extractor for https://macstories.net
"""
alias Frenzy.Pipeline.Extractor
@behaviour Extractor
@impl Extractor
def extract(html_tree) do
case Floki.find(html_tree, ".post-content") do
[content_elem | _] ->
content_elem =
content_elem
# some images have full size links, strip those out
|> Floki.filter_out("a.view-full-size")
# rewrite non-standard images captions to <figure>/<figcaption>
|> Floki.map(&rewrite_element/1)
{:ok, content_elem}
_ ->
{:error, "no matching elements"}
end
end
defp rewrite_element({"div", [{"class", "media-wrapper"}]}) do
{"figure", []}
end
defp rewrite_element({"p", [{"class", "image-caption"}]}) do
{"figcaption", []}
end
defp rewrite_element(elem), do: elem
end