1 defmodule Pleroma.Web.Metadata do
3 alias Pleroma.{Formatter, User}
4 alias Pleroma.Web.MediaProxy
6 def build_tags(params) do
7 if(meta_enabled?(:opengraph), do: opengraph_tags(params), else: [])
9 |> Enum.map(&HTML.safe_to_string/1)
13 def meta_enabled?(type) do
14 config = Pleroma.Config.get(:metadata, [])
15 Keyword.get(config, type, false)
18 # opengraph for single status
19 defp opengraph_tags(%{activity: activity, user: user}) do
20 with truncated_content = Formatter.truncate(activity.data["object"]["content"]) do
25 content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) post ##{activity.id}"
27 {:meta, [property: "og:url", content: activity.data["id"]], []},
28 {:meta, [property: "og:description", content: truncated_content], []},
29 {:meta, [property: "og:image", content: user_avatar_url(user)], []},
30 {:meta, [property: "og:image:width", content: 120], []},
31 {:meta, [property: "og:image:height", content: 120], []},
32 {:meta, [property: "twitter:card", content: "summary"], []}
37 # opengraph for user card
38 defp opengraph_tags(%{user: user}) do
39 with truncated_bio = Formatter.truncate(user.bio) do
44 content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) profile"
46 {:meta, [property: "og:url", content: User.profile_url(user)], []},
47 {:meta, [property: "og:description", content: truncated_bio], []},
48 {:meta, [property: "og:image", content: user_avatar_url(user)], []},
49 {:meta, [property: "og:image:width", content: 120], []},
50 {:meta, [property: "og:image:height", content: 120], []},
51 {:meta, [property: "twitter:card", content: "summary"], []}
57 with {name, attrs, _content = []} <- data do
58 HTML.Tag.tag(name, attrs)
60 {name, attrs, content} ->
61 HTML.Tag.content_tag(name, content, attrs)
64 raise ArgumentError, message: "make_tag invalid args"
68 defp user_avatar_url(user) do
69 User.avatar_url(user) |> MediaProxy.url()
73 Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN")