From: Mark Felder Date: Wed, 12 Jun 2019 22:56:51 +0000 (-0500) Subject: Attempt to use from HTML as a fallback X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=097fdf6a5d1ecd373c911bda4a1d7ee3c873fa21;p=akkoma Attempt to use <title> from HTML as a fallback --- diff --git a/lib/pleroma/web/rich_media/parsers/meta_tags_parser.ex b/lib/pleroma/web/rich_media/parsers/meta_tags_parser.ex index 4a7c5eae0..7da4e7561 100644 --- a/lib/pleroma/web/rich_media/parsers/meta_tags_parser.ex +++ b/lib/pleroma/web/rich_media/parsers/meta_tags_parser.ex @@ -1,12 +1,14 @@ defmodule Pleroma.Web.RichMedia.Parsers.MetaTagsParser do def parse(html, data, prefix, error_message, key_name, value_name \\ "content") do with elements = [_ | _] <- get_elements(html, key_name, prefix), + page_title = get_page_title(html), meta_data = Enum.reduce(elements, data, fn el, acc -> attributes = normalize_attributes(el, prefix, key_name, value_name) Map.merge(acc, attributes) - end) do + end) + |> Map.put_new(:title, page_title) do {:ok, meta_data} else _e -> {:error, error_message} @@ -27,4 +29,8 @@ defmodule Pleroma.Web.RichMedia.Parsers.MetaTagsParser do %{String.to_atom(data[key_name]) => data[value_name]} end + + defp get_page_title(html) do + Floki.find(html, "title") |> Floki.text() + end end