From f303a02e8688697a6c91f4fc0d436abbdc056d6f Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 27 Oct 2022 13:13:22 -0500 Subject: [PATCH] Let favicon be configurable --- config/config.exs | 1 + config/description.exs | 6 +++ .../web/fallback/redirect_controller.ex | 42 +++++++++++-------- priv/static/index.html | 1 - test/pleroma/web/fallback_test.exs | 2 + 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/config/config.exs b/config/config.exs index 9ba8896a63..7a621cbc2f 100644 --- a/config/config.exs +++ b/config/config.exs @@ -190,6 +190,7 @@ short_description: "", background_image: "/images/city.jpg", instance_thumbnail: "/instance/thumbnail.png", + favicon: "/favicon.png", limit: 5_000, description_limit: 5_000, remote_limit: 100_000, diff --git a/config/description.exs b/config/description.exs index 535950fc2d..fff3ac33f3 100644 --- a/config/description.exs +++ b/config/description.exs @@ -988,6 +988,12 @@ "The instance thumbnail can be any image that represents your instance and is used by some apps or services when they display information about your instance.", suggestions: ["/instance/thumbnail.jpeg"] }, + %{ + key: :favicon, + type: {:string, :image}, + description: "Shortcut icon displayed in the browser, and possibly displayed by other instances.", + suggestions: ["/favicon.png"] + }, %{ key: :show_reactions, type: :boolean, diff --git a/lib/pleroma/web/fallback/redirect_controller.ex b/lib/pleroma/web/fallback/redirect_controller.ex index 1a86f7a53f..365520b658 100644 --- a/lib/pleroma/web/fallback/redirect_controller.ex +++ b/lib/pleroma/web/fallback/redirect_controller.ex @@ -33,19 +33,7 @@ def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id} end 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])}" - - response = - index_content - |> String.replace("", tags <> preloads <> title) - - conn - |> put_resp_content_type("text/html") - |> send_resp(200, response) + redirector_with_ssr(conn, params, [:tags, :preload, :title, :favicon]) end def redirector_with_preload(conn, %{"path" => ["pleroma", "admin"]}) do @@ -53,13 +41,17 @@ def redirector_with_preload(conn, %{"path" => ["pleroma", "admin"]}) do end def redirector_with_preload(conn, params) do + redirector_with_ssr(conn, params, [:preload, :title, :favicon]) + end + + defp redirector_with_ssr(conn, params, keys) do {:ok, index_content} = File.read(index_file_path()) - preloads = preload_data(conn, params) - title = "#{Pleroma.Config.get([:instance, :name])}" + + meta = compose_meta(conn, params, keys) response = index_content - |> String.replace("", preloads <> title) + |> String.replace("", Enum.join(meta)) conn |> put_resp_content_type("text/html") @@ -80,7 +72,13 @@ defp index_file_path do Pleroma.Web.Plugs.InstanceStatic.file_path("index.html") end - defp build_tags(conn, params) do + defp compose_meta(conn, params, attrs) when is_list(attrs) do + Enum.map(attrs, fn attr -> + build_meta(attr, {conn, params}) + end) + end + + defp build_meta(:tags, {conn, params}) do try do Metadata.build_tags(params) rescue @@ -94,7 +92,7 @@ defp build_tags(conn, params) do end end - defp preload_data(conn, params) do + defp build_meta(:preload, {conn, params}) do try do Preload.build_tags(conn, params) rescue @@ -107,4 +105,12 @@ defp preload_data(conn, params) do "" end end + + defp build_meta(:title, _) do + "#{Pleroma.Config.get([:instance, :name])}" + end + + defp build_meta(:favicon, _) do + "" + end end diff --git a/priv/static/index.html b/priv/static/index.html index ae0cd9a5d9..9a2b6e9e47 100644 --- a/priv/static/index.html +++ b/priv/static/index.html @@ -4,7 +4,6 @@ Welcome to Rebased -