1 defmodule Pleroma.Web.RichMedia.Parsers.OGP do
2 def parse(html, data) do
3 with elements = [_ | _] <- get_elements(html),
5 Enum.reduce(elements, data, fn el, acc ->
6 attributes = normalize_attributes(el)
8 Map.merge(acc, attributes)
12 _e -> {:error, "No OGP metadata found"}
16 defp get_elements(html) do
17 html |> Floki.find("meta[property^='og:']")
20 defp normalize_attributes(html_node) do
21 {_tag, attributes, _children} = html_node
24 Enum.into(attributes, %{}, fn {name, value} ->
25 {name, String.trim_leading(value, "og:")}
28 %{String.to_atom(data["property"]) => data["content"]}