mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-10 11:19:19 +00:00
ac7ef0999d
Twitter cards were not passing any useful metadata. A few things were being handled on Twitter's end by trying to match OpenGraph tags with their own, but it wasn't working at all for media. This is an attempt to fix that. Common functions have been pulled out of opengraph and put into utils. Twitter's functionality was entirely replaced with a direct copy of Opengraph's and then modified as needed. Profiles are now represented as Summary Cards Posts with images are now represented as Summart with Large Image Cards Posts with video and audio attachments are represented as Player Cards. This now passes the Twitter Card Validator. Validator and Docs are below https://cards-dev.twitter.com/validator https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/abouts-cards
42 lines
1.2 KiB
Elixir
42 lines
1.2 KiB
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright \xc2\xa9 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Web.Metadata.Utils do
|
|
alias Pleroma.HTML
|
|
alias Pleroma.Formatter
|
|
alias Pleroma.Web.MediaProxy
|
|
|
|
def scrub_html_and_truncate(%{data: %{"content" => content}} = object) 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(object, __MODULE__)
|
|
|> Formatter.demojify()
|
|
|> Formatter.truncate()
|
|
end
|
|
|
|
def scrub_html_and_truncate(content) when is_binary(content) do
|
|
content
|
|
# html content comes from DB already encoded, decode first and scrub after
|
|
|> HtmlEntities.decode()
|
|
|> String.replace(~r/<br\s?\/?>/, " ")
|
|
|> HTML.strip_tags()
|
|
|> Formatter.demojify()
|
|
|> Formatter.truncate()
|
|
end
|
|
|
|
def attachment_url(url) do
|
|
MediaProxy.url(url)
|
|
end
|
|
|
|
def user_name_string(user) do
|
|
"#{user.name} " <>
|
|
if user.local do
|
|
"(@#{user.nickname}@#{Pleroma.Web.Endpoint.host()})"
|
|
else
|
|
"(@#{user.nickname})"
|
|
end
|
|
end
|
|
end
|