Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
565caff3
Commit
565caff3
authored
Jan 16, 2019
by
rinpatch
Browse files
cache HTML in OGP
parent
9aa69e12
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/metadata/opengraph.ex
View file @
565caff3
...
...
@@ -7,7 +7,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do
@impl
Provider
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
)
[
...
...
@@ -71,6 +71,15 @@ defp build_attachments(activity) do
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
content
# 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
()
|>
Formatter
.
truncate
()
end
defp
attachment_url
(
url
)
do
MediaProxy
.
url
(
url
)
end
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment