From 5d3e145dc4090dc5709a649ee5d646b637da252e Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 14 Nov 2023 11:01:02 +0100 Subject: [PATCH] RedirectController: Unify server-generated-meta insertion code --- .../web/fallback/redirect_controller.ex | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/lib/pleroma/web/fallback/redirect_controller.ex b/lib/pleroma/web/fallback/redirect_controller.ex index 005a5da8b..4a0885fab 100644 --- a/lib/pleroma/web/fallback/redirect_controller.ex +++ b/lib/pleroma/web/fallback/redirect_controller.ex @@ -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 = "#{Pleroma.Config.get([:instance, :name])}" favicon = "" manifest = "" + page_content + |> String.replace( + "", + 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( - "", - 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 = "#{Pleroma.Config.get([:instance, :name])}" - favicon = "" - manifest = "" response = index_content - |> String.replace( - "", - 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 = "#{Pleroma.Config.get([:instance, :name])}" - favicon = "" - manifest = "" response = index_content - |> String.replace("", preloads <> title <> favicon <> manifest) + |> add_generated_metadata(preloads) conn |> put_resp_content_type("text/html")