X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Frich_media%2Fparsers%2Fogp.ex;h=3e90125882e2f2d58799584bd6be4b726f4b311b;hb=2019f3b3ff365b61c14f01c736a6dcb68cb36624;hp=5773a52632f476ec328996c525102d16ed03189a;hpb=bf5aaefbb56a8ff8ac4e43874dacd794f3deda84;p=akkoma diff --git a/lib/pleroma/web/rich_media/parsers/ogp.ex b/lib/pleroma/web/rich_media/parsers/ogp.ex index 5773a5263..3e9012588 100644 --- a/lib/pleroma/web/rich_media/parsers/ogp.ex +++ b/lib/pleroma/web/rich_media/parsers/ogp.ex @@ -1,30 +1,15 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + 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 - - data = - Enum.into(attributes, %{}, fn {name, value} -> - {name, String.trim_leading(value, "og:")} - end) - - %{String.to_atom(data["property"]) => data["content"]} + Pleroma.Web.RichMedia.Parsers.MetaTagsParser.parse( + html, + data, + "og", + "No OGP metadata found", + "property" + ) end end