Redirect properly to correct endpoint depending on content-type

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-03-04 17:20:18 +01:00
parent 634157eb4b
commit 66e67aa816
12 changed files with 237 additions and 70 deletions

6
lib/service/metadata.ex Normal file
View File

@@ -0,0 +1,6 @@
defprotocol Mobilizon.Service.Metadata do
@doc """
Build tags
"""
def build_tags(entity)
end

View File

@@ -0,0 +1,25 @@
defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do
alias Phoenix.HTML
alias Phoenix.HTML.Tag
alias Mobilizon.Actors.Actor
require Logger
def build_tags(%Actor{} = actor) do
actor
|> do_build_tags()
|> Enum.map(&HTML.safe_to_string/1)
|> Enum.reduce("", fn tag, acc -> acc <> tag end)
end
defp do_build_tags(%Actor{} = actor) do
[
Tag.tag(:meta, property: "og:title", content: Actor.display_name_and_username(actor)),
Tag.tag(:meta, property: "og:url", content: actor.url),
Tag.tag(:meta, property: "og:description", content: actor.summary),
Tag.tag(:meta, property: "og:type", content: "profile"),
Tag.tag(:meta, property: "profile:username", content: actor.preferred_username),
Tag.tag(:meta, property: "og:image", content: actor.avatar_url),
Tag.tag(:meta, property: "twitter:card", content: "summary")
]
end
end

View File

@@ -0,0 +1,22 @@
defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Comment do
alias Phoenix.HTML
alias Phoenix.HTML.Tag
alias Mobilizon.Events.Comment
def build_tags(%Comment{} = comment) do
comment
|> do_build_tags()
|> Enum.map(&HTML.safe_to_string/1)
|> Enum.reduce("", fn tag, acc -> acc <> tag end)
end
defp do_build_tags(%Comment{} = comment) do
[
Tag.tag(:meta, property: "og:title", content: comment.actor.preferred_username),
Tag.tag(:meta, property: "og:url", content: comment.url),
Tag.tag(:meta, property: "og:description", content: comment.text),
Tag.tag(:meta, property: "og:type", content: "website"),
Tag.tag(:meta, property: "twitter:card", content: "summary")
]
end
end

View File

@@ -0,0 +1,24 @@
defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
alias Phoenix.HTML
alias Phoenix.HTML.Tag
alias Mobilizon.Events.Event
def build_tags(%Event{} = event) do
event
|> do_build_tags()
|> Enum.map(&HTML.safe_to_string/1)
|> Enum.reduce("", fn tag, acc -> acc <> tag end)
end
defp do_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),
Tag.tag(:meta, property: "twitter:card", content: "summary_large_image")
]
end
end