Merge branch 'fix-schema-org-location' into 'master'

Add a VirtualLocation field to the event URL itself when location is not defined

See merge request framasoft/mobilizon!530
This commit is contained in:
Thomas Citharel 2020-08-10 16:44:22 +02:00
commit 786c5e7f1d

View file

@ -22,7 +22,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
# We assume for now performer == organizer
"performer" => organizer,
"organizer" => organizer,
"location" => render_one(event.physical_address, ObjectView, "place.json", as: :address),
"location" => render_location(event),
"eventStatus" =>
if(event.status == :cancelled,
do: "https://schema.org/EventCancelled",
@ -67,8 +67,6 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
}
end
def render("place.json", nil), do: %{}
def render("post.json", %{post: %Post{} = post}) do
%{
"@context" => "https://schema.org",
@ -82,4 +80,16 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
"dateModified" => post.updated_at
}
end
defp render_location(%Event{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,
# but in the future it will be a special field
defp render_location(%Event{url: event_url}) do
%{
"@type" => "VirtualLocation",
"url" => event_url
}
end
end