2019-10-10 16:47:38 +02:00
|
|
|
defmodule Mobilizon.Service.Metadata.Instance do
|
|
|
|
@moduledoc """
|
|
|
|
Generates metadata for every other page that isn't event/actor/comment
|
|
|
|
"""
|
|
|
|
|
|
|
|
alias Phoenix.HTML
|
|
|
|
alias Phoenix.HTML.Tag
|
2020-01-28 20:15:59 +01:00
|
|
|
|
2019-10-10 16:47:38 +02:00
|
|
|
alias Mobilizon.Config
|
2020-06-24 16:33:59 +02:00
|
|
|
alias Mobilizon.Service.Formatter.HTML, as: HTMLFormatter
|
2020-01-26 21:36:50 +01:00
|
|
|
alias Mobilizon.Web.Endpoint
|
2019-10-10 16:47:38 +02:00
|
|
|
|
2020-01-28 20:15:59 +01:00
|
|
|
def build_tags do
|
2019-10-10 16:47:38 +02:00
|
|
|
description = 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",
|
2020-08-10 18:08:25 +02:00
|
|
|
"target": "#{Endpoint.url()}/search?term={search_term}",
|
2019-10-10 16:47:38 +02:00
|
|
|
"query-input": "required name=search_term"
|
|
|
|
}
|
|
|
|
}</script>
|
|
|
|
"""
|
|
|
|
|
|
|
|
[
|
|
|
|
Tag.content_tag(:title, title),
|
|
|
|
Tag.tag(:meta, name: "description", content: description),
|
|
|
|
Tag.tag(:meta, property: "og:title", content: title),
|
|
|
|
Tag.tag(:meta, property: "og:url", content: Endpoint.url()),
|
|
|
|
Tag.tag(:meta, property: "og:description", content: description),
|
|
|
|
Tag.tag(:meta, property: "og:type", content: "website"),
|
|
|
|
HTML.raw(instance_json_ld)
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
defp process_description(description) do
|
|
|
|
description
|
2020-06-24 16:33:59 +02:00
|
|
|
|> HTMLFormatter.strip_tags()
|
2019-10-10 16:47:38 +02:00
|
|
|
|> String.slice(0..200)
|
|
|
|
|> (&"#{&1}…").()
|
|
|
|
end
|
|
|
|
end
|