Add replacement for $

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-10-08 23:49:12 +02:00
parent 84b4368211
commit 6fe062ed6c

View file

@ -1020,6 +1020,7 @@ defp replace_instance_host(value, nil), do: value
defp replace_instance_host(content, host) when is_binary(content) do
content
|> String.replace("$INSTANCE$host$", host)
|> String.replace("$INSTANCE$tld$", get_tld(host, "$INSTANCE$tld$"))
end
defp replace_instance_host(object, host) when is_map(object) do
@ -1031,6 +1032,14 @@ defp replace_instance_host(object, host) when is_map(object) do
defp replace_instance_host(value, _), do: value
defp get_tld(host, default) do
with [domain | _] <- String.split(host, ".") |> Enum.reverse() do
domain
else
_ -> default
end
end
defp patch_content_map(%{"contentMap" => %{} = content_map}, host) do
content_map
|> Enum.map(fn {key, value} -> {key, replace_instance_host(value, host)} end)