Add more metadata elements
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -20,14 +20,24 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do
|
||||
|
||||
[
|
||||
Tag.tag(:meta, property: "og:title", content: Actor.display_name_and_username(group)),
|
||||
Tag.tag(:meta, property: "og:url", content: group.url),
|
||||
Tag.tag(:meta,
|
||||
property: "og:url",
|
||||
content:
|
||||
Endpoint
|
||||
|> Routes.page_url(
|
||||
:actor,
|
||||
Actor.preferred_username_and_domain(group)
|
||||
)
|
||||
|> URI.decode()
|
||||
),
|
||||
Tag.tag(:meta, property: "og:description", content: group.summary),
|
||||
Tag.tag(:meta, property: "og:type", content: "profile"),
|
||||
Tag.tag(:meta,
|
||||
property: "profile:username",
|
||||
content: Actor.preferred_username_and_domain(group)
|
||||
),
|
||||
Tag.tag(:meta, property: "twitter:card", content: "summary")
|
||||
Tag.tag(:meta, property: "twitter:card", content: "summary"),
|
||||
Tag.tag(:meta, property: "twitter:site", content: "@joinmobilizon")
|
||||
]
|
||||
|> maybe_add_avatar(group)
|
||||
|> add_group_schema(group)
|
||||
@@ -50,8 +60,22 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do
|
||||
|
||||
@spec add_group_schema(list(Tag.t()), Actor.t()) :: list(Tag.t())
|
||||
defp add_group_schema(tags, %Actor{} = group) do
|
||||
breadcrumbs = %{
|
||||
"@context" => "https://schema.org",
|
||||
"@type" => "BreadcrumbList",
|
||||
"itemListElement" => [
|
||||
%{
|
||||
"@type" => "ListItem",
|
||||
"position" => 1,
|
||||
"name" => Actor.display_name(group)
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
tags ++
|
||||
[
|
||||
~s{<script type="application/ld+json">#{Jason.encode!(breadcrumbs)}</script>}
|
||||
|> HTML.raw(),
|
||||
~s{<script type="application/ld+json">#{json(group)}</script>} |> HTML.raw()
|
||||
]
|
||||
end
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
|
||||
alias Phoenix.HTML
|
||||
alias Phoenix.HTML.Tag
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Events.{Event, EventOptions}
|
||||
alias Mobilizon.Web.Endpoint
|
||||
alias Mobilizon.Web.JsonLD.ObjectView
|
||||
alias Mobilizon.Web.Router.Helpers, as: Routes
|
||||
|
||||
import Mobilizon.Service.Metadata.Utils,
|
||||
only: [process_description: 2, strip_tags: 1, datetime_to_string: 2, render_address: 1]
|
||||
@@ -35,9 +38,64 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
|
||||
]
|
||||
end
|
||||
|
||||
breadcrumbs =
|
||||
if event.attributed_to do
|
||||
[
|
||||
%{
|
||||
"@context" => "https://schema.org",
|
||||
"@type" => "BreadcrumbList",
|
||||
"itemListElement" => [
|
||||
%{
|
||||
"@type" => "ListItem",
|
||||
"position" => 1,
|
||||
"name" => Actor.display_name(event.attributed_to),
|
||||
"item" =>
|
||||
Endpoint
|
||||
|> Routes.page_url(
|
||||
:actor,
|
||||
Actor.preferred_username_and_domain(event.attributed_to)
|
||||
)
|
||||
|> URI.decode()
|
||||
},
|
||||
%{
|
||||
"@type" => "ListItem",
|
||||
"position" => 2,
|
||||
"name" => event.title
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
||||
breadcrumbs =
|
||||
breadcrumbs ++
|
||||
[
|
||||
%{
|
||||
"@context" => "https://schema.org",
|
||||
"@type" => "BreadcrumbList",
|
||||
"itemListElement" => [
|
||||
%{
|
||||
"@type" => "ListItem",
|
||||
"position" => 1,
|
||||
"name" => "Events",
|
||||
"item" => "#{Endpoint.url()}/search"
|
||||
},
|
||||
%{
|
||||
"@type" => "ListItem",
|
||||
"position" => 2,
|
||||
"name" => event.title
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
tags ++
|
||||
[
|
||||
Tag.tag(:meta, property: "twitter:card", content: "summary_large_image"),
|
||||
~s{<script type="application/ld+json">#{Jason.encode!(breadcrumbs)}</script>}
|
||||
|> HTML.raw(),
|
||||
~s{<script type="application/ld+json">#{json(event)}</script>} |> HTML.raw()
|
||||
]
|
||||
end
|
||||
|
||||
@@ -20,18 +20,20 @@ defmodule Mobilizon.Service.Metadata.Instance do
|
||||
description = Utils.process_description(Config.instance_description())
|
||||
title = "#{Config.instance_name()} - Mobilizon"
|
||||
|
||||
instance_json_ld = """
|
||||
<script type="application/ld+json">{
|
||||
"@context": "http://schema.org",
|
||||
"@type": "WebSite",
|
||||
"name": "#{title}",
|
||||
"url": "#{Endpoint.url()}",
|
||||
"potentialAction": {
|
||||
"@type": "SearchAction",
|
||||
"target": "#{Endpoint.url()}/search?term={search_term}",
|
||||
"query-input": "required name=search_term"
|
||||
json_ld = %{
|
||||
"@context" => "http://schema.org",
|
||||
"@type" => "WebSite",
|
||||
"name" => "#{title}",
|
||||
"url" => "#{Endpoint.url()}",
|
||||
"potentialAction" => %{
|
||||
"@type" => "SearchAction",
|
||||
"target" => "#{Endpoint.url()}/search?term={search_term}",
|
||||
"query-input" => "required name=search_term"
|
||||
}
|
||||
}
|
||||
}</script>
|
||||
|
||||
instance_json_ld = """
|
||||
<script type="application/ld+json">#{Jason.encode!(json_ld)}</script>
|
||||
"""
|
||||
|
||||
[
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
defimpl Mobilizon.Service.Metadata, for: Mobilizon.Posts.Post do
|
||||
alias Phoenix.HTML
|
||||
alias Phoenix.HTML.Tag
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Medias.{File, Media}
|
||||
alias Mobilizon.Posts.Post
|
||||
alias Mobilizon.Web.Endpoint
|
||||
alias Mobilizon.Web.JsonLD.ObjectView
|
||||
alias Mobilizon.Web.Router.Helpers, as: Routes
|
||||
import Mobilizon.Service.Metadata.Utils, only: [process_description: 2, strip_tags: 1]
|
||||
|
||||
def build_tags(%Post{} = post, locale \\ "en") do
|
||||
@@ -21,9 +24,35 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Posts.Post do
|
||||
]
|
||||
|> maybe_add_post_picture(post)
|
||||
|
||||
breadcrumbs = %{
|
||||
"@context" => "https://schema.org",
|
||||
"@type" => "BreadcrumbList",
|
||||
"itemListElement" => [
|
||||
%{
|
||||
"@type" => "ListItem",
|
||||
"position" => 1,
|
||||
"name" => Actor.display_name(post.attributed_to),
|
||||
"item" =>
|
||||
Endpoint
|
||||
|> Routes.page_url(
|
||||
:actor,
|
||||
Actor.preferred_username_and_domain(post.attributed_to)
|
||||
)
|
||||
|> URI.decode()
|
||||
},
|
||||
%{
|
||||
"@type" => "ListItem",
|
||||
"position" => 2,
|
||||
"name" => post.title
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
tags ++
|
||||
[
|
||||
Tag.tag(:meta, property: "twitter:card", content: "summary_large_image"),
|
||||
~s{<script type="application/ld+json">#{Jason.encode!(breadcrumbs)}</script>}
|
||||
|> HTML.raw(),
|
||||
~s{<script type="application/ld+json">#{json(post)}</script>} |> HTML.raw()
|
||||
]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user