mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:57:10 -06:00
FEATURE: add RSS feed for badge pages
This commit is contained in:
parent
49c6959dfc
commit
bf2c35aa99
@ -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
|
||||
|
@ -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 %>
|
||||
|
21
app/views/badges/show.rss.erb
Normal file
21
app/views/badges/show.rss.erb
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0" xmlns:discourse="http://www.discourse.org/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<channel>
|
||||
<% lang = SiteSetting.find_by_name('default_locale').try(:value) %>
|
||||
<% site_email = SiteSetting.find_by_name('contact_email').try(:value) %>
|
||||
<title><%= @rss_title %></title>
|
||||
<link><%= @rss_link %></link>
|
||||
<description><![CDATA[<%= @rss_description %>]]></description>
|
||||
<% if @badge.user_badges.first.present? %>
|
||||
<atom:link href="<%= "#{@rss_link}.rss" %>" rel="self" type="application/rss+xml" />
|
||||
<% @badge.user_badges.last(50).reverse_each do |user_badge| %>
|
||||
<item>
|
||||
<title><![CDATA[<%= "@#{user_badge.user.username}#{" #{user_badge.user.name}" if (user_badge.user.name.present? && SiteSetting.enable_names?)}" -%>]]></title>
|
||||
<discourse:grantedAt><%= user_badge.granted_at.rfc2822 %></discourse:grantedAt>
|
||||
<discourse:grantedBy><![CDATA[<%= "@#{user_badge.granted_by.username}#{" #{user_badge.granted_by.name}" if (user_badge.granted_by.name.present? && SiteSetting.enable_names?)}" -%>]]></discourse:grantedBy>
|
||||
<guid><%= "#{@rss_link}?username=#{user_badge.user.username}" %></guid>
|
||||
</item>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</channel>
|
||||
</rss>
|
@ -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."
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user