From bfc936f57cbfe0019ad8a95e45e5708f9132eb3a Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 23 Aug 2022 10:09:10 +0200 Subject: [PATCH] [JSON-LD] Only render single location when list has only one element Signed-off-by: Thomas Citharel --- lib/web/views/json_ld/object_view.ex | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/web/views/json_ld/object_view.ex b/lib/web/views/json_ld/object_view.ex index a4aa282b..3e61880f 100644 --- a/lib/web/views/json_ld/object_view.ex +++ b/lib/web/views/json_ld/object_view.ex @@ -176,6 +176,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do [] |> render_location(event) |> render_virtual_location(event) + |> maybe_render_single_element() end @spec render_location(list(), map()) :: list() @@ -207,6 +208,10 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do defp render_virtual_location(locations, _), do: locations + @spec maybe_render_single_element(list(map())) :: list(map()) | map() + defp maybe_render_single_element([location]), do: location + defp maybe_render_single_element(locations), do: locations + defp render_address(%{physical_address: %Address{} = address}), do: render_one(address, ObjectView, "address.json", as: :address)