From 0a1992430db7a859b3b7faa3d9ce4f07734b5fd8 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 26 May 2022 23:02:42 +0200 Subject: [PATCH] Fix errors when rendering RSS feeds (#18531) --- app/helpers/formatting_helper.rb | 2 +- app/helpers/languages_helper.rb | 4 ++++ app/lib/rss/media_content.rb | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/helpers/formatting_helper.rb b/app/helpers/formatting_helper.rb index f5b8dbed8..a9d2f9651 100644 --- a/app/helpers/formatting_helper.rb +++ b/app/helpers/formatting_helper.rb @@ -23,7 +23,7 @@ module FormattingHelper before_html = begin if status.spoiler_text? - "

#{I18n.t('rss.content_warning', locale: valid_locale_or_nil(status.language))} #{h(status.spoiler_text)}


" + "

#{I18n.t('rss.content_warning', locale: available_locale_or_nil(status.language) || I18n.default_locale)} #{h(status.spoiler_text)}


" else '' end diff --git a/app/helpers/languages_helper.rb b/app/helpers/languages_helper.rb index d39bb6c93..4077e19bd 100644 --- a/app/helpers/languages_helper.rb +++ b/app/helpers/languages_helper.rb @@ -254,4 +254,8 @@ module LanguagesHelper def valid_locale?(locale) locale.present? && SUPPORTED_LOCALES.key?(locale.to_sym) end + + def available_locale_or_nil(locale_name) + locale_name.to_sym if locale_name.present? && I18n.available_locales.include?(locale_name.to_sym) + end end diff --git a/app/lib/rss/media_content.rb b/app/lib/rss/media_content.rb index 7aefd8b40..f281fe29e 100644 --- a/app/lib/rss/media_content.rb +++ b/app/lib/rss/media_content.rb @@ -26,4 +26,10 @@ class RSS::MediaContent < RSS::Element description['type'] = 'plain' end end + + def thumbnail(str) + append_element('media:thumbnail') do |thumbnail| + thumbnail['url'] = str + end + end end