summaryrefslogtreecommitdiff
path: root/lib/plugins/link/quirks.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plugins/link/quirks.ex')
-rw-r--r--lib/plugins/link/quirks.ex47
1 files changed, 30 insertions, 17 deletions
diff --git a/lib/plugins/link/quirks.ex b/lib/plugins/link/quirks.ex
index 5acfdac..6f46f6b 100644
--- a/lib/plugins/link/quirks.ex
+++ b/lib/plugins/link/quirks.ex
@@ -1,32 +1,45 @@
defmodule Nola.Plugins.Link.Quirks do
- # def uri(%URI{host: "x.com"} = uri) do
- # %URI{uri | host: "vxtwitter.com"}
- # end
+ @rewrite_hosts "./lib/plugins/link/data/quirks_rewrite_host.txt"
+ |> Util.read_file_list!()
+ |> Enum.map(fn line ->
+ [old, new] = String.split(line, ":")
+ {old, new}
+ end)
+ |> Enum.map(fn {old, new} -> [{old, new}, {"www.#{old}", new}] end)
+ |> List.flatten()
+ |> then(fn list ->
+ IO.puts("Link Quirks: rewrite_hosts: #{inspect(list)}")
+ list
+ end)
- # reddit: new reddit don't have titles for pages we don't handle in the reddit module
- # fallback to old. which has nice titles
- def uri(%URI{host: reddit} = uri) when reddit in ["www.reddit.com", "reddit.com"] do
- %URI{uri | host: "old.reddit.com"}
+ for {old, new} <- @rewrite_hosts do
+ def uri(%URI{host: unquote(old)} = uri) do
+ %URI{uri | host: unquote(new)}
+ end
end
def uri(url) do
url
end
- def user_agent(host)
- when host in [
- "x.com",
- "vxtwitter.com",
- "fxtwitter.com",
- "instagram.com",
- "facebook.com",
- "xnstagram.com",
- "ddinstagram.com"
- ] do
+ @telegram_bot_hosts "./lib/plugins/link/data/quirks_telegram_bot_user_agent.txt"
+ |> Util.read_file_list!()
+ |> Enum.map(fn h -> [h, "www.#{h}"] end)
+ |> List.flatten()
+ |> then(fn list ->
+ IO.puts("Link Quirks: telegram_bot_hosts: #{inspect(list)}")
+ list
+ end)
+
+ def user_agent(host) when host in @telegram_bot_hosts do
"TelegramBot (like TwitterBot)"
end
def user_agent(_host) do
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36"
end
+
+ def list() do
+ [rewrite_hosts: @rewrite_hosts, telegram_bot_hosts: @telegram_bot_hosts]
+ end
end