@@ -2,10 +2,9 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
|
||||
alias Phoenix.HTML
|
||||
alias Phoenix.HTML.Tag
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Service.Formatter.HTML, as: HTMLFormatter
|
||||
alias Mobilizon.Web.JsonLD.ObjectView
|
||||
alias Mobilizon.Web.MediaProxy
|
||||
import Mobilizon.Web.Gettext
|
||||
import Mobilizon.Service.Metadata.Utils, only: [process_description: 2, strip_tags: 1]
|
||||
|
||||
def build_tags(%Event{} = event, locale \\ "en") do
|
||||
event = Map.put(event, :description, process_description(event.description, locale))
|
||||
@@ -41,24 +40,10 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
|
||||
]
|
||||
end
|
||||
|
||||
defp process_description(nil, locale), do: process_description("", locale)
|
||||
|
||||
defp process_description("", locale) do
|
||||
Gettext.put_locale(locale)
|
||||
gettext("The event organizer didn't add any description.")
|
||||
end
|
||||
|
||||
defp process_description(description, _locale) do
|
||||
description
|
||||
|> HTMLFormatter.strip_tags()
|
||||
|> String.slice(0..200)
|
||||
|> (&"#{&1}…").()
|
||||
end
|
||||
|
||||
# Insert JSON-LD schema by hand because Tag.content_tag wants to escape it
|
||||
defp json(%Event{title: title} = event) do
|
||||
"event.json"
|
||||
|> ObjectView.render(%{event: %{event | title: HTMLFormatter.strip_tags(title)}})
|
||||
|> ObjectView.render(%{event: %{event | title: strip_tags(title)}})
|
||||
|> Jason.encode!()
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user