show.rss.ruby 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # frozen_string_literal: true
  2. RSS::Builder.build do |doc|
  3. doc.title(display_name(@account))
  4. doc.description(I18n.t('rss.descriptions.account', acct: @account.local_username_and_domain))
  5. doc.link(params[:tag].present? ? short_account_tag_url(@account, params[:tag]) : short_account_url(@account))
  6. doc.image(full_asset_url(@account.avatar.url(:original)), display_name(@account), params[:tag].present? ? short_account_tag_url(@account, params[:tag]) : short_account_url(@account))
  7. doc.last_build_date(@statuses.first.created_at) if @statuses.any?
  8. doc.icon(full_asset_url(@account.avatar.url(:original)))
  9. doc.generator("Mastodon v#{Mastodon::Version}")
  10. @statuses.each do |status|
  11. doc.item do |item|
  12. item.link(ActivityPub::TagManager.instance.url_for(status))
  13. item.pub_date(status.created_at)
  14. item.description(rss_status_content_format(status))
  15. if status.ordered_media_attachments.first&.audio?
  16. media = status.ordered_media_attachments.first
  17. item.enclosure(full_asset_url(media.file.url(:original, false)), media.file.content_type, media.file.size)
  18. end
  19. status.ordered_media_attachments.each do |media_attachment|
  20. item.media_content(full_asset_url(media_attachment.file.url(:original, false)), media_attachment.file.content_type, media_attachment.file.size) do |media_content|
  21. media_content.medium(media_attachment.gifv? ? 'image' : media_attachment.type.to_s)
  22. media_content.rating(status.sensitive? ? 'adult' : 'nonadult')
  23. media_content.description(media_attachment.description) if media_attachment.description.present?
  24. media_content.thumbnail(media_attachment.thumbnail.url(:original, false)) if media_attachment.thumbnail?
  25. end
  26. end
  27. status.tags.each do |tag|
  28. item.category(tag.display_name)
  29. end
  30. end
  31. end
  32. end