Add configurable theme color (#53)
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/53
This commit is contained in:
parent
a9c82b62f2
commit
bc6bfe383f
|
@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
|
||||
### Added
|
||||
- Added move account API
|
||||
- Added ability to set instance accent-color via theme-color
|
||||
|
||||
### Removed
|
||||
- SSH frontend, to be potentially re-enabled via a bridge rather than wired into the main system
|
||||
|
|
|
@ -477,6 +477,8 @@
|
|||
],
|
||||
unfurl_nsfw: false
|
||||
|
||||
config :pleroma, Pleroma.Web.Metadata.Providers.Theme, theme_color: "#593196"
|
||||
|
||||
config :pleroma, Pleroma.Web.Preload,
|
||||
providers: [
|
||||
Pleroma.Web.Preload.Providers.Instance
|
||||
|
|
|
@ -1979,6 +1979,21 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
group: :pleroma,
|
||||
key: Pleroma.Web.Metadata.Providers.Theme,
|
||||
type: :group,
|
||||
description: "Specific provider to hand out themes to instances that scrape index.html",
|
||||
children: [
|
||||
%{
|
||||
key: :theme_color,
|
||||
type: :string,
|
||||
description:
|
||||
"The 'accent color' of the instance, used in places like misskey's instance ticker",
|
||||
suggestions: ["#593196"]
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
group: :pleroma,
|
||||
key: :rich_media,
|
||||
|
|
|
@ -1114,6 +1114,18 @@ config :pleroma, :frontends,
|
|||
|
||||
This would serve the frontend from the the folder at `$instance_static/frontends/pleroma/stable`. You have to copy the frontend into this folder yourself. You can choose the name and ref any way you like, but they will be used by mix tasks to automate installation in the future, the name referring to the project and the ref referring to a commit.
|
||||
|
||||
### Theme settings
|
||||
|
||||
Settings to change theme as exposed to the outside world, for software
|
||||
that scans `index.html` (mainly misskey)
|
||||
|
||||
```
|
||||
config :pleroma, Pleroma.Web.Metadata.Providers.Theme, theme_color: "#593196"
|
||||
```
|
||||
|
||||
This sets the `theme-color` meta tag on `index.html`, and is basically
|
||||
a hack to make misskey find the right thing.
|
||||
|
||||
## Ephemeral activities (Pleroma.Workers.PurgeExpiredActivity)
|
||||
|
||||
Settings to enable and configure expiration for ephemeral activities
|
||||
|
|
|
@ -47,7 +47,6 @@ def start(_type, _args) do
|
|||
# Disable warnings_as_errors at runtime, it breaks Phoenix live reload
|
||||
# due to protocol consolidation warnings
|
||||
Code.compiler_options(warnings_as_errors: false)
|
||||
Pleroma.Telemetry.Logger.attach()
|
||||
Config.Holder.save_default()
|
||||
Pleroma.HTML.compile_scrubbers()
|
||||
Pleroma.Config.Oban.warn()
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Telemetry.Logger do
|
||||
@moduledoc "Transforms Pleroma telemetry events to logs"
|
||||
|
||||
require Logger
|
||||
|
||||
@events [
|
||||
[:pleroma, :repo, :query]
|
||||
]
|
||||
def attach do
|
||||
:telemetry.attach_many(
|
||||
"pleroma-logger",
|
||||
@events,
|
||||
&Pleroma.Telemetry.Logger.handle_event/4,
|
||||
[]
|
||||
)
|
||||
end
|
||||
|
||||
# Passing anonymous functions instead of strings to logger is intentional,
|
||||
# that way strings won't be concatenated if the message is going to be thrown
|
||||
# out anyway due to higher log level configured
|
||||
|
||||
def handle_event(
|
||||
[:pleroma, :repo, :query] = _name,
|
||||
%{query_time: query_time} = measurements,
|
||||
%{source: source} = metadata,
|
||||
config
|
||||
) do
|
||||
logging_config = Pleroma.Config.get([:telemetry, :slow_queries_logging], [])
|
||||
|
||||
if logging_config[:enabled] &&
|
||||
logging_config[:min_duration] &&
|
||||
query_time > logging_config[:min_duration] and
|
||||
(is_nil(logging_config[:exclude_sources]) or
|
||||
source not in logging_config[:exclude_sources]) do
|
||||
log_slow_query(measurements, metadata, config)
|
||||
else
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
||||
defp log_slow_query(
|
||||
%{query_time: query_time} = _measurements,
|
||||
%{source: _source, query: query, params: query_params, repo: repo} = _metadata,
|
||||
_config
|
||||
) do
|
||||
sql_explain =
|
||||
with {:ok, %{rows: explain_result_rows}} <-
|
||||
repo.query("EXPLAIN " <> query, query_params, log: false) do
|
||||
Enum.map_join(explain_result_rows, "\n", & &1)
|
||||
end
|
||||
|
||||
{:current_stacktrace, stacktrace} = Process.info(self(), :current_stacktrace)
|
||||
|
||||
pleroma_stacktrace =
|
||||
Enum.filter(stacktrace, fn
|
||||
{__MODULE__, _, _, _} ->
|
||||
false
|
||||
|
||||
{mod, _, _, _} ->
|
||||
mod
|
||||
|> to_string()
|
||||
|> String.starts_with?("Elixir.Pleroma.")
|
||||
end)
|
||||
|
||||
Logger.warn(fn ->
|
||||
"""
|
||||
Slow query!
|
||||
|
||||
Total time: #{round(query_time / 1_000)} ms
|
||||
|
||||
#{query}
|
||||
|
||||
#{inspect(query_params, limit: :infinity)}
|
||||
|
||||
#{sql_explain}
|
||||
|
||||
#{Exception.format_stacktrace(pleroma_stacktrace)}
|
||||
"""
|
||||
end)
|
||||
end
|
||||
end
|
|
@ -12,8 +12,6 @@ defmodule Pleroma.Web.Endpoint do
|
|||
socket("/socket", Pleroma.Web.UserSocket)
|
||||
socket("/live", Phoenix.LiveView.Socket)
|
||||
|
||||
plug(Plug.Telemetry, event_prefix: [:phoenix, :endpoint])
|
||||
|
||||
plug(Pleroma.Web.Plugs.SetLocalePlug)
|
||||
plug(CORSPlug)
|
||||
plug(Pleroma.Web.Plugs.HTTPSecurityPlug)
|
||||
|
|
|
@ -55,11 +55,12 @@ def redirector_with_preload(conn, %{"path" => ["pleroma", "admin"]}) do
|
|||
def redirector_with_preload(conn, params) do
|
||||
{:ok, index_content} = File.read(index_file_path())
|
||||
preloads = preload_data(conn, params)
|
||||
tags = Metadata.build_static_tags(params)
|
||||
title = "<title>#{Pleroma.Config.get([:instance, :name])}</title>"
|
||||
|
||||
response =
|
||||
index_content
|
||||
|> String.replace("<!--server-generated-meta-->", preloads <> title)
|
||||
|> String.replace("<!--server-generated-meta-->", tags <> preloads <> title)
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("text/html")
|
||||
|
|
|
@ -5,10 +5,28 @@
|
|||
defmodule Pleroma.Web.Metadata do
|
||||
alias Phoenix.HTML
|
||||
|
||||
def build_static_tags(params) do
|
||||
providers = [
|
||||
Pleroma.Web.Metadata.Providers.Theme
|
||||
]
|
||||
|
||||
Enum.reduce(providers, "", fn parser, acc ->
|
||||
rendered_html =
|
||||
params
|
||||
|> parser.build_tags()
|
||||
|> Enum.map(&to_tag/1)
|
||||
|> Enum.map(&HTML.safe_to_string/1)
|
||||
|> Enum.join()
|
||||
|
||||
acc <> rendered_html
|
||||
end)
|
||||
end
|
||||
|
||||
def build_tags(params) do
|
||||
providers = [
|
||||
Pleroma.Web.Metadata.Providers.RelMe,
|
||||
Pleroma.Web.Metadata.Providers.RestrictIndexing
|
||||
Pleroma.Web.Metadata.Providers.RestrictIndexing,
|
||||
Pleroma.Web.Metadata.Providers.Theme
|
||||
| activated_providers()
|
||||
]
|
||||
|
||||
|
|
16
lib/pleroma/web/metadata/providers/theme.ex
Normal file
16
lib/pleroma/web/metadata/providers/theme.ex
Normal file
|
@ -0,0 +1,16 @@
|
|||
defmodule Pleroma.Web.Metadata.Providers.Theme do
|
||||
alias Pleroma.Web.Metadata.Providers.Provider
|
||||
|
||||
@behaviour Provider
|
||||
|
||||
@impl Provider
|
||||
def build_tags(_) do
|
||||
[
|
||||
{:meta,
|
||||
[
|
||||
name: "theme-color",
|
||||
content: Pleroma.Config.get([__MODULE__, :theme_color])
|
||||
], []}
|
||||
]
|
||||
end
|
||||
end
|
12
test/pleroma/web/metadata/providers/theme_test.exs
Normal file
12
test/pleroma/web/metadata/providers/theme_test.exs
Normal file
|
@ -0,0 +1,12 @@
|
|||
defmodule Pleroma.Web.Metadata.Providers.ThemeTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Web.Metadata.Providers.Theme
|
||||
|
||||
setup do: clear_config([Pleroma.Web.Metadata.Providers.Theme, :theme_color], "configured")
|
||||
|
||||
test "it renders the theme-color meta tag" do
|
||||
result = Theme.build_tags(%{})
|
||||
|
||||
assert {:meta, [name: "theme-color", content: "configured"], []} in result
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue