diff --git a/lib/something_erlang/awful_api/thread.ex b/lib/something_erlang/awful_api/thread.ex index 93ff4d1..6f45439 100644 --- a/lib/something_erlang/awful_api/thread.ex +++ b/lib/something_erlang/awful_api/thread.ex @@ -111,7 +111,11 @@ defmodule SomethingErlang.AwfulApi.Thread do if class == "sa-smilie" do {"img", attrs, []} else - t_attrs = List.keyreplace(attrs, "class", 0, {"class", "img-responsive"}) + t_attrs = + attrs + |> fix_attachment_links() + |> List.keyreplace("class", 0, {"class", "img-responsive"}) + {"img", [{"loading", "lazy"} | t_attrs], []} end end @@ -194,4 +198,15 @@ defmodule SomethingErlang.AwfulApi.Thread do {"src", src} ], []} ]} + + defp fix_attachment_links(attrs) do + {"src", src} = List.keyfind(attrs, "src", 0) + + if String.starts_with?(src, "attachment.php") do + List.keyreplace(attrs, "src", 0, {"src", "https://forums.somethingawful.com/" <> src}) + |> List.keydelete("alt", 0) + else + attrs + end + end end