logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

preload.ex (928B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.Preload do
  5. alias Phoenix.HTML
  6. def build_tags(_conn, params) do
  7. preload_data =
  8. Enum.reduce(Pleroma.Config.get([__MODULE__, :providers], []), %{}, fn parser, acc ->
  9. terms =
  10. params
  11. |> parser.generate_terms()
  12. |> Enum.map(fn {k, v} -> {k, Base.encode64(Jason.encode!(v, escape: :html_safe))} end)
  13. |> Enum.into(%{})
  14. Map.merge(acc, terms)
  15. end)
  16. rendered_html =
  17. preload_data
  18. |> Jason.encode!(escape: :html_safe)
  19. |> build_script_tag()
  20. |> HTML.safe_to_string()
  21. rendered_html
  22. end
  23. def build_script_tag(content) do
  24. HTML.Tag.content_tag(:script, HTML.raw(content),
  25. id: "initial-results",
  26. type: "application/json"
  27. )
  28. end
  29. end