RedirectController: Unify server-generated-meta insertion code
This commit is contained in:
parent
a5aa8ea796
commit
5d3e145dc4
|
@ -17,19 +17,24 @@ def api_not_implemented(conn, _params) do
|
||||||
|> json(%{error: "Not implemented"})
|
|> json(%{error: "Not implemented"})
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirector(conn, _params, code \\ 200) do
|
def add_generated_metadata(page_content, extra \\ "") do
|
||||||
{:ok, index_content} = File.read(index_file_path())
|
|
||||||
|
|
||||||
title = "<title>#{Pleroma.Config.get([:instance, :name])}</title>"
|
title = "<title>#{Pleroma.Config.get([:instance, :name])}</title>"
|
||||||
favicon = "<link rel='icon' href='#{Pleroma.Config.get([:instance, :favicon])}'>"
|
favicon = "<link rel='icon' href='#{Pleroma.Config.get([:instance, :favicon])}'>"
|
||||||
manifest = "<link rel='manifest' href='/manifest.json'>"
|
manifest = "<link rel='manifest' href='/manifest.json'>"
|
||||||
|
|
||||||
response =
|
page_content
|
||||||
index_content
|
|
||||||
|> String.replace(
|
|> String.replace(
|
||||||
"<!--server-generated-meta-->",
|
"<!--server-generated-meta-->",
|
||||||
title <> favicon <> manifest
|
title <> favicon <> manifest <> extra
|
||||||
)
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def redirector(conn, _params, code \\ 200) do
|
||||||
|
{:ok, index_content} = File.read(index_file_path())
|
||||||
|
|
||||||
|
response =
|
||||||
|
index_content
|
||||||
|
|> add_generated_metadata()
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("text/html")
|
|> put_resp_content_type("text/html")
|
||||||
|
@ -47,19 +52,12 @@ def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id}
|
||||||
|
|
||||||
def redirector_with_meta(conn, params) do
|
def redirector_with_meta(conn, params) do
|
||||||
{:ok, index_content} = File.read(index_file_path())
|
{:ok, index_content} = File.read(index_file_path())
|
||||||
|
|
||||||
tags = build_tags(conn, params)
|
tags = build_tags(conn, params)
|
||||||
preloads = preload_data(conn, params)
|
preloads = preload_data(conn, params)
|
||||||
title = "<title>#{Pleroma.Config.get([:instance, :name])}</title>"
|
|
||||||
favicon = "<link rel='icon' href='#{Pleroma.Config.get([:instance, :favicon])}'>"
|
|
||||||
manifest = "<link rel='manifest' href='/manifest.json'>"
|
|
||||||
|
|
||||||
response =
|
response =
|
||||||
index_content
|
index_content
|
||||||
|> String.replace(
|
|> add_generated_metadata(tags <> preloads)
|
||||||
"<!--server-generated-meta-->",
|
|
||||||
tags <> preloads <> title <> favicon <> manifest
|
|
||||||
)
|
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("text/html")
|
|> put_resp_content_type("text/html")
|
||||||
|
@ -73,13 +71,10 @@ def redirector_with_preload(conn, %{"path" => ["pleroma", "admin"]}) do
|
||||||
def redirector_with_preload(conn, params) do
|
def redirector_with_preload(conn, params) do
|
||||||
{:ok, index_content} = File.read(index_file_path())
|
{:ok, index_content} = File.read(index_file_path())
|
||||||
preloads = preload_data(conn, params)
|
preloads = preload_data(conn, params)
|
||||||
title = "<title>#{Pleroma.Config.get([:instance, :name])}</title>"
|
|
||||||
favicon = "<link rel='icon' href='#{Pleroma.Config.get([:instance, :favicon])}'>"
|
|
||||||
manifest = "<link rel='manifest' href='/manifest.json'>"
|
|
||||||
|
|
||||||
response =
|
response =
|
||||||
index_content
|
index_content
|
||||||
|> String.replace("<!--server-generated-meta-->", preloads <> title <> favicon <> manifest)
|
|> add_generated_metadata(preloads)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("text/html")
|
|> put_resp_content_type("text/html")
|
||||||
|
|
Loading…
Reference in New Issue