preload data into index.html
[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 Map.merge(acc, parser.generate_terms(params))
13 end)
14
15 rendered_html =
16 preload_data
17 |> Jason.encode!()
18 |> build_script_tag()
19 |> HTML.safe_to_string()
20
21 rendered_html
22 end
23
24 def build_script_tag(content) do
25 HTML.Tag.content_tag(:script, HTML.raw(content),
26 id: "initial-results",
27 type: "application/json"
28 )
29 end
30 end