@@ -7,6 +7,7 @@ defmodule MobilizonWeb.PageView do
|
||||
alias Mobilizon.Service.ActivityPub.{Converter, Utils}
|
||||
alias Mobilizon.Service.Metadata
|
||||
alias Mobilizon.Service.MetadataUtils
|
||||
alias Mobilizon.Service.Metadata.Instance
|
||||
|
||||
def render("actor.activity-json", %{conn: %{assigns: %{object: actor}}}) do
|
||||
public_key = Utils.pem_to_public_key_pem(actor.keys)
|
||||
@@ -80,6 +81,8 @@ defmodule MobilizonWeb.PageView do
|
||||
|
||||
def render("index.html", _assigns) do
|
||||
with {:ok, index_content} <- File.read(index_file_path()) do
|
||||
tags = Instance.build_tags() |> MetadataUtils.stringify_tags()
|
||||
index_content = String.replace(index_content, "<!--server-generated-meta-->", tags)
|
||||
{:safe, index_content}
|
||||
end
|
||||
end
|
||||
|
||||
46
lib/service/metadata/instance.ex
Normal file
46
lib/service/metadata/instance.ex
Normal file
@@ -0,0 +1,46 @@
|
||||
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
|
||||
alias Mobilizon.Config
|
||||
alias MobilizonWeb.Endpoint
|
||||
|
||||
def build_tags() do
|
||||
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",
|
||||
"target": "#{Endpoint.url()}/search/{search_term}",
|
||||
"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
|
||||
|> HtmlSanitizeEx.strip_tags()
|
||||
|> String.slice(0..200)
|
||||
|> (&"#{&1}…").()
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user