add more info to rss feeds

This commit is contained in:
Alexander 2013-12-15 01:17:39 -08:00
parent 1145e4bfd9
commit d93e4fc65d
5 changed files with 46 additions and 31 deletions

View File

@ -281,10 +281,6 @@ class Post < ActiveRecord::Base
end end
end end
def author_readable
user.readable_name
end
def revise(updated_by, new_raw, opts = {}) def revise(updated_by, new_raw, opts = {})
PostRevisor.new(self).revise!(updated_by, new_raw, opts) PostRevisor.new(self).revise!(updated_by, new_raw, opts)
end end

View File

@ -1,22 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel> <channel>
<% lang = SiteSetting.find_by_name('default_locale').try(:value) %>
<title><%= @title %></title> <title><%= @title %></title>
<link><%= @link %></link> <link><%= @link %></link>
<description><%= @description %></description> <description><%= @description %></description>
<% if lang %>
<language><%= lang %></language>
<% end %>
<lastBuildDate><%= @topic_list.topics.first.created_at.rfc2822 %></lastBuildDate>
<atom:link href="<%= @atom_link %>" rel="self" type="application/rss+xml" /> <atom:link href="<%= @atom_link %>" rel="self" type="application/rss+xml" />
<% @topic_list.topics.each do |topic| %> <% @topic_list.topics.each do |topic| %>
<% topic_url = Discourse.base_url + topic.relative_url -%>
<item> <item>
<title><%= topic.title %></title> <title><%= topic.title %></title>
<author><%= "@#{topic.user.username} (#{topic.user.name})" -%></author>
<category><%= topic.category.name %></category>
<description><![CDATA[ <description><![CDATA[
<p><%= pluralize(topic.posts_count, 'post') %></p> <p><%= t('author_wrote', author: link_to(topic.user.name, topic.user)).html_safe %></p>
<p><%= t 'author_wrote', author: topic.posts.first.author_readable %></p> <blockquote>
<%= topic.posts.first.cooked.html_safe %> <%= topic.posts.first.cooked.html_safe %>
</blockquote>
<p><%= t 'num_posts' %> <%= topic.posts_count %></p>
<p><%= t 'num_participants' %> <%= topic.participant_count %></p>
<p><%= link_to t('read_full_topic'), topic_url %></p>
]]></description> ]]></description>
<link><%= Discourse.base_url %><%= topic.relative_url %></link> <link><%= topic_url %></link>
<pubDate><%= topic.created_at.rfc2822 %></pubDate> <pubDate><%= topic.created_at.rfc2822 %></pubDate>
<guid><%= Discourse.base_url %><%= topic.relative_url %></guid> <guid><%= topic_url %></guid>
<source url="<%= Discourse.base_url %><%= topic.relative_url %>.rss"><%= topic.title %></source> <source url="<%= topic_url %>.rss"><%= topic.title %></source>
</item> </item>
<% end %> <% end %>
</channel> </channel>

View File

@ -1,24 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel> <channel>
<% topic_url = Discourse.base_url + @topic_view.relative_url %>
<% lang = SiteSetting.find_by_name('default_locale').try(:value) %>
<title><%= @topic_view.title %></title> <title><%= @topic_view.title %></title>
<link><%= Discourse.base_url %><%= @topic_view.relative_url %></link> <link><%= topic_url %></link>
<description><%= @topic_view.posts.first.raw %></description> <description><%= @topic_view.posts.first.raw %></description>
<atom:link href="<%= Discourse.base_url %><%= @topic_view.relative_url %>.rss" rel="self" type="application/rss+xml" /> <% if lang %>
<language><%= lang %></language>
<% end %>
<lastBuildDate><%= @topic_view.topic.created_at.rfc2822 %></lastBuildDate>
<category><%= @topic_view.topic.category.name %></category>
<atom:link href="<%= topic_url %>.rss" rel="self" type="application/rss+xml" />
<% @topic_view.recent_posts.each do |post| %> <% @topic_view.recent_posts.each do |post| %>
<% if post.user %> <% next unless post.user %>
<item> <item>
<title><%= @topic_view.title %> at <%= post.created_at %></title> <title><%= @topic_view.title %> at <%= post.created_at %></title>
<description><![CDATA[ <author><%= "@#{post.user.username} (#{post.user.name})" -%></author>
<p><%= post.author_readable %> wrote:</p> <description><![CDATA[
<% post_url = Discourse.base_url + post.url %>
<p><%= t('author_wrote', author: link_to(post.user.name, post.user)).html_safe %></p>
<blockquote>
<%= post.cooked.html_safe %> <%= post.cooked.html_safe %>
]]></description> </blockquote>
<link><%= Discourse.base_url %><%= post.url %></link> <p><%= link_to t('read_full_topic'), post_url %></p>
<pubDate><%= post.created_at.rfc2822 %></pubDate> ]]></description>
<guid><%= Discourse.base_url %><%= post.url %></guid> <link><%= post_url %></link>
<source url="<%= Discourse.base_url %><%= @topic_view.relative_url %>.rss"><%= @topic_view.title %></source> <pubDate><%= post.created_at.rfc2822 %></pubDate>
</item> <guid><%= post_url %></guid>
<% end %> <source url="<%= Discourse.base_url %><%= @topic_view.relative_url %>.rss"><%= @topic_view.title %></source>
</item>
<% end %> <% end %>
</channel> </channel>
</rss> </rss>

View File

@ -59,6 +59,9 @@ en:
rss_posts_in_topic: "RSS feed of '%{topic}'" rss_posts_in_topic: "RSS feed of '%{topic}'"
rss_topics_in_category: "RSS feed of topics in the '%{category}' category" rss_topics_in_category: "RSS feed of topics in the '%{category}' category"
author_wrote: "%{author} wrote:" author_wrote: "%{author} wrote:"
num_posts: "Posts:"
num_participants: "Participants:"
read_full_topic: "Read full topic"
private_message_abbrev: "PM" private_message_abbrev: "PM"
rss_description: rss_description:
latest: "Latest topics" latest: "Latest topics"

View File

@ -742,13 +742,6 @@ describe Post do
end end
describe '#readable_author' do
it 'delegates to the associated user' do
User.any_instance.expects(:readable_name)
Fabricate(:post).author_readable
end
end
describe 'urls' do describe 'urls' do
it 'no-ops for empty list' do it 'no-ops for empty list' do
Post.urls([]).should == {} Post.urls([]).should == {}