Files
mastodon/app/serializers/seo/social_media_posting_serializer.rb
jcoffey-dev 319ed76dbd
Crowdin / Upload translations / upload-translations (push) Skipped
Historical data migration test / test (14-alpine) (push) Canceled after 0s
Historical data migration test / test (15-alpine) (push) Canceled after 0s
Historical data migration test / test (16-alpine) (push) Canceled after 0s
Historical data migration test / test (17-alpine) (push) Canceled after 0s
Bundler Audit / security (push) Canceled after 0s
Haml Linting / lint (push) Canceled after 0s
JavaScript Linting / lint (push) Canceled after 0s
Ruby Linting / lint (push) Canceled after 0s
JavaScript Testing / test (push) Canceled after 0s
Ruby Testing / build (production) (push) Canceled after 0s
Ruby Testing / test (.ruby-version) (push) Canceled after 0s
Ruby Testing / test (3.3) (push) Canceled after 0s
Ruby Testing / test (3.4) (push) Canceled after 0s
Ruby Testing / End to End testing (.ruby-version) (push) Canceled after 0s
Ruby Testing / End to End testing (3.3) (push) Canceled after 0s
Ruby Testing / End to End testing (3.4) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check i18n / check-i18n (push) Canceled after 0s
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (javascript) (push) Canceled after 0s
CodeQL / Analyze (ruby) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check formatting / lint (push) Canceled after 0s
CSS Linting / lint (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Canceled after 0s
Chromatic / Check for relevant changes (push) Canceled after 0s
Chromatic / Run Chromatic (push) Canceled after 0s
Import Mastodon v4.7.3
Snapshot of upstream tag v4.7.3 (commit 8ff11c2bb7b9f0714e947b10fa3629c6542c7121) from
https://github.com/mastodon/mastodon, unmodified.
2026-10-05 22:03:13 -07:00

128 lines
3.6 KiB
Ruby

# frozen_string_literal: true
class SEO::SocialMediaPostingSerializer < ActiveModel::Serializer
include FormattingHelper
include RoutingHelper
attributes :context, :type, :url, :date_published, :date_modified,
:author, :text, :interaction_statistic
attribute :image, if: -> { object.ordered_media_attachments.any?(&:image?) }
attribute :video, if: -> { object.ordered_media_attachments.any? { |attachment| attachment.video? || attachment.gifv? } }
attribute :audio, if: -> { object.ordered_media_attachments.any?(&:audio?) }
attribute :shared_content, if: -> { object.with_preview_card? }
def context
'https://schema.org'
end
def type
'SocialMediaPosting'
end
def url
ActivityPub::TagManager.instance.url_for(object)
end
def date_published
object.created_at.iso8601
end
def date_modified
object.edited_at&.iso8601
end
def author
{
type: 'Person',
name: object.account.display_name.presence || object.account.username,
alternate_name: object.account.local_username_and_domain,
identifier: object.account.local_username_and_domain,
url: ActivityPub::TagManager.instance.url_for(object.account),
interaction_statistic: [
{
type: 'InteractionCounter',
interaction_type: 'https://schema.org/FollowAction',
user_interaction_count: object.account.followers_count,
},
],
}
end
def text
status_content_format(object)
end
def interaction_statistic
[
{
type: 'InteractionCounter',
interaction_type: 'https://schema.org/LikeAction',
user_interaction_count: object.favourites_count,
},
{
type: 'InteractionCounter',
interaction_type: 'https://schema.org/ShareAction',
user_interaction_count: object.reblogs_count,
},
{
type: 'InteractionCounter',
interaction_type: 'https://schema.org/ReplyAction',
user_interaction_count: object.replies_count,
},
]
end
def image
object.ordered_media_attachments.filter_map do |attachment|
next unless attachment.image?
{
type: 'ImageObject',
content_url: full_asset_url(attachment.file.url(:original, false)),
thumbnail_url: attachment.thumbnail.present? ? full_asset_url(attachment.thumbnail.url(:original)) : full_asset_url(attachment.file.url(:small)),
description: attachment.description,
}
end
end
def video
object.ordered_media_attachments.filter_map do |attachment|
next unless attachment.video? || attachment.gifv?
{
type: 'VideoObject',
upload_date: attachment.created_at.iso8601,
content_url: full_asset_url(attachment.file.url(:original, false)),
thumbnail_url: attachment.thumbnail.present? ? full_asset_url(attachment.thumbnail.url(:original)) : full_asset_url(attachment.file.url(:small)),
embed_url: player_medium_url(attachment),
description: attachment.description,
}
end
end
def audio
object.ordered_media_attachments.filter_map do |attachment|
next unless attachment.audio?
{
type: 'AudioObject',
upload_date: attachment.created_at.iso8601,
content_url: full_asset_url(attachment.file.url(:original, false)),
thumbnail_url: attachment.thumbnail.present? ? full_asset_url(attachment.thumbnail.url(:original)) : full_asset_url(attachment.file.url(:small)),
embed_url: player_medium_url(attachment),
description: attachment.description,
}
end
end
def shared_content
{
type: 'WebPage',
url: object.preview_card.url,
}
end
end