From 992e3af23796fae3897ea1303bbc00537e88bad3 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 10 Aug 2020 16:22:15 +0200 Subject: [PATCH] Add a VirtualLocation field to the event URL itself when location is not defined Signed-off-by: Thomas Citharel --- lib/web/views/json_ld/object_view.ex | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/web/views/json_ld/object_view.ex b/lib/web/views/json_ld/object_view.ex index 03fa0fbb2..59e69976c 100644 --- a/lib/web/views/json_ld/object_view.ex +++ b/lib/web/views/json_ld/object_view.ex @@ -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