Compare commits

...

2 Commits

Author SHA1 Message Date
Shadowfacts b9be2879ed Fix srcsets overriding rewritten image srcs 2022-07-17 15:13:13 -04:00
Shadowfacts 852db1520f Add birchtree.me extractor 2022-07-17 15:13:08 -04:00
3 changed files with 31 additions and 1 deletions

View File

@ -0,0 +1,19 @@
defmodule Frenzy.Pipeline.Extractor.Birchtree do
@moduledoc """
Extractor for https://birchtree.me
"""
alias Frenzy.Pipeline.Extractor
@behaviour Extractor
@impl Extractor
def extract(html_tree) do
case Floki.find(html_tree, "section.post-content") do
[content_elem | _] ->
{:ok, content_elem}
_ ->
{:error, "no matching elements"}
end
end
end

View File

@ -158,6 +158,16 @@ defmodule Frenzy.Pipeline.ScrapeStage do
attr
end)
has_src = Enum.find(new_attrs, fn {name, _} -> name == "src" end)
# remove srcsets because our transformation only applies to the src attribute, so that should always be used
new_attrs =
if has_src do
Enum.reject(new_attrs, fn {name, _} -> name == "srcset" end)
else
new_attrs
end
{"img", new_attrs}
elem ->
@ -191,5 +201,5 @@ defmodule Frenzy.Pipeline.ScrapeStage do
end
end
defp image_to_data_uri(src, _site_uri, false), do: src
defp image_to_data_uri(src, site_uri, false), do: to_string(URI.merge(site_uri, src))
end

View File

@ -6,6 +6,7 @@ defmodule FrenzyWeb.ConfigureStage.ScrapeStageLive do
{"512 Pixels", Frenzy.Pipeline.Extractor.FiveTwelvePixels},
{"Ars Technica", Frenzy.Pipeline.Extractor.ArsTechnica},
{"beckyhansmeyer.com", Frenzy.Pipeline.Extractor.BeckyHansmeyer},
{"birchtree.me", Frenzy.Pipeline.Extractor.Birchtree},
{"daringfireball.net", Frenzy.Pipeline.Extractor.DaringFireball},
{"ericasadun.com", Frenzy.Pipeline.Extractor.EricaSadun},
{"finertech.com", Frenzy.Pipeline.Extractor.FinerTech},