30 lines
814 B
Elixir
30 lines
814 B
Elixir
defmodule WhoNeedHelpWeb.SearchMetadata do
|
|
@moduledoc false
|
|
|
|
@locales ~w(en uk ru)
|
|
|
|
def public_page_assigns(path) when is_binary(path) do
|
|
locale = Gettext.get_locale(WhoNeedHelpWeb.Gettext)
|
|
|
|
[
|
|
page_robots: "index, follow",
|
|
canonical_url: localized_url(path, locale),
|
|
language_alternates:
|
|
Enum.map(@locales, &{&1, localized_url(path, &1)}) ++
|
|
[{"x-default", absolute_url(path)}]
|
|
]
|
|
end
|
|
|
|
def localized_url(path, "en"), do: absolute_url(path)
|
|
|
|
def localized_url(path, locale) when locale in @locales do
|
|
absolute_url(path) <> "?" <> URI.encode_query(%{"locale" => locale})
|
|
end
|
|
|
|
def localized_url(path, _unknown_locale), do: absolute_url(path)
|
|
|
|
def absolute_url(path) do
|
|
String.trim_trailing(WhoNeedHelpWeb.Endpoint.url(), "/") <> path
|
|
end
|
|
end
|