logo

pleroma

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

metadata.ex (1377B)


  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.Metadata do
  5. alias Phoenix.HTML
  6. def build_tags(params) do
  7. providers = [
  8. Pleroma.Web.Metadata.Providers.RelMe,
  9. Pleroma.Web.Metadata.Providers.RestrictIndexing
  10. | activated_providers()
  11. ]
  12. Enum.reduce(providers, "", fn parser, acc ->
  13. rendered_html =
  14. params
  15. |> parser.build_tags()
  16. |> Enum.map(&to_tag/1)
  17. |> Enum.map(&HTML.safe_to_string/1)
  18. |> Enum.join()
  19. acc <> rendered_html
  20. end)
  21. end
  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. raise ArgumentError, message: "make_tag invalid args"
  30. end
  31. end
  32. def activity_nsfw?(%{data: %{"sensitive" => sensitive}}) do
  33. Pleroma.Config.get([__MODULE__, :unfurl_nsfw], false) == false and sensitive
  34. end
  35. def activity_nsfw?(_) do
  36. false
  37. end
  38. defp activated_providers do
  39. unless Pleroma.Config.restrict_unauthenticated_access?(:activities, :local) do
  40. [Pleroma.Web.Metadata.Providers.Feed | Pleroma.Config.get([__MODULE__, :providers], [])]
  41. else
  42. []
  43. end
  44. end
  45. end