diff --git a/app/controllers/badges_controller.rb b/app/controllers/badges_controller.rb index 6447558befe..27a2d909ccc 100644 --- a/app/controllers/badges_controller.rb +++ b/app/controllers/badges_controller.rb @@ -39,6 +39,8 @@ class BadgesController < ApplicationController params.require(:id) @badge = Badge.enabled.find(params[:id]) + @rss_title = I18n.t('rss_description.badge', display_name: @badge.display_name, site_title: SiteSetting.title) + @rss_link = "#{Discourse.base_url}/badges/#{@badge.id}/#{@badge.slug}" if current_user user_badge = UserBadge.find_by(user_id: current_user.id, badge_id: @badge.id) @@ -49,9 +51,11 @@ class BadgesController < ApplicationController serialized = MultiJson.dump(serialize_data(@badge, BadgeSerializer, root: "badge", include_long_description: true)) respond_to do |format| + format.rss do + @rss_description = @badge.long_description + end format.html do store_preloaded "badge", serialized - render :show end format.json { render json: serialized } end diff --git a/app/views/badges/show.html.erb b/app/views/badges/show.html.erb index 6fc281b9dd6..1022d59a0d0 100644 --- a/app/views/badges/show.html.erb +++ b/app/views/badges/show.html.erb @@ -1,3 +1,4 @@ <% content_for :head do %> <%= raw crawlable_meta_data(title: I18n.t('badges.badge_title_metadata', display_name: @badge.display_name, site_title: SiteSetting.title), description: @badge.long_description) %> + <%= auto_discovery_link_tag(:rss, "#{@rss_link}.rss", title: @rss_title) %> <% end %> diff --git a/app/views/badges/show.rss.erb b/app/views/badges/show.rss.erb new file mode 100644 index 00000000000..ca74f8091a4 --- /dev/null +++ b/app/views/badges/show.rss.erb @@ -0,0 +1,21 @@ + + + + <% lang = SiteSetting.find_by_name('default_locale').try(:value) %> + <% site_email = SiteSetting.find_by_name('contact_email').try(:value) %> + <%= @rss_title %> + <%= @rss_link %> + ]]> + <% if @badge.user_badges.first.present? %> + " rel="self" type="application/rss+xml" /> + <% @badge.user_badges.last(50).reverse_each do |user_badge| %> + + <![CDATA[<%= "@#{user_badge.user.username}#{" #{user_badge.user.name}" if (user_badge.user.name.present? && SiteSetting.enable_names?)}" -%>]]> + <%= user_badge.granted_at.rfc2822 %> + ]]> + <%= "#{@rss_link}?username=#{user_badge.user.username}" %> + + <% end %> + <% end %> + + diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index b3559db9816..93cdfb59955 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -232,6 +232,7 @@ en: num_participants: "Participants:" read_full_topic: "Read full topic" private_message_abbrev: "Msg" + rss_description: latest: "Latest topics" hot: "Hot topics" @@ -249,6 +250,8 @@ en: user_posts: "Latest posts by @%{username}" user_topics: "Latest topics by @%{username}" tag: "Tagged topics" + badge: "%{display_name} badge on %{site_title}" + too_late_to_edit: "That post was created too long ago. It can no longer be edited or deleted." revert_version_same: "The current version is same as the version you are trying to revert to." diff --git a/spec/controllers/badges_controller_spec.rb b/spec/controllers/badges_controller_spec.rb index a2bb4420dcd..a59cc812081 100644 --- a/spec/controllers/badges_controller_spec.rb +++ b/spec/controllers/badges_controller_spec.rb @@ -33,5 +33,11 @@ describe BadgesController do get :show, id: badge.id, format: :json expect(user_badge.notification.reload.read).to eq(true) end + + it 'renders rss feed of a badge' do + get :show, id: badge.id, format: :rss + expect(response.status).to eq(200) + expect(response.content_type).to eq('application/rss+xml') + end end end