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-11-17 15:45:08 +01:00
|
|
|
alias Mobilizon.Service.Metadata.Utils
|
2020-01-26 21:36:50 +01:00
|
|
|
alias Mobilizon.Web.Endpoint
|
2021-04-19 12:41:19 +02:00
|
|
|
alias Mobilizon.Web.Router.Helpers, as: Routes
|
|
|
|
import Mobilizon.Web.Gettext
|
2019-10-10 16:47:38 +02:00
|
|
|
|
2020-11-17 15:45:08 +01:00
|
|
|
@doc """
|
|
|
|
Build the list of tags for the instance
|
|
|
|
"""
|
|
|
|
@spec build_tags() :: list(Phoenix.HTML.safe())
|
2020-01-28 20:15:59 +01:00
|
|
|
def build_tags do
|
2020-11-17 15:45:08 +01:00
|
|
|
description = Utils.process_description(Config.instance_description())
|
2019-10-10 16:47:38 +02:00
|
|
|
title = "#{Config.instance_name()} - Mobilizon"
|
|
|
|
|
2021-10-21 17:55:16 +02:00
|
|
|
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"
|
|
|
|
}
|
2019-10-10 16:47:38 +02:00
|
|
|
}
|
2021-10-21 17:55:16 +02:00
|
|
|
|
|
|
|
instance_json_ld = """
|
|
|
|
<script type="application/ld+json">#{Jason.encode!(json_ld)}</script>
|
2019-10-10 16:47:38 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
[
|
|
|
|
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)
|
2022-07-12 10:55:28 +02:00
|
|
|
] ++ maybe_add_instance_feeds(enable_instance_feeds())
|
|
|
|
end
|
|
|
|
|
|
|
|
defp enable_instance_feeds do
|
|
|
|
get_in(Application.get_env(:mobilizon, :instance), [:enable_instance_feeds])
|
2021-04-19 12:41:19 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
@spec maybe_add_instance_feeds(boolean()) :: list()
|
|
|
|
defp maybe_add_instance_feeds(true) do
|
|
|
|
[
|
|
|
|
Tag.tag(:link,
|
|
|
|
rel: "alternate",
|
|
|
|
type: "application/atom+xml",
|
|
|
|
title: gettext("%{name}'s feed", name: Config.instance_name()) |> HTML.raw(),
|
|
|
|
href: Routes.feed_url(Endpoint, :instance, :atom)
|
|
|
|
),
|
|
|
|
Tag.tag(:link,
|
|
|
|
rel: "alternate",
|
|
|
|
type: "text/calendar",
|
|
|
|
title: gettext("%{name}'s feed", name: Config.instance_name()) |> HTML.raw(),
|
|
|
|
href: Routes.feed_url(Endpoint, :instance, :ics)
|
|
|
|
)
|
2019-10-10 16:47:38 +02:00
|
|
|
]
|
|
|
|
end
|
2021-04-19 12:41:19 +02:00
|
|
|
|
|
|
|
defp maybe_add_instance_feeds(false), do: []
|
2019-10-10 16:47:38 +02:00
|
|
|
end
|