Add rss feed for latest and hot

This commit is contained in:
Neil Lalonde 2013-07-05 16:49:06 -04:00
parent 4c90b16681
commit 1c0e0da683
4 changed files with 29 additions and 5 deletions

View file

@ -1,6 +1,6 @@
class ListController < ApplicationController
before_filter :ensure_logged_in, except: [:latest, :hot, :category, :category_feed]
before_filter :ensure_logged_in, except: [:latest, :hot, :category, :category_feed, :latest_feed, :hot_feed]
before_filter :set_category, only: [:category, :category_feed]
skip_before_filter :check_xhr
@ -15,6 +15,19 @@ class ListController < ApplicationController
end
end
[:latest, :hot].each do |filter|
define_method("#{filter}_feed") do
anonymous_etag(@category) do
@title = "#{filter.capitalize} Topics"
@link = "#{Discourse.base_url}/#{filter}"
@description = I18n.t("rss_description.#{filter}")
@atom_link = "#{Discourse.base_url}/#{filter}.rss"
@topic_list = TopicQuery.new(current_user).public_send("list_#{filter}")
render 'list', formats: [:rss]
end
end
end
def category
query = TopicQuery.new(current_user, page: params[:page])
@ -36,6 +49,10 @@ class ListController < ApplicationController
guardian.ensure_can_see!(@category)
anonymous_etag(@category) do
@title = @category.name
@link = "#{Discourse.base_url}/category/#{@category.slug}"
@description = "#{I18n.t('topics_in_category', category: @category.name)} #{@category.description}"
@atom_link = "#{Discourse.base_url}/category/#{@category.slug}.rss"
@topic_list = TopicQuery.new.list_new_in_category(@category)
render 'list', formats: [:rss]
end

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title><%= @category.name %></title>
<link><%= Discourse.base_url %>/category/<%= @category.slug %></link>
<description><%= t 'topics_in_category', category: @category.name %><%= @category.description %></description>
<atom:link href="<%= Discourse.base_url %>/category/<%= @category.slug %>.rss" rel="self" type="application/rss+xml" />
<title><%= @title %></title>
<link><%= @link %></link>
<description><%= @description %></description>
<atom:link href="<%= @atom_link %>" rel="self" type="application/rss+xml" />
<% @topic_list.topics.each do |topic| %>
<item>
<title><%= topic.title %></title>

View file

@ -56,6 +56,9 @@ en:
rss_topics_in_category: "RSS feed of topics in the '%{category}' category"
author_wrote: "%{author} wrote:"
private_message_abbrev: "PM"
rss_description:
latest: "Latest topics"
hot: "Hot topics"
groups:
errors:

View file

@ -179,6 +179,10 @@ Discourse::Application.routes.draw do
get 'popular' => 'list#popular_redirect'
get 'popular/more' => 'list#popular_redirect'
[:latest, :hot].each do |filter|
get "#{filter}.rss" => "list##{filter}_feed", format: :rss, as: "#{filter}_feed", filter: filter
end
[:latest, :hot, :favorited, :read, :posted, :unread, :new].each do |filter|
get "#{filter}" => "list##{filter}"
get "#{filter}/more" => "list##{filter}"