diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index a65777768..635d6a1dd 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -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 diff --git a/app/views/list/list.rss.erb b/app/views/list/list.rss.erb index 7dd92c017..8c6a1979a 100644 --- a/app/views/list/list.rss.erb +++ b/app/views/list/list.rss.erb @@ -1,10 +1,10 @@ - <%= @category.name %> - <%= Discourse.base_url %>/category/<%= @category.slug %> - <%= t 'topics_in_category', category: @category.name %><%= @category.description %> - + <%= @title %> + <%= @link %> + <%= @description %> + <% @topic_list.topics.each do |topic| %> <%= topic.title %> diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index f2446deeb..bd319589a 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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: diff --git a/config/routes.rb b/config/routes.rb index 4679da32c..8a0bd7848 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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}"