Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into chat-federation...
[akkoma] / lib / pleroma / web / preload.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.Preload do
6 alias Phoenix.HTML
7 require Logger
8
9 def build_tags(_conn, params) do
10 preload_data =
11 Enum.reduce(Pleroma.Config.get([__MODULE__, :providers], []), %{}, fn parser, acc ->
12 terms =
13 params
14 |> parser.generate_terms()
15 |> Enum.map(fn {k, v} -> {k, Base.encode64(Jason.encode!(v))} end)
16 |> Enum.into(%{})
17
18 Map.merge(acc, terms)
19 end)
20
21 rendered_html =
22 preload_data
23 |> Jason.encode!()
24 |> build_script_tag()
25 |> HTML.safe_to_string()
26
27 rendered_html
28 end
29
30 def build_script_tag(content) do
31 HTML.Tag.content_tag(:script, HTML.raw(content),
32 id: "initial-results",
33 type: "application/json"
34 )
35 end
36 end