diff options
author | Mark Felder <feld@feld.me> | 2025-02-28 13:17:44 -0800 |
---|---|---|
committer | Mark Felder <feld@feld.me> | 2025-02-28 13:36:00 -0800 |
commit | 7bdeb9a1e561bd061410a4174d4ee155589943c5 (patch) | |
tree | a555661e476c9da0f8799130820b2537747ddea9 /lib | |
parent | 6f48ade41736ffd5ac02eee445c35516cbbbe907 (diff) | |
download | pleroma-7bdeb9a1e561bd061410a4174d4ee155589943c5.tar.gz pleroma-7bdeb9a1e561bd061410a4174d4ee155589943c5.zip |
Fix OpenGraph/TwitterCard meta tag ordering for posts with multiple attachments
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/metadata/providers/open_graph.ex | 26 | ||||
-rw-r--r-- | lib/pleroma/web/metadata/providers/twitter_card.ex | 54 |
2 files changed, 40 insertions, 40 deletions
diff --git a/lib/pleroma/web/metadata/providers/open_graph.ex b/lib/pleroma/web/metadata/providers/open_graph.ex index fa5fbe553..604434df2 100644 --- a/lib/pleroma/web/metadata/providers/open_graph.ex +++ b/lib/pleroma/web/metadata/providers/open_graph.ex @@ -78,10 +78,10 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do # object when a Video or GIF is attached it will display that in Whatsapp Rich Preview. case Utils.fetch_media_type(@media_types, url["mediaType"]) do "audio" -> - [ - {:meta, [property: "og:audio", content: MediaProxy.url(url["href"])], []} - | acc - ] + acc ++ + [ + {:meta, [property: "og:audio", content: MediaProxy.url(url["href"])], []} + ] # Not using preview_url for this. It saves bandwidth, but the image dimensions will # be wrong. We generate it on the fly and have no way to capture or analyze the @@ -89,18 +89,18 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do # in timelines too, but you can get clever with the aspect ratio metadata as a # workaround. "image" -> - [ - {:meta, [property: "og:image", content: MediaProxy.url(url["href"])], []}, - {:meta, [property: "og:image:alt", content: attachment["name"]], []} - | acc - ] + (acc ++ + [ + {:meta, [property: "og:image", content: MediaProxy.url(url["href"])], []}, + {:meta, [property: "og:image:alt", content: attachment["name"]], []} + ]) |> maybe_add_dimensions(url) "video" -> - [ - {:meta, [property: "og:video", content: MediaProxy.url(url["href"])], []} - | acc - ] + (acc ++ + [ + {:meta, [property: "og:video", content: MediaProxy.url(url["href"])], []} + ]) |> maybe_add_dimensions(url) |> maybe_add_video_thumbnail(url) diff --git a/lib/pleroma/web/metadata/providers/twitter_card.ex b/lib/pleroma/web/metadata/providers/twitter_card.ex index 7f50877c3..212fa85ed 100644 --- a/lib/pleroma/web/metadata/providers/twitter_card.ex +++ b/lib/pleroma/web/metadata/providers/twitter_card.ex @@ -61,13 +61,13 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do Enum.reduce(attachment["url"], [], fn url, acc -> case Utils.fetch_media_type(@media_types, url["mediaType"]) do "audio" -> - [ - {:meta, [name: "twitter:card", content: "player"], []}, - {:meta, [name: "twitter:player:width", content: "480"], []}, - {:meta, [name: "twitter:player:height", content: "80"], []}, - {:meta, [name: "twitter:player", content: player_url(id)], []} - | acc - ] + acc ++ + [ + {:meta, [name: "twitter:card", content: "player"], []}, + {:meta, [name: "twitter:player:width", content: "480"], []}, + {:meta, [name: "twitter:player:height", content: "80"], []}, + {:meta, [name: "twitter:player", content: player_url(id)], []} + ] # Not using preview_url for this. It saves bandwidth, but the image dimensions will # be wrong. We generate it on the fly and have no way to capture or analyze the @@ -75,16 +75,16 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do # in timelines too, but you can get clever with the aspect ratio metadata as a # workaround. "image" -> - [ - {:meta, [name: "twitter:card", content: "summary_large_image"], []}, - {:meta, + (acc ++ [ - name: "twitter:image", - content: MediaProxy.url(url["href"]) - ], []}, - {:meta, [name: "twitter:image:alt", content: truncate(attachment["name"])], []} - | acc - ] + {:meta, [name: "twitter:card", content: "summary_large_image"], []}, + {:meta, + [ + name: "twitter:image", + content: MediaProxy.url(url["href"]) + ], []}, + {:meta, [name: "twitter:image:alt", content: truncate(attachment["name"])], []} + ]) |> maybe_add_dimensions(url) "video" -> @@ -92,17 +92,17 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do height = url["height"] || 480 width = url["width"] || 480 - [ - {:meta, [name: "twitter:card", content: "player"], []}, - {:meta, [name: "twitter:player", content: player_url(id)], []}, - {:meta, [name: "twitter:player:width", content: "#{width}"], []}, - {:meta, [name: "twitter:player:height", content: "#{height}"], []}, - {:meta, [name: "twitter:player:stream", content: MediaProxy.url(url["href"])], - []}, - {:meta, [name: "twitter:player:stream:content_type", content: url["mediaType"]], - []} - | acc - ] + acc ++ + [ + {:meta, [name: "twitter:card", content: "player"], []}, + {:meta, [name: "twitter:player", content: player_url(id)], []}, + {:meta, [name: "twitter:player:width", content: "#{width}"], []}, + {:meta, [name: "twitter:player:height", content: "#{height}"], []}, + {:meta, [name: "twitter:player:stream", content: MediaProxy.url(url["href"])], + []}, + {:meta, [name: "twitter:player:stream:content_type", content: url["mediaType"]], + []} + ] _ -> acc |