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..bdf57dd633 100644 --- a/config/description.exs +++ b/config/description.exs @@ -988,6 +988,13 @@ "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..e5bab8ee6a 100644 --- a/lib/pleroma/web/fallback/redirect_controller.ex +++ b/lib/pleroma/web/fallback/redirect_controller.ex @@ -17,10 +17,8 @@ def api_not_implemented(conn, _params) do |> json(%{error: "Not implemented"}) end - def redirector(conn, _params, code \\ 200) do - conn - |> put_resp_content_type("text/html") - |> send_file(code, index_file_path()) + def redirector(conn, params, code \\ 200) do + redirector_with_ssr(conn, params, [:title, :favicon], code) end def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id} = params) do @@ -33,19 +31,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,17 +39,21 @@ 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, code \\ 200) 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") - |> send_resp(200, response) + |> send_resp(code, response) end def registration_page(conn, params) do @@ -80,7 +70,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 +90,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 +103,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/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex index 2215018fe2..44deca5782 100644 --- a/lib/pleroma/web/mastodon_api/views/instance_view.ex +++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex @@ -56,7 +56,10 @@ def render("show.json", _) do }, stats: %{mau: Pleroma.User.active_user_count()}, vapid_public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key), - oauth_consumer_strategies: Pleroma.Config.oauth_consumer_strategies() + oauth_consumer_strategies: Pleroma.Config.oauth_consumer_strategies(), + favicon: + URI.merge(Pleroma.Web.Endpoint.url(), Keyword.get(instance, :favicon)) + |> to_string }, configuration: configuration(), soapbox: %{ 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 -