Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
907B

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.Preload do
  5. alias Phoenix.HTML
  6. require Logger
  7. def build_tags(_conn, params) do
  8. preload_data =
  9. Enum.reduce(Pleroma.Config.get([__MODULE__, :providers], []), %{}, fn parser, acc ->
  10. terms =
  11. params
  12. |> parser.generate_terms()
  13. |> Enum.map(fn {k, v} -> {k, Base.encode64(Jason.encode!(v))} end)
  14. |> Enum.into(%{})
  15. Map.merge(acc, terms)
  16. end)
  17. rendered_html =
  18. preload_data
  19. |> Jason.encode!()
  20. |> build_script_tag()
  21. |> HTML.safe_to_string()
  22. rendered_html
  23. end
  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