RedirectController: Don't replace title, but inject into the meta
This commit is contained in:
parent
3cd7ea693f
commit
631def2df2
|
@ -41,8 +41,7 @@ def redirector_with_meta(conn, params) do
|
||||||
|
|
||||||
response =
|
response =
|
||||||
index_content
|
index_content
|
||||||
|> String.replace(~r/<title>.+?<\/title>/, title)
|
|> String.replace("<!--server-generated-meta-->", tags <> preloads <> title)
|
||||||
|> String.replace("<!--server-generated-meta-->", tags <> preloads)
|
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("text/html")
|
|> put_resp_content_type("text/html")
|
||||||
|
@ -60,8 +59,7 @@ def redirector_with_preload(conn, params) do
|
||||||
|
|
||||||
response =
|
response =
|
||||||
index_content
|
index_content
|
||||||
|> String.replace(~r/<title>.+?<\/title>/, title)
|
|> String.replace("<!--server-generated-meta-->", preloads <> title)
|
||||||
|> String.replace("<!--server-generated-meta-->", preloads)
|
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("text/html")
|
|> put_resp_content_type("text/html")
|
||||||
|
|
|
@ -20,15 +20,26 @@ test "GET /*path", %{conn: conn} do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "GET /*path adds a title", %{conn: conn} do
|
||||||
|
clear_config([:instance, :name], "a cool title")
|
||||||
|
|
||||||
|
assert conn
|
||||||
|
|> get("/")
|
||||||
|
|> html_response(200) =~ "<title>a cool title</title>"
|
||||||
|
end
|
||||||
|
|
||||||
describe "preloaded data and metadata attached to" do
|
describe "preloaded data and metadata attached to" do
|
||||||
test "GET /:maybe_nickname_or_id", %{conn: conn} do
|
test "GET /:maybe_nickname_or_id", %{conn: conn} do
|
||||||
|
clear_config([:instance, :name], "a cool title")
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
user_missing = get(conn, "/foo")
|
user_missing = get(conn, "/foo")
|
||||||
user_present = get(conn, "/#{user.nickname}")
|
user_present = get(conn, "/#{user.nickname}")
|
||||||
|
|
||||||
assert(html_response(user_missing, 200) =~ "<!--server-generated-meta-->")
|
assert html_response(user_missing, 200) =~ "<!--server-generated-meta-->"
|
||||||
refute html_response(user_present, 200) =~ "<!--server-generated-meta-->"
|
refute html_response(user_present, 200) =~ "<!--server-generated-meta-->"
|
||||||
assert html_response(user_present, 200) =~ "initial-results"
|
assert html_response(user_present, 200) =~ "initial-results"
|
||||||
|
assert html_response(user_present, 200) =~ "<title>a cool title</title>"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "GET /*path", %{conn: conn} do
|
test "GET /*path", %{conn: conn} do
|
||||||
|
@ -44,10 +55,13 @@ test "GET /*path", %{conn: conn} do
|
||||||
|
|
||||||
describe "preloaded data is attached to" do
|
describe "preloaded data is attached to" do
|
||||||
test "GET /main/public", %{conn: conn} do
|
test "GET /main/public", %{conn: conn} do
|
||||||
|
clear_config([:instance, :name], "a cool title")
|
||||||
|
|
||||||
public_page = get(conn, "/main/public")
|
public_page = get(conn, "/main/public")
|
||||||
|
|
||||||
refute html_response(public_page, 200) =~ "<!--server-generated-meta-->"
|
refute html_response(public_page, 200) =~ "<!--server-generated-meta-->"
|
||||||
assert html_response(public_page, 200) =~ "initial-results"
|
assert html_response(public_page, 200) =~ "initial-results"
|
||||||
|
assert html_response(public_page, 200) =~ "<title>a cool title</title>"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "GET /main/all", %{conn: conn} do
|
test "GET /main/all", %{conn: conn} do
|
||||||
|
|
Loading…
Reference in a new issue