blob: 6f46f6b4ebd6a9268d4086ec845ee160bb3c4613 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
defmodule Nola.Plugins.Link.Quirks do
@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)
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
@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
|