join us now and share the software~. Also tests
[akkoma] / lib / pleroma / web / metadata.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4 defmodule Pleroma.Web.Metadata do
5 alias Phoenix.HTML
6
7 @providers Pleroma.Config.get([__MODULE__, :providers], [])
8
9 def build_tags(params) do
10 Enum.reduce(@providers, "", fn parser, acc ->
11 rendered_html =
12 params
13 |> parser.build_tags()
14 |> Enum.map(&to_tag/1)
15 |> Enum.map(&HTML.safe_to_string/1)
16 |> Enum.join()
17
18 acc <> rendered_html
19 end)
20 end
21
22 def to_tag(data) do
23 with {name, attrs, _content = []} <- data do
24 HTML.Tag.tag(name, attrs)
25 else
26 {name, attrs, content} ->
27 HTML.Tag.content_tag(name, content, attrs)
28
29 _ ->
30 raise ArgumentError, message: "make_tag invalid args"
31 end
32 end
33 end