Fix srcsets overriding rewritten image srcs

This commit is contained in:
Shadowfacts 2022-07-17 15:13:13 -04:00
parent 852db1520f
commit b9be2879ed
1 changed files with 11 additions and 1 deletions

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