From 295e4a4da3fe51b953351cad2128eb8008d0cc6c Mon Sep 17 00:00:00 2001 From: Oneric Date: Thu, 15 May 2025 20:39:39 +0200 Subject: [PATCH] api/masto/instance: add short_description field Added in Mastodon 2.9.2 (June 2019) this is plain-text-only and supposed to be shorter compared to the older description field. Some clients were reported to require this field to properly function. Reported-by: https://akkoma.dev/paulyd --- config/config.exs | 3 +++ config/description.exs | 11 ++++++++++- docs/docs/configuration/cheatsheet.md | 7 ++++++- lib/pleroma/web/mastodon_api/views/instance_view.ex | 2 ++ lib/pleroma/web/nodeinfo/nodeinfo.ex | 8 +++++++- .../controllers/instance_controller_test.exs | 1 + 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/config/config.exs b/config/config.exs index bcfccf97b..54f8b1d8f 100644 --- a/config/config.exs +++ b/config/config.exs @@ -194,7 +194,10 @@ name: "Akkoma", email: "example@example.com", notify_email: "noreply@example.com", + # allowed to use HTML (if short_description is set) description: "Akkoma: The cooler fediverse server", + # only plain text (defaults to description) + short_description: nil, background_image: "/images/city.jpg", instance_thumbnail: "/instance/thumbnail.jpeg", limit: 5_000, diff --git a/config/description.exs b/config/description.exs index 2a7f3344d..c6584a3e7 100644 --- a/config/description.exs +++ b/config/description.exs @@ -566,7 +566,16 @@ key: :description, type: :string, description: - "The instance's description. It can be seen in nodeinfo and `/api/v1/instance`", + "The instance's description. It may use HTML and can be seen in `/api/v1/instance` and nodeifno if no short description is set", + suggestions: [ + "Very cool instance" + ] + }, + %{ + key: :short_description, + type: :string, + description: + "A brief instance description. It must be plain text and can be seen in `/api/v1/instance` and nodeinfo", suggestions: [ "Very cool instance" ] diff --git a/docs/docs/configuration/cheatsheet.md b/docs/docs/configuration/cheatsheet.md index 425488958..b90f6974a 100644 --- a/docs/docs/configuration/cheatsheet.md +++ b/docs/docs/configuration/cheatsheet.md @@ -12,7 +12,12 @@ To add configuration to your config file, you can copy it from the base config. * `name`: The instance’s name. * `email`: Email used to reach an Administrator/Moderator of the instance. * `notify_email`: Email used for notifications. -* `description`: The instance’s description, can be seen in nodeinfo and `/api/v1/instance`. +* `short_description`: A brief, plain-text-only instance description. + Can be seen in nodeinfo and `/api/v1/instance`. + Defaults to `description` if unset +* `description`: The instance’s more detailed description. + This is allowed to use HTML if `short_description` is set. + Can be seen in `api/v1/instance`. * `limit`: Posts character limit (CW/Subject included in the counter). * `description_limit`: The character limit for image descriptions. * `remote_limit`: Hard character limit beyond which remote posts will be dropped. diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex index 2b5354873..b5fc4df0e 100644 --- a/lib/pleroma/web/mastodon_api/views/instance_view.ex +++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex @@ -17,6 +17,8 @@ def render("show.json", _) do uri: Pleroma.Web.Endpoint.url(), title: Keyword.get(instance, :name), description: Keyword.get(instance, :description), + short_description: + Keyword.get(instance, :short_description) || Keyword.get(instance, :description), version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})", email: Keyword.get(instance, :email), urls: %{ diff --git a/lib/pleroma/web/nodeinfo/nodeinfo.ex b/lib/pleroma/web/nodeinfo/nodeinfo.ex index 532ae53a7..25b1bfe64 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo.ex @@ -9,6 +9,12 @@ defmodule Pleroma.Web.Nodeinfo.Nodeinfo do alias Pleroma.Web.Federator.Publisher alias Pleroma.Web.MastodonAPI.InstanceView + defp description() do + # The text in nodeinfo should be plain text and preferably not too long + Config.get([:instance, :short_description]) || + Config.get([:instance, :description]) + end + # returns a nodeinfo 2.0 map, since 2.1 just adds a repository field # under software. def get_nodeinfo("2.0") do @@ -43,7 +49,7 @@ def get_nodeinfo("2.0") do }, metadata: %{ nodeName: Config.get([:instance, :name]), - nodeDescription: Config.get([:instance, :description]), + nodeDescription: description(), private: !Config.get([:instance, :public], true), suggestions: %{ enabled: false diff --git a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs index 39e9629eb..61a9337f6 100644 --- a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs @@ -23,6 +23,7 @@ test "get instance information", %{conn: conn} do "uri" => _, "title" => _, "description" => _, + "short_description" => _, "version" => _, "email" => from_config_email, "urls" => %{