2019-03-04 17:20:18 +01:00
|
|
|
defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
|
|
|
|
alias Phoenix.HTML
|
|
|
|
alias Phoenix.HTML.Tag
|
|
|
|
alias Mobilizon.Events.Event
|
2019-03-04 18:38:30 +01:00
|
|
|
alias MobilizonWeb.JsonLD.ObjectView
|
2019-03-04 17:20:18 +01:00
|
|
|
|
|
|
|
def build_tags(%Event{} = event) do
|
|
|
|
[
|
|
|
|
Tag.tag(:meta, property: "og:title", content: event.title),
|
|
|
|
Tag.tag(:meta, property: "og:url", content: event.url),
|
|
|
|
Tag.tag(:meta, property: "og:description", content: event.description),
|
|
|
|
Tag.tag(:meta, property: "og:type", content: "website"),
|
|
|
|
Tag.tag(:meta, property: "og:image", content: event.thumbnail),
|
|
|
|
Tag.tag(:meta, property: "og:image", content: event.large_image),
|
2019-04-17 17:13:20 +02:00
|
|
|
Tag.tag(:meta, property: "twitter:card", content: "summary_large_image"),
|
|
|
|
~s{<script type="application/ld+json">#{json(event)}</script>} |> HTML.raw()
|
2019-03-04 17:20:18 +01:00
|
|
|
]
|
|
|
|
end
|
2019-03-04 18:38:30 +01:00
|
|
|
|
|
|
|
# Insert JSON-LD schema by hand because Tag.content_tag wants to escape it
|
2019-04-17 17:13:20 +02:00
|
|
|
defp json(%Event{} = event) do
|
|
|
|
"event.json"
|
|
|
|
|> ObjectView.render(%{event: event})
|
|
|
|
|> Jason.encode!()
|
2019-03-04 18:38:30 +01:00
|
|
|
end
|
2019-03-04 17:20:18 +01:00
|
|
|
end
|