logo

pleroma

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

twitter_card.ex (794B)


  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.RichMedia.Parsers.TwitterCard do
  5. alias Pleroma.Web.RichMedia.Parsers.MetaTagsParser
  6. @spec parse(list(), map()) :: map()
  7. def parse(html, data) do
  8. data
  9. |> MetaTagsParser.parse(html, "og", "property")
  10. |> MetaTagsParser.parse(html, "twitter", "name")
  11. |> MetaTagsParser.parse(html, "twitter", "property")
  12. |> filter_tags()
  13. end
  14. defp filter_tags(tags) do
  15. Map.filter(tags, fn {k, _v} ->
  16. cond do
  17. k in ["card", "description", "image", "title", "ttl", "type", "url"] -> true
  18. String.starts_with?(k, "image:") -> true
  19. true -> false
  20. end
  21. end)
  22. end
  23. end