logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: 5d3e145dc4090dc5709a649ee5d646b637da252e
parent a5aa8ea79603e22541de04c26293dc87bd2f2ed8
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 14 Nov 2023 11:01:02 +0100

RedirectController: Unify server-generated-meta insertion code

Diffstat:

Mlib/pleroma/web/fallback/redirect_controller.ex33++++++++++++++-------------------
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 @@ -17,19 +17,24 @@ defmodule Pleroma.Web.Fallback.RedirectController 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 @@ defmodule Pleroma.Web.Fallback.RedirectController do 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 @@ defmodule Pleroma.Web.Fallback.RedirectController 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")