29 lines
797 B
Elixir
29 lines
797 B
Elixir
defmodule Frenzy.Pipeline.Extractor.Util do
|
|
@doc """
|
|
WordPress Jetpack uses a 1x1 pixel transparent gif in a srcset to keep browsers from loading images
|
|
by overriding the src attribute. We want to strip those so the images actually load.
|
|
"""
|
|
@spec strip_wp_lazy_loading(Floki.html_tree()) :: Floki.html_tree()
|
|
def strip_wp_lazy_loading(tree) do
|
|
Floki.map(tree, fn
|
|
{"img", attrs} = el ->
|
|
class = Enum.find(attrs, fn {k, _} -> k == "class" end)
|
|
|
|
if !is_nil(class) && String.contains?(elem(class, 1), "jetpack-lazy-image") do
|
|
{
|
|
"img",
|
|
Enum.filter(attrs, fn
|
|
{"srcset", _} -> false
|
|
_ -> true
|
|
end)
|
|
}
|
|
else
|
|
el
|
|
end
|
|
|
|
el ->
|
|
el
|
|
end)
|
|
end
|
|
end
|