fix: append field values to bio before parsing
This commit is contained in:
parent
d6271e7613
commit
8fb235e71b
2 changed files with 7 additions and 11 deletions
|
@ -9,8 +9,9 @@ defmodule Pleroma.Web.Metadata.Providers.RelMe do
|
||||||
@impl Provider
|
@impl Provider
|
||||||
def build_tags(%{user: user}) do
|
def build_tags(%{user: user}) do
|
||||||
profile_tree =
|
profile_tree =
|
||||||
Floki.parse_fragment!(user.bio)
|
user.bio
|
||||||
|> prepend_fields_tag(user.fields)
|
|> append_fields_tag(user.fields)
|
||||||
|
|> Floki.parse_fragment!()
|
||||||
|
|
||||||
(Floki.attribute(profile_tree, "link[rel~=me]", "href") ++
|
(Floki.attribute(profile_tree, "link[rel~=me]", "href") ++
|
||||||
Floki.attribute(profile_tree, "a[rel~=me]", "href"))
|
Floki.attribute(profile_tree, "a[rel~=me]", "href"))
|
||||||
|
@ -19,13 +20,8 @@ defmodule Pleroma.Web.Metadata.Providers.RelMe do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp prepend_fields_tag(bio_tree, fields) do
|
defp append_fields_tag(bio, fields) do
|
||||||
fields
|
fields
|
||||||
|> Enum.reduce(bio_tree, fn %{"value" => v}, tree ->
|
|> Enum.reduce(bio, fn %{"value" => v}, res -> res <> v end)
|
||||||
case Floki.parse_fragment(v) do
|
|
||||||
{:ok, [a | _]} -> [a | tree]
|
|
||||||
_ -> tree
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,8 +27,8 @@ defmodule Pleroma.Web.Metadata.Providers.RelMeTest do
|
||||||
|
|
||||||
assert RelMe.build_tags(%{user: user}) == [
|
assert RelMe.build_tags(%{user: user}) == [
|
||||||
{:link, [rel: "me", href: "http://some3.com"], []},
|
{:link, [rel: "me", href: "http://some3.com"], []},
|
||||||
{:link, [rel: "me", href: "http://profile.com"], []},
|
{:link, [rel: "me", href: "https://another-link.com"], []},
|
||||||
{:link, [rel: "me", href: "https://another-link.com"], []}
|
{:link, [rel: "me", href: "http://profile.com"], []}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue