Skip to content
GitLab
Menu
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
939b3bfe
Commit
939b3bfe
authored
Jun 08, 2021
by
feld
Browse files
Merge branch 'improve-og-embed' into 'develop'
Improve opengraph embeds See merge request
!3442
parents
5667c02f
26445853
Pipeline
#36480
passed with stages
in 85 minutes and 16 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/metadata/providers/open_graph.ex
View file @
939b3bfe
...
...
@@ -19,31 +19,18 @@ def build_tags(%{
})
do
attachments
=
build_attachments
(
object
)
scrubbed_content
=
Utils
.
scrub_html_and_truncate
(
object
)
# Zero width space
content
=
if
scrubbed_content
!=
""
and
scrubbed_content
!=
"
\u200
B"
do
": “"
<>
scrubbed_content
<>
"”"
else
""
end
# Most previews only show og:title which is inconvenient. Instagram
# hacks this by putting the description in the title and making the
# description longer prefixed by how many likes and shares the post
# has. Here we use the descriptive nickname in the title, and expand
# the full account & nickname in the description. We also use the cute^Wevil
# smart quotes around the status text like Instagram, too.
[
{
:meta
,
[
property:
"og:title"
,
content:
"
#{
user
.
name
}
"
<>
content
content:
Utils
.
user
_
name
_string
(
user
)
],
[]},
{
:meta
,
[
property:
"og:url"
,
content:
url
],
[]},
{
:meta
,
[
property:
"og:description"
,
content:
"
#{
Utils
.
user_name_string
(
user
)
}
"
<>
content
content:
scrubbed_
content
],
[]},
{
:meta
,
[
property:
"og:type"
,
content:
"website"
],
[]}
]
++
...
...
@@ -95,8 +82,7 @@ defp build_attachments(%{data: %{"attachment" => attachments}}) do
"image"
->
[
{
:meta
,
[
property:
"og:image"
,
content:
Utils
.
attachment_url
(
url
[
"href"
])],
[]},
{
:meta
,
[
property:
"og:image:width"
,
content:
150
],
[]},
{
:meta
,
[
property:
"og:image:height"
,
content:
150
],
[]}
{
:meta
,
[
property:
"og:image:alt"
,
content:
attachment
[
"name"
]],
[]}
|
acc
]
...
...
lib/pleroma/web/metadata/providers/twitter_card.ex
View file @
939b3bfe
...
...
@@ -16,17 +16,10 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
def
build_tags
(%{
activity_id:
id
,
object:
object
,
user:
user
})
do
attachments
=
build_attachments
(
id
,
object
)
scrubbed_content
=
Utils
.
scrub_html_and_truncate
(
object
)
# Zero width space
content
=
if
scrubbed_content
!=
""
and
scrubbed_content
!=
"
\u200
B"
do
"“"
<>
scrubbed_content
<>
"”"
else
""
end
[
title_tag
(
user
),
{
:meta
,
[
property:
"twitter:description"
,
content:
content
],
[]}
{
:meta
,
[
property:
"twitter:description"
,
content:
scrubbed_
content
],
[]}
]
++
if
attachments
==
[]
or
Metadata
.
activity_nsfw?
(
object
)
do
[
...
...
@@ -91,7 +84,10 @@ defp build_attachments(id, %{data: %{"attachment" => attachments}}) do
{
:meta
,
[
property:
"twitter:card"
,
content:
"player"
],
[]},
{
:meta
,
[
property:
"twitter:player"
,
content:
player_url
(
id
)],
[]},
{
:meta
,
[
property:
"twitter:player:width"
,
content:
"480"
],
[]},
{
:meta
,
[
property:
"twitter:player:height"
,
content:
"480"
],
[]}
{
:meta
,
[
property:
"twitter:player:height"
,
content:
"480"
],
[]},
{
:meta
,
[
property:
"twitter:player:stream"
,
content:
url
[
"href"
]],
[]},
{
:meta
,
[
property:
"twitter:player:stream:content_type"
,
content:
url
[
"mediaType"
]],
[]}
|
acc
]
...
...
test/pleroma/web/metadata/providers/twitter_card_test.exs
View file @
939b3bfe
...
...
@@ -46,7 +46,7 @@ test "it uses summary twittercard if post has no attachment" do
assert
[
{
:meta
,
[
property:
"twitter:title"
,
content:
Utils
.
user_name_string
(
user
)],
[]},
{
:meta
,
[
property:
"twitter:description"
,
content:
"
“
pleroma in a nutshell
”
"
],
[]},
{
:meta
,
[
property:
"twitter:description"
,
content:
"pleroma in a nutshell"
],
[]},
{
:meta
,
[
property:
"twitter:image"
,
content:
"http://localhost:4001/images/avi.png"
],
[]},
{
:meta
,
[
property:
"twitter:card"
,
content:
"summary"
],
[]}
...
...
@@ -91,7 +91,7 @@ test "it renders avatar not attachment if post is nsfw and unfurl_nsfw is disabl
assert
[
{
:meta
,
[
property:
"twitter:title"
,
content:
Utils
.
user_name_string
(
user
)],
[]},
{
:meta
,
[
property:
"twitter:description"
,
content:
"
“
pleroma in a nutshell
”
"
],
[]},
{
:meta
,
[
property:
"twitter:description"
,
content:
"pleroma in a nutshell"
],
[]},
{
:meta
,
[
property:
"twitter:image"
,
content:
"http://localhost:4001/images/avi.png"
],
[]},
{
:meta
,
[
property:
"twitter:card"
,
content:
"summary"
],
[]}
...
...
@@ -134,7 +134,7 @@ test "it renders supported types of attachments and skips unknown types" do
assert
[
{
:meta
,
[
property:
"twitter:title"
,
content:
Utils
.
user_name_string
(
user
)],
[]},
{
:meta
,
[
property:
"twitter:description"
,
content:
"
“
pleroma in a nutshell
”
"
],
[]},
{
:meta
,
[
property:
"twitter:description"
,
content:
"pleroma in a nutshell"
],
[]},
{
:meta
,
[
property:
"twitter:card"
,
content:
"summary_large_image"
],
[]},
{
:meta
,
[
property:
"twitter:player"
,
content:
"https://pleroma.gov/tenshi.png"
],
[]},
{
:meta
,
[
property:
"twitter:card"
,
content:
"player"
],
[]},
...
...
@@ -144,7 +144,13 @@ test "it renders supported types of attachments and skips unknown types" do
content:
Router
.
Helpers
.
o_status_url
(
Endpoint
,
:notice_player
,
activity
.
id
)
],
[]},
{
:meta
,
[
property:
"twitter:player:width"
,
content:
"480"
],
[]},
{
:meta
,
[
property:
"twitter:player:height"
,
content:
"480"
],
[]}
{
:meta
,
[
property:
"twitter:player:height"
,
content:
"480"
],
[]},
{
:meta
,
[
property:
"twitter:player:stream"
,
content:
"https://pleroma.gov/about/juche.webm"
],
[]},
{
:meta
,
[
property:
"twitter:player:stream:content_type"
,
content:
"video/webm"
],
[]}
]
==
result
end
end
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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