cache HTML in OGP
This commit is contained in:
parent
9aa69e12b8
commit
565caff3f4
1 changed files with 10 additions and 2 deletions
|
@ -7,7 +7,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do
|
||||||
|
|
||||||
@impl Provider
|
@impl Provider
|
||||||
def build_tags(%{activity: activity, user: user}) do
|
def build_tags(%{activity: activity, user: user}) do
|
||||||
with truncated_content = scrub_html_and_truncate(activity.data["object"]["content"]) do
|
with truncated_content = scrub_html_and_truncate(activity) do
|
||||||
attachments = build_attachments(activity)
|
attachments = build_attachments(activity)
|
||||||
|
|
||||||
[
|
[
|
||||||
|
@ -71,6 +71,15 @@ defp build_attachments(activity) do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp scrub_html_and_truncate(%{data: %{ "object" => %{ "content" => content}}} = activity) do
|
||||||
|
content
|
||||||
|
# html content comes from DB already encoded, decode first and scrub after
|
||||||
|
|> HtmlEntities.decode()
|
||||||
|
|> String.replace(~r/<br\s?\/?>/, " ")
|
||||||
|
|> HTML.get_cached_stripped_html_for_object(activity, __MODULE__)
|
||||||
|
|> Formatter.truncate()
|
||||||
|
end
|
||||||
|
|
||||||
defp scrub_html_and_truncate(content) do
|
defp scrub_html_and_truncate(content) do
|
||||||
content
|
content
|
||||||
# html content comes from DB already encoded, decode first and scrub after
|
# html content comes from DB already encoded, decode first and scrub after
|
||||||
|
@ -79,7 +88,6 @@ defp scrub_html_and_truncate(content) do
|
||||||
|> HTML.strip_tags()
|
|> HTML.strip_tags()
|
||||||
|> Formatter.truncate()
|
|> Formatter.truncate()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp attachment_url(url) do
|
defp attachment_url(url) do
|
||||||
MediaProxy.url(url)
|
MediaProxy.url(url)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue