aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorio <eiy7rongai0g@paperboats.net>2021-06-04 04:15:54 +0000
committerio <eiy7rongai0g@paperboats.net>2021-06-04 05:33:35 +0000
commit2c401dafa1105b73f4b4141f96e8414612625420 (patch)
tree0f620620671f97f27c79455c82dccafd1d0364cf /lib
parenta5dce42c85de2d8316541348335d1dd49c2c3d89 (diff)
downloadpleroma-2c401dafa1105b73f4b4141f96e8414612625420.tar.gz
Improve opengraph embeds
This brings them more in line with Mastodon. - Deduplicates display name from the title and content - Removes arbitrary limits on the size of the embedded image - Removes angled double quotes from embed descriptions. These would normally just indicate that the content is a quote, but that is already implied by the content being in an embed.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/metadata/providers/open_graph.ex20
-rw-r--r--lib/pleroma/web/metadata/providers/twitter_card.ex13
2 files changed, 7 insertions, 26 deletions
diff --git a/lib/pleroma/web/metadata/providers/open_graph.ex b/lib/pleroma/web/metadata/providers/open_graph.ex
index 1687b2634..18ddde84b 100644
--- a/lib/pleroma/web/metadata/providers/open_graph.ex
+++ b/lib/pleroma/web/metadata/providers/open_graph.ex
@@ -19,31 +19,18 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do
}) do
attachments = build_attachments(object)
scrubbed_content = Utils.scrub_html_and_truncate(object)
- # Zero width space
- content =
- if scrubbed_content != "" and scrubbed_content != "\u200B" 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 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph 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
]
diff --git a/lib/pleroma/web/metadata/providers/twitter_card.ex b/lib/pleroma/web/metadata/providers/twitter_card.ex
index 58fc05cf9..589989a9d 100644
--- a/lib/pleroma/web/metadata/providers/twitter_card.ex
+++ b/lib/pleroma/web/metadata/providers/twitter_card.ex
@@ -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 != "\u200B" 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,9 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard 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
]