Merge branch 'ops/fix-ci' 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 Enum.reduce(Pleroma.Config.get([__MODULE__, :providers], []), "", fn parser, acc ->
10 rendered_html =
11 params
12 |> parser.build_tags()
13 |> Enum.map(&to_tag/1)
14 |> Enum.map(&HTML.safe_to_string/1)
15 |> Enum.join()
16
17 acc <> rendered_html
18 end)
19 end
20
21 def to_tag(data) do
22 with {name, attrs, _content = []} <- data do
23 HTML.Tag.tag(name, attrs)
24 else
25 {name, attrs, content} ->
26 HTML.Tag.content_tag(name, content, attrs)
27
28 _ ->
29 raise ArgumentError, message: "make_tag invalid args"
30 end
31 end
32
33 def activity_nsfw?(%{data: %{"sensitive" => sensitive}}) do
34 Pleroma.Config.get([__MODULE__, :unfurl_nsfw], false) == false and sensitive
35 end
36
37 def activity_nsfw?(_) do
38 false
39 end
40 end