Merge branch 'instance-feed-links' into 'master'

Expose instance feed config option in the API and show it on About page

Closes #661

See merge request framasoft/mobilizon!898
This commit is contained in:
Thomas Citharel 2021-04-19 11:18:55 +00:00
commit 9a50d7e6c5
10 changed files with 89 additions and 6 deletions

View file

@ -80,6 +80,9 @@ export const CONFIG = gql`
avatar
banner
}
instanceFeeds {
enabled
}
}
}
`;
@ -113,6 +116,9 @@ export const ABOUT = gql`
}
version
federating
instanceFeeds {
enabled
}
}
}
`;

View file

@ -984,5 +984,6 @@
"Unable to create the group. One of the pictures may be too heavy.": "Unable to create the group. One of the pictures may be too heavy.",
"Unable to update the profile. The avatar picture may be too heavy.": "Unable to update the profile. The avatar picture may be too heavy.",
"Unable to create the profile. The avatar picture may be too heavy.": "Unable to create the profile. The avatar picture may be too heavy.",
"Error while loading the preview": "Error while loading the preview"
"Error while loading the preview": "Error while loading the preview",
"Instance feeds": "Instance feeds"
}

View file

@ -1078,5 +1078,6 @@
"Unable to create the group. One of the pictures may be too heavy.": "Impossible de créer le groupe. Une des images est trop lourde.",
"Unable to update the profile. The avatar picture may be too heavy.": "Impossible de mettre à jour le profil. L'image d'avatar est probablement trop lourde.",
"Unable to create the profile. The avatar picture may be too heavy.": "Impossible de créer le profil. L'image d'avatar est probablement trop lourde.",
"Error while loading the preview": "Erreur lors du chargement de l'aperçu"
"Error while loading the preview": "Erreur lors du chargement de l'aperçu",
"Instance feeds": "Flux de l'instance"
}

View file

@ -94,4 +94,7 @@ export interface IConfig {
avatar: number;
banner: number;
};
instanceFeeds: {
enabled: boolean;
};
}

View file

@ -42,9 +42,13 @@
<table class="table is-fullwidth">
<tr>
<td>{{ $t("Instance languages") }}</td>
<td :title="this.config ? this.config.languages.join(', ') : ''">
<td
v-if="config.languages.length > 0"
:title="this.config ? this.config.languages.join(', ') : ''"
>
{{ formattedLanguageList }}
</td>
<td v-else>{{ $t("No information") }}</td>
</tr>
<tr>
<td>{{ $t("Mobilizon version") }}</td>
@ -72,6 +76,29 @@
</td>
<td v-else>{{ $t("Disabled") }}</td>
</tr>
<tr class="instance-feeds">
<td>{{ $t("Instance feeds") }}</td>
<td v-if="config.instanceFeeds.enabled" class="buttons">
<b-button
tag="a"
size="is-small"
icon-left="rss"
href="/feed/instance/atom"
target="_blank"
>{{ $t("RSS/Atom Feed") }}</b-button
>
<b-button
tag="a"
size="is-small"
icon-left="calendar-sync"
href="/feed/instance/ics"
target="_blank"
>{{ $t("ICS/WebCal Feed") }}</b-button
>
</td>
<td v-else>{{ $t("Disabled") }}</td>
</tr>
</table>
</section>
</div>
@ -177,5 +204,14 @@ section {
}
}
}
tr.instance-feeds {
height: 3rem;
td:first-child {
vertical-align: middle;
}
td:last-child {
height: 3rem;
}
}
}
</style>

View file

@ -108,6 +108,10 @@ export const configMock = {
avatar: 2_000_000,
banner: 4_000_000,
},
instanceFeeds: {
__typename: "InstanceFeeds",
enabled: false,
},
},
},
};

View file

@ -139,6 +139,9 @@ defmodule Mobilizon.GraphQL.Resolvers.Config do
default: Config.get([:instance, :upload_limit]),
avatar: Config.get([:instance, :avatar_upload_limit]),
banner: Config.get([:instance, :banner_upload_limit])
},
instance_feeds: %{
enabled: Config.get([:instance, :enable_instance_feeds])
}
}
end

View file

@ -63,6 +63,7 @@ defmodule Mobilizon.GraphQL.Schema.ConfigType do
field(:rules, :string, description: "The instance's rules")
field(:auth, :auth, description: "The instance auth methods")
field(:instance_feeds, :instance_feeds, description: "The instance's feed settings")
end
@desc """
@ -294,6 +295,10 @@ defmodule Mobilizon.GraphQL.Schema.ConfigType do
field(:banner, :integer, description: "The banner limitation, in bytes")
end
object :instance_feeds do
field(:enabled, :boolean, description: "Whether the instance-wide feeds are enabled")
end
object :config_queries do
@desc "Get the instance config"
field :config, :config do

View file

@ -83,8 +83,10 @@ defmodule Mobilizon.Addresses.Address do
def representation(nil), do: nil
def representation(%__MODULE__{} = address) do
"#{address.street} #{address.postal_code} #{address.locality} #{address.region} #{
address.country
}"
String.trim(
"#{address.street} #{address.postal_code} #{address.locality} #{address.region} #{
address.country
}"
)
end
end

View file

@ -9,6 +9,8 @@ defmodule Mobilizon.Service.Metadata.Instance do
alias Mobilizon.Config
alias Mobilizon.Service.Metadata.Utils
alias Mobilizon.Web.Endpoint
alias Mobilizon.Web.Router.Helpers, as: Routes
import Mobilizon.Web.Gettext
@doc """
Build the list of tags for the instance
@ -40,6 +42,26 @@ defmodule Mobilizon.Service.Metadata.Instance do
Tag.tag(:meta, property: "og:description", content: description),
Tag.tag(:meta, property: "og:type", content: "website"),
HTML.raw(instance_json_ld)
] ++ maybe_add_instance_feeds(Config.get([:instance, :enable_instance_feeds]))
end
@spec maybe_add_instance_feeds(boolean()) :: list()
defp maybe_add_instance_feeds(true) do
[
Tag.tag(:link,
rel: "alternate",
type: "application/atom+xml",
title: gettext("%{name}'s feed", name: Config.instance_name()) |> HTML.raw(),
href: Routes.feed_url(Endpoint, :instance, :atom)
),
Tag.tag(:link,
rel: "alternate",
type: "text/calendar",
title: gettext("%{name}'s feed", name: Config.instance_name()) |> HTML.raw(),
href: Routes.feed_url(Endpoint, :instance, :ics)
)
]
end
defp maybe_add_instance_feeds(false), do: []
end