From: Mark Felder Date: Wed, 12 Jun 2019 23:32:28 +0000 (-0500) Subject: Revert "Only run Floki if title is missing from the map" X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=7363a0ea8aa5c034e0335e826c081f1166e71f92;p=akkoma Revert "Only run Floki if title is missing from the map" This reverts commit 97d2b1a45ab12c530dd730518b9d8ca546bbc9f2. --- 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 8c42557aa..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,14 +1,15 @@ 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 - rich_meta_data = maybe_use_page_title(meta_data, html) - {:ok, rich_meta_data} + end) + |> Map.put_new(:title, page_title) do + {:ok, meta_data} else _e -> {:error, error_message} end @@ -29,10 +30,7 @@ defmodule Pleroma.Web.RichMedia.Parsers.MetaTagsParser do %{String.to_atom(data[key_name]) => data[value_name]} end - defp maybe_use_page_title(meta_data, html) do - if !Map.has_key?(meta_data, :title) do - page_title = Floki.find(html, "title") |> Floki.text() - Map.put_new(meta_data, :title, page_title) - end + defp get_page_title(html) do + Floki.find(html, "title") |> Floki.text() end end