Merge branch 'configurable-favicon' into 'develop'
Let favicon be configurable See merge request soapbox-pub/rebased!192
This commit is contained in:
commit
ad014adc1c
8 changed files with 55 additions and 32 deletions
|
@ -190,6 +190,7 @@
|
||||||
short_description: "",
|
short_description: "",
|
||||||
background_image: "/images/city.jpg",
|
background_image: "/images/city.jpg",
|
||||||
instance_thumbnail: "/instance/thumbnail.png",
|
instance_thumbnail: "/instance/thumbnail.png",
|
||||||
|
favicon: "/favicon.png",
|
||||||
limit: 5_000,
|
limit: 5_000,
|
||||||
description_limit: 5_000,
|
description_limit: 5_000,
|
||||||
remote_limit: 100_000,
|
remote_limit: 100_000,
|
||||||
|
|
|
@ -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.",
|
"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"]
|
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,
|
key: :show_reactions,
|
||||||
type: :boolean,
|
type: :boolean,
|
||||||
|
|
|
@ -17,10 +17,8 @@ def api_not_implemented(conn, _params) do
|
||||||
|> json(%{error: "Not implemented"})
|
|> json(%{error: "Not implemented"})
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirector(conn, _params, code \\ 200) do
|
def redirector(conn, params, code \\ 200) do
|
||||||
conn
|
redirector_with_ssr(conn, params, [:title, :favicon], code)
|
||||||
|> put_resp_content_type("text/html")
|
|
||||||
|> send_file(code, index_file_path())
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id} = params) do
|
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
|
end
|
||||||
|
|
||||||
def redirector_with_meta(conn, params) do
|
def redirector_with_meta(conn, params) do
|
||||||
{:ok, index_content} = File.read(index_file_path())
|
redirector_with_ssr(conn, params, [:tags, :preload, :title, :favicon])
|
||||||
|
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirector_with_preload(conn, %{"path" => ["pleroma", "admin"]}) do
|
def redirector_with_preload(conn, %{"path" => ["pleroma", "admin"]}) do
|
||||||
|
@ -53,17 +39,21 @@ def redirector_with_preload(conn, %{"path" => ["pleroma", "admin"]}) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirector_with_preload(conn, params) do
|
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())
|
{: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 =
|
response =
|
||||||
index_content
|
index_content
|
||||||
|> String.replace("<!--server-generated-meta-->", preloads <> title)
|
|> String.replace("<!--server-generated-meta-->", Enum.join(meta))
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("text/html")
|
|> put_resp_content_type("text/html")
|
||||||
|> send_resp(200, response)
|
|> send_resp(code, response)
|
||||||
end
|
end
|
||||||
|
|
||||||
def registration_page(conn, params) do
|
def registration_page(conn, params) do
|
||||||
|
@ -80,7 +70,13 @@ defp index_file_path do
|
||||||
Pleroma.Web.Plugs.InstanceStatic.file_path("index.html")
|
Pleroma.Web.Plugs.InstanceStatic.file_path("index.html")
|
||||||
end
|
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
|
try do
|
||||||
Metadata.build_tags(params)
|
Metadata.build_tags(params)
|
||||||
rescue
|
rescue
|
||||||
|
@ -94,7 +90,7 @@ defp build_tags(conn, params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp preload_data(conn, params) do
|
defp build_meta(:preload, {conn, params}) do
|
||||||
try do
|
try do
|
||||||
Preload.build_tags(conn, params)
|
Preload.build_tags(conn, params)
|
||||||
rescue
|
rescue
|
||||||
|
@ -107,4 +103,12 @@ defp preload_data(conn, params) do
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -56,7 +56,10 @@ def render("show.json", _) do
|
||||||
},
|
},
|
||||||
stats: %{mau: Pleroma.User.active_user_count()},
|
stats: %{mau: Pleroma.User.active_user_count()},
|
||||||
vapid_public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key),
|
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(),
|
configuration: configuration(),
|
||||||
soapbox: %{
|
soapbox: %{
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
<title>Welcome to Rebased</title>
|
<title>Welcome to Rebased</title>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover,user-scalable=no">
|
<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">
|
<style type="text/css">
|
||||||
:root {
|
:root {
|
||||||
--brand-color: #0482d8;
|
--brand-color: #0482d8;
|
||||||
|
|
|
@ -10,13 +10,13 @@ defmodule Pleroma.Web.FallbackTest do
|
||||||
test "GET /registration/:token", %{conn: conn} do
|
test "GET /registration/:token", %{conn: conn} do
|
||||||
response = get(conn, "/registration/foo")
|
response = get(conn, "/registration/foo")
|
||||||
|
|
||||||
assert html_response(response, 200) =~ "<!--server-generated-meta-->"
|
refute html_response(response, 200) =~ "initial-results"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "GET /*path", %{conn: conn} do
|
test "GET /*path", %{conn: conn} do
|
||||||
assert conn
|
refute conn
|
||||||
|> get("/foo")
|
|> get("/foo")
|
||||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
|> html_response(200) =~ "initial-results"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -31,21 +31,25 @@ test "GET /*path adds a title", %{conn: conn} do
|
||||||
describe "preloaded data and metadata attached to" do
|
describe "preloaded data and metadata attached to" do
|
||||||
test "GET /:maybe_nickname_or_id", %{conn: conn} do
|
test "GET /:maybe_nickname_or_id", %{conn: conn} do
|
||||||
clear_config([:instance, :name], "a cool title")
|
clear_config([:instance, :name], "a cool title")
|
||||||
|
clear_config([:instance, :favicon], "/favicon.svg")
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
user_missing = get(conn, "/foo")
|
user_missing = get(conn, "/foo")
|
||||||
user_present = get(conn, "/#{user.nickname}")
|
user_present = get(conn, "/#{user.nickname}")
|
||||||
|
|
||||||
assert html_response(user_missing, 200) =~ "<!--server-generated-meta-->"
|
refute html_response(user_missing, 200) =~ "<!--server-generated-meta-->"
|
||||||
refute html_response(user_present, 200) =~ "<!--server-generated-meta-->"
|
refute html_response(user_present, 200) =~ "<!--server-generated-meta-->"
|
||||||
assert html_response(user_present, 200) =~ "initial-results"
|
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) =~ "<title>a cool title</title>"
|
||||||
|
assert html_response(user_present, 200) =~ "<link rel=\"icon\" href=\"/favicon.svg\">"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "GET /*path", %{conn: conn} do
|
test "GET /*path", %{conn: conn} do
|
||||||
|
clear_config([:instance, :name], "Rebased")
|
||||||
|
|
||||||
assert conn
|
assert conn
|
||||||
|> get("/foo")
|
|> get("/foo")
|
||||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
|> html_response(200) =~ "Rebased"
|
||||||
|
|
||||||
refute conn
|
refute conn
|
||||||
|> get("/foo/bar")
|
|> get("/foo/bar")
|
||||||
|
|
|
@ -19,6 +19,7 @@ test "get instance information", %{conn: conn} do
|
||||||
email = Pleroma.Config.get([:instance, :email])
|
email = Pleroma.Config.get([:instance, :email])
|
||||||
thumbnail = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :instance_thumbnail])
|
thumbnail = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :instance_thumbnail])
|
||||||
background = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :background_image])
|
background = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :background_image])
|
||||||
|
favicon = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :favicon])
|
||||||
|
|
||||||
# Note: not checking for "max_toot_chars" since it's optional
|
# Note: not checking for "max_toot_chars" since it's optional
|
||||||
assert %{
|
assert %{
|
||||||
|
@ -44,7 +45,10 @@ test "get instance information", %{conn: conn} do
|
||||||
"background_image" => from_config_background,
|
"background_image" => from_config_background,
|
||||||
"shout_limit" => _,
|
"shout_limit" => _,
|
||||||
"description_limit" => _,
|
"description_limit" => _,
|
||||||
"rules" => _
|
"rules" => _,
|
||||||
|
"pleroma" => %{
|
||||||
|
"favicon" => from_config_favicon
|
||||||
|
}
|
||||||
} = result
|
} = result
|
||||||
|
|
||||||
assert result["version"] =~ "Pleroma"
|
assert result["version"] =~ "Pleroma"
|
||||||
|
@ -60,6 +64,7 @@ test "get instance information", %{conn: conn} do
|
||||||
assert email == from_config_email
|
assert email == from_config_email
|
||||||
assert thumbnail == from_config_thumbnail
|
assert thumbnail == from_config_thumbnail
|
||||||
assert background == from_config_background
|
assert background == from_config_background
|
||||||
|
assert favicon == from_config_favicon
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get instance stats", %{conn: conn} do
|
test "get instance stats", %{conn: conn} do
|
||||||
|
|
|
@ -196,7 +196,7 @@ test "render html for redirect for html format", %{conn: conn} do
|
||||||
|> get("/notice/#{like_activity.id}")
|
|> get("/notice/#{like_activity.id}")
|
||||||
|> response(200)
|
|> response(200)
|
||||||
|
|
||||||
assert resp =~ "<!--server-generated-meta-->"
|
refute resp =~ "initial-results"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "404s a private notice", %{conn: conn} do
|
test "404s a private notice", %{conn: conn} do
|
||||||
|
|
Loading…
Reference in a new issue