mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FEATURE: latest posts RSS feed
This commit is contained in:
parent
5db768b69f
commit
71ee84f848
3 changed files with 41 additions and 9 deletions
|
@ -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
|
||||
|
|
21
app/views/posts/latest.rss.erb
Normal file
21
app/views/posts/latest.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">
|
||||
<channel>
|
||||
<% lang = SiteSetting.find_by_name('default_locale').try(:value) %>
|
||||
<% site_email = SiteSetting.find_by_name('contact_email').try(:value) %>
|
||||
<title><%= @title %></title>
|
||||
<link><%= @link %></link>
|
||||
<description><%= @description %></description>
|
||||
<% @posts.each do |post| %>
|
||||
<% next unless post.user %>
|
||||
<item>
|
||||
<title><%= post.topic.title %></title>
|
||||
<author><%= "no-reply@example.com (@#{post.user.username}#{" #{post.user.name}" if (post.user.name.present? && SiteSetting.enable_names?)})" -%></author>
|
||||
<description><![CDATA[ <%= post.cooked.html_safe %> ]]></description>
|
||||
<link><%= Discourse.base_url + post.url %></link>
|
||||
<pubDate><%= post.created_at.rfc2822 %></pubDate>
|
||||
<guid isPermaLink="false">post-<%= post.id %></guid>
|
||||
</item>
|
||||
<% end %>
|
||||
</channel>
|
||||
</rss>
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue