Merge branch 'fix-lang-not-detected-on-fallback-pages' into 'master'

Fix lang not detected on fallback pages

See merge request framasoft/mobilizon!456
This commit is contained in:
Thomas Citharel 2020-06-09 18:00:42 +02:00
commit 503616fa60
3 changed files with 12 additions and 11 deletions

View File

@ -3,11 +3,12 @@ defmodule Mobilizon.Web.ErrorView do
View for errors View for errors
""" """
use Mobilizon.Web, :view use Mobilizon.Web, :view
alias Mobilizon.Service.Metadata.Instance
alias Mobilizon.Web.PageView
def render("404.html", _assigns) do def render("404.html", %{conn: conn}) do
with {:ok, index_content} <- File.read(index_file_path()) do tags = Instance.build_tags()
{:safe, index_content} PageView.inject_tags(conn, tags)
end
end end
def render("404.json", _assigns) do def render("404.json", _assigns) do
@ -48,8 +49,4 @@ defmodule Mobilizon.Web.ErrorView do
Logger.warn("Template #{inspect(template)} not found") Logger.warn("Template #{inspect(template)} not found")
render("500.html", assigns) render("500.html", assigns)
end end
defp index_file_path do
Path.join(Application.app_dir(:mobilizon, "priv/static"), "index.html")
end
end end

View File

@ -60,7 +60,7 @@ defmodule Mobilizon.Web.PageView do
end end
@spec inject_tags(Conn.t(), List.t()) :: {:safe, String.t()} @spec inject_tags(Conn.t(), List.t()) :: {:safe, String.t()}
defp inject_tags(conn, tags) do def inject_tags(conn, tags) do
with {:ok, index_content} <- File.read(index_file_path()) do with {:ok, index_content} <- File.read(index_file_path()) do
locale = get_locale(conn) locale = get_locale(conn)

View File

@ -6,9 +6,13 @@ defmodule Mobilizon.Web.ErrorViewTest do
alias Mobilizon.Web.ErrorView alias Mobilizon.Web.ErrorView
test "renders 404.html" do test "renders 404.html", %{conn: conn} do
# Produced HTML might have new lines inside # Produced HTML might have new lines inside
assert Regex.replace(~r/(\r\n|\n|\r) +/, render_to_string(ErrorView, "404.html", []), " ") =~ assert Regex.replace(
~r/(\r\n|\n|\r) +/,
render_to_string(ErrorView, "404.html", %{conn: conn}),
" "
) =~
"We're sorry but mobilizon doesn't work properly without JavaScript enabled. Please enable it to continue." "We're sorry but mobilizon doesn't work properly without JavaScript enabled. Please enable it to continue."
end end