diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index f595ada8676..ad0e8cb5409 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -9,7 +9,7 @@ class PostsController < ApplicationController # Need to be logged in for all actions here before_filter :ensure_logged_in, except: [:show, :replies, :by_number, :short_link, :reply_history, :revisions, :latest_revision, :expand_embed, :markdown_id, :markdown_num, :cooked, :latest] - skip_before_filter :preload_json, :check_xhr, only: [:markdown_id, :markdown_num, :short_link] + skip_before_filter :preload_json, :check_xhr, only: [:markdown_id, :markdown_num, :short_link, :latest] def markdown_id markdown Post.find(params[:id].to_i) @@ -42,16 +42,26 @@ class PostsController < ApplicationController # Remove posts the user doesn't have permission to see # This isn't leaking any information we weren't already through the post ID numbers posts = posts.reject { |post| !guardian.can_see?(post) } - counts = PostAction.counts_for(posts, current_user) - render_json_dump(serialize_data(posts, - PostSerializer, - scope: guardian, - root: 'latest_posts', - add_raw: true, - all_post_actions: counts) - ) + respond_to do |format| + format.rss do + @posts = posts + @title = "#{SiteSetting.title} - #{I18n.t("rss_description.posts")}" + @link = Discourse.base_url + @description = I18n.t("rss_description.posts") + render 'posts/latest', formats: [:rss] + end + format.json do + render_json_dump(serialize_data(posts, + PostSerializer, + scope: guardian, + root: 'latest_posts', + add_raw: true, + all_post_actions: counts) + ) + end + end end def cooked diff --git a/app/views/posts/latest.rss.erb b/app/views/posts/latest.rss.erb new file mode 100644 index 00000000000..04aeb027870 --- /dev/null +++ b/app/views/posts/latest.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) %> + <%= @title %> + <%= @link %> + <%= @description %> + <% @posts.each do |post| %> + <% next unless post.user %> + + <%= post.topic.title %> + <%= "no-reply@example.com (@#{post.user.username}#{" #{post.user.name}" if (post.user.name.present? && SiteSetting.enable_names?)})" -%> + ]]> + <%= Discourse.base_url + post.url %> + <%= post.created_at.rfc2822 %> + post-<%= post.id %> + + <% end %> + + diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 9ca22fef336..fc8525206f4 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -173,6 +173,7 @@ en: rss_description: latest: "Latest topics" hot: "Hot topics" + posts: "Latest posts" too_late_to_edit: "That post was created too long ago. It can no longer be edited or deleted." excerpt_image: "image"