-defmodule Pleroma.Web.RichMedia.Parsers.OGP do
- def parse(html, data) do
- with elements = [_ | _] <- get_elements(html),
- ogp_data =
- Enum.reduce(elements, data, fn el, acc ->
- attributes = normalize_attributes(el)
-
- Map.merge(acc, attributes)
- end) do
- {:ok, ogp_data}
- else
- _e -> {:error, "No OGP metadata found"}
- end
- end
-
- defp get_elements(html) do
- html |> Floki.find("meta[property^='og:']")
- end
-
- defp normalize_attributes(html_node) do
- {_tag, attributes, _children} = html_node
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only