Let favicon be configurable

This commit is contained in:
Alex Gleason 2022-10-27 13:13:22 -05:00
parent 0447197378
commit f303a02e86
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
5 changed files with 33 additions and 19 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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 = "<title>#{Pleroma.Config.get([:instance, :name])}</title>"
response =
index_content
|> String.replace("<!--server-generated-meta-->", 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 = "<title>#{Pleroma.Config.get([:instance, :name])}</title>"
meta = compose_meta(conn, params, keys)
response =
index_content
|> String.replace("<!--server-generated-meta-->", preloads <> title)
|> String.replace("<!--server-generated-meta-->", 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
"<title>#{Pleroma.Config.get([:instance, :name])}</title>"
end
defp build_meta(:favicon, _) do
"<link rel=\"icon\" href=\"#{Pleroma.Config.get([:instance, :favicon])}\">"
end
end

View file

@ -4,7 +4,6 @@
<title>Welcome to Rebased</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover,user-scalable=no">
<link rel="icon" type="image/png" href="/favicon.png">
<style type="text/css">
:root {
--brand-color: #0482d8;

View file

@ -31,6 +31,7 @@ test "GET /*path adds a title", %{conn: conn} do
describe "preloaded data and metadata attached to" do
test "GET /:maybe_nickname_or_id", %{conn: conn} do
clear_config([:instance, :name], "a cool title")
clear_config([:instance, :favicon], "/favicon.svg")
user = insert(:user)
user_missing = get(conn, "/foo")
@ -40,6 +41,7 @@ test "GET /:maybe_nickname_or_id", %{conn: conn} do
refute html_response(user_present, 200) =~ "<!--server-generated-meta-->"
assert html_response(user_present, 200) =~ "initial-results"
assert html_response(user_present, 200) =~ "<title>a cool title</title>"
assert html_response(user_present, 200) =~ "<link rel=\"icon\" href=\"/favicon.svg\">"
end
test "GET /*path", %{conn: conn} do