Show group address in group metadata

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-09-02 10:00:39 +02:00
parent 93728cb9d7
commit 952e592e2c
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
8 changed files with 61 additions and 28 deletions

View File

@ -731,7 +731,6 @@
"any distance": "any distance",
"Group visibility": "Group visibility",
"The group will be publicly listed in search results and may be suggested in the explore section. Only public informations will be shown on it's page.": "The group will be publicly listed in search results and may be suggested in the explore section. Only public informations will be shown on it's page.",
"You'll need to transmit the group URL so people may access the group's profile.": "You'll need to transmit the group URL so people may access the group's profile.",
"Group address": "Group address",
"Events tagged with {tag}": "Events tagged with {tag}",
"Explore events": "Explore events",
@ -793,5 +792,6 @@
"A place to publish something to the whole world, your community or just your group members.": "A place to publish something to the whole world, your community or just your group members.",
"No posts found": "No posts found",
"Last sign-in": "Last sign-in",
"Last IP adress": "Last IP adress"
"Last IP adress": "Last IP adress",
"You'll need to transmit the group URL so people may access the group's profile. The group won't be findable in Mobilizon's search or regular search engines.": "You'll need to transmit the group URL so people may access the group's profile. The group won't be findable in Mobilizon's search or regular search engines."
}

View File

@ -456,7 +456,6 @@
"Please refresh the page and retry.": "Merci de rafraîchir la page puis réessayer.",
"Post": "Billet",
"Post a comment": "Ajouter un commentaire",
"Post a public message": "Poster un message public",
"Post a reply": "Envoyer une réponse",
"Postal Code": "Code postal",
"Posts": "Billets",
@ -634,10 +633,6 @@
"Username": "Pseudo",
"Users": "Utilisateur⋅ice⋅s",
"View a reply": "Aucune réponse | Voir une réponse | Voir {totalReplies} réponses",
"View all discussions": "Voir toutes les discussions",
"View all events": "Voir tous les événements",
"View all resources": "Voir toutes les resources",
"View all todos": "Voir tous les todos",
"View all upcoming events": "Voir tous les événements à venir",
"View event page": "Voir la page de l'évènement",
"View everything": "Voir tout",
@ -684,7 +679,6 @@
"You will be redirected to the original instance": "Vous allez être redirigé⋅e vers l'instance d'origine",
"You wish to participate to the following event": "Vous souhaitez participer à l'événement suivant",
"You'll get a weekly recap every Monday for upcoming events, if you have any.": "Vous recevrez un récapitulatif hebdomadaire chaque lundi pour les événements de la semaine, si vous en avez.",
"You'll need to transmit the group URL so people may access the group's profile.": "Vous aurez besoin de transmettre l'URL du groupe pour que d'autres personnes accèdent au profil du groupe.",
"You'll receive a confirmation email.": "Vous recevrez un email de confirmation.",
"Your account has been successfully deleted": "Votre compte a été supprimé avec succès",
"Your account has been validated": "Votre compte a été validé",
@ -798,5 +792,6 @@
"A place to publish something to the whole world, your community or just your group members.": "Un endroit pour publier quelque chose à l'intention du monde entier, de votre communauté ou simplement des membres de votre groupe.",
"No posts found": "Aucun billet trouvé",
"Last sign-in": "Dernière connexion",
"Last IP adress": "Dernière addresse IP"
"Last IP adress": "Dernière addresse IP",
"You'll need to transmit the group URL so people may access the group's profile. The group won't be findable in Mobilizon's search or regular search engines.": "Vous aurez besoin de transmettre l'URL du groupe pour que d'autres personnes accèdent au profil du groupe. Le groupe ne sera pas trouvable dans la recherche de Mobilizon ni dans les moteurs de recherche habituels."
}

View File

@ -61,7 +61,9 @@
:native-value="GroupVisibility.UNLISTED"
>{{ $t("Only accessible through link") }}<br />
<small>{{
$t("You'll need to transmit the group URL so people may access the group's profile.")
$t(
"You'll need to transmit the group URL so people may access the group's profile. The group won't be findable in Mobilizon's search or regular search engines."
)
}}</small>
</b-radio>
<p class="control">

View File

@ -187,7 +187,7 @@ defmodule Mobilizon.Actors do
def get_actor_by_name_with_preload(name, type \\ nil) do
name
|> get_actor_by_name(type)
|> Repo.preload([:organized_events, :user])
|> Repo.preload([:organized_events, :user, :physical_address])
end
@doc """

View File

@ -1,10 +1,12 @@
defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do
alias Phoenix.HTML
alias Phoenix.HTML.Tag
alias Mobilizon.Actors.Actor
alias Mobilizon.Web.JsonLD.ObjectView
alias Mobilizon.Web.MediaProxy
def build_tags(%Actor{} = actor, _locale \\ "en") do
tags = [
[
Tag.tag(:meta, property: "og:title", content: Actor.display_name_and_username(actor)),
Tag.tag(:meta, property: "og:url", content: actor.url),
Tag.tag(:meta, property: "og:description", content: actor.summary),
@ -12,7 +14,12 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do
Tag.tag(:meta, property: "profile:username", content: actor.preferred_username),
Tag.tag(:meta, property: "twitter:card", content: "summary")
]
|> maybe_add_avatar(actor)
|> maybe_add_group_schema(actor)
end
@spec maybe_add_avatar(list(Tag.t()), Actor.t()) :: list(Tag.t())
defp maybe_add_avatar(tags, actor) do
if is_nil(actor.avatar) do
tags
else
@ -20,4 +27,17 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do
[Tag.tag(:meta, property: "og:image", content: actor.avatar.url |> MediaProxy.url())]
end
end
defp maybe_add_group_schema(tags, %Actor{type: :Group} = group) do
tags ++ [~s{<script type="application/ld+json">#{json(group)}</script>} |> HTML.raw()]
end
defp maybe_add_group_schema(tags, _), do: tags
# Insert JSON-LD schema by hand because Tag.content_tag wants to escape it
defp json(%Actor{} = group) do
"group.json"
|> ObjectView.render(%{group: group})
|> Jason.encode!()
end
end

View File

@ -23,7 +23,7 @@ defmodule Mobilizon.Web.Cache.ActivityPub do
{:commit, Actor.t()} | {:ignore, nil}
def get_actor_by_name(name) do
Cachex.fetch(@cache, "actor_" <> name, fn "actor_" <> name ->
case Actors.get_actor_by_name(name) do
case Actors.get_actor_by_name_with_preload(name) do
%Actor{} = actor ->
{:commit, actor}

View File

@ -157,12 +157,7 @@ defmodule Mobilizon.Web.PageController do
defp is_local?(%{local: local}), do: if(local, do: true, else: :remote)
defp is_local?(_), do: false
defp maybe_add_noindex_header(conn, %Event{visibility: visibility})
when visibility != :public do
put_resp_header(conn, "x-robots-tag", "noindex")
end
defp maybe_add_noindex_header(conn, %Post{visibility: visibility})
defp maybe_add_noindex_header(conn, %{visibility: visibility})
when visibility != :public do
put_resp_header(conn, "x-robots-tag", "noindex")
end

View File

@ -8,6 +8,16 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
alias Mobilizon.Web.JsonLD.ObjectView
alias Mobilizon.Web.MediaProxy
def render("group.json", %{group: %Actor{} = group}) do
%{
"@context" => "http://schema.org",
"@type" => "Organization",
"url" => group.url,
"name" => group.name || group.preferred_username,
"address" => render_address(group)
}
end
def render("event.json", %{event: %Event{} = event}) do
organizer = %{
"@type" => if(event.organizer_actor.type == :Group, do: "Organization", else: "Person"),
@ -56,7 +66,12 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
%{
"@type" => "Place",
"name" => address.description,
"address" => %{
"address" => render_one(address, ObjectView, "address.json", as: :address)
}
end
def render("address.json", %{address: %Address{} = address}) do
%{
"@type" => "PostalAddress",
"streetAddress" => address.street,
"addressLocality" => address.locality,
@ -64,7 +79,6 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
"addressRegion" => address.region,
"addressCountry" => address.country
}
}
end
def render("post.json", %{post: %Post{} = post}) do
@ -81,7 +95,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
}
end
defp render_location(%Event{physical_address: %Address{} = address}),
defp render_location(%{physical_address: %Address{} = address}),
do: render_one(address, ObjectView, "place.json", as: :address)
# For now the Virtual Location of an event is it's own URL,
@ -92,4 +106,11 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
"url" => event_url
}
end
defp render_location(_), do: nil
defp render_address(%{physical_address: %Address{} = address}),
do: render_one(address, ObjectView, "address.json", as: :address)
defp render_address(_), do: nil
end