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"})
|
||||
end
|
||||
|
||||
def redirector(conn, _params, code \\ 200) do
|
||||
{:ok, index_content} = File.read(index_file_path())
|
||||
|
||||
def add_generated_metadata(page_content, extra \\ "") do
|
||||
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'>"
|
||||
|
||||
page_content
|
||||
|> String.replace(
|
||||
"<!--server-generated-meta-->",
|
||||
title <> favicon <> manifest <> extra
|
||||
)
|
||||
end
|
||||
|
||||
def redirector(conn, _params, code \\ 200) do
|
||||
{:ok, index_content} = File.read(index_file_path())
|
||||
|
||||
response =
|
||||
index_content
|
||||
|> String.replace(
|
||||
"<!--server-generated-meta-->",
|
||||
title <> favicon <> manifest
|
||||
)
|
||||
|> add_generated_metadata()
|
||||
|
||||
conn
|
||||
|> 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
|
||||
{:ok, index_content} = File.read(index_file_path())
|
||||
|
||||
tags = build_tags(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 =
|
||||
index_content
|
||||
|> String.replace(
|
||||
"<!--server-generated-meta-->",
|
||||
tags <> preloads <> title <> favicon <> manifest
|
||||
)
|
||||
|> add_generated_metadata(tags <> preloads)
|
||||
|
||||
conn
|
||||
|> 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
|
||||
{:ok, index_content} = File.read(index_file_path())
|
||||
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 =
|
||||
index_content
|
||||
|> String.replace("<!--server-generated-meta-->", preloads <> title <> favicon <> manifest)
|
||||
|> add_generated_metadata(preloads)
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("text/html")
|
||||
|
|
Loading…
Reference in New Issue