Merge branch 'fix/1601-add-new-meta-tag' into 'develop'
[akkoma] / lib / pleroma / web / metadata.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Metadata do
6 alias Phoenix.HTML
7
8 def build_tags(params) do
9 providers = [
10 Pleroma.Web.Metadata.Providers.RestrictIndexing
11 | Pleroma.Config.get([__MODULE__, :providers], [])
12 ]
13
14 Enum.reduce(providers, "", fn parser, acc ->
15 rendered_html =
16 params
17 |> parser.build_tags()
18 |> Enum.map(&to_tag/1)
19 |> Enum.map(&HTML.safe_to_string/1)
20 |> Enum.join()
21
22 acc <> rendered_html
23 end)
24 end
25
26 def to_tag(data) do
27 with {name, attrs, _content = []} <- data do
28 HTML.Tag.tag(name, attrs)
29 else
30 {name, attrs, content} ->
31 HTML.Tag.content_tag(name, content, attrs)
32
33 _ ->
34 raise ArgumentError, message: "make_tag invalid args"
35 end
36 end
37
38 def activity_nsfw?(%{data: %{"sensitive" => sensitive}}) do
39 Pleroma.Config.get([__MODULE__, :unfurl_nsfw], false) == false and sensitive
40 end
41
42 def activity_nsfw?(_) do
43 false
44 end
45 end