Add rss feed for latest and hot
This commit is contained in:
parent
4c90b16681
commit
1c0e0da683
4 changed files with 29 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
||||||
class ListController < ApplicationController
|
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]
|
before_filter :set_category, only: [:category, :category_feed]
|
||||||
skip_before_filter :check_xhr
|
skip_before_filter :check_xhr
|
||||||
|
|
||||||
|
@ -15,6 +15,19 @@ class ListController < ApplicationController
|
||||||
end
|
end
|
||||||
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
|
def category
|
||||||
query = TopicQuery.new(current_user, page: params[:page])
|
query = TopicQuery.new(current_user, page: params[:page])
|
||||||
|
|
||||||
|
@ -36,6 +49,10 @@ class ListController < ApplicationController
|
||||||
guardian.ensure_can_see!(@category)
|
guardian.ensure_can_see!(@category)
|
||||||
|
|
||||||
anonymous_etag(@category) do
|
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)
|
@topic_list = TopicQuery.new.list_new_in_category(@category)
|
||||||
render 'list', formats: [:rss]
|
render 'list', formats: [:rss]
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<?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>
|
||||||
<title><%= @category.name %></title>
|
<title><%= @title %></title>
|
||||||
<link><%= Discourse.base_url %>/category/<%= @category.slug %></link>
|
<link><%= @link %></link>
|
||||||
<description><%= t 'topics_in_category', category: @category.name %><%= @category.description %></description>
|
<description><%= @description %></description>
|
||||||
<atom:link href="<%= Discourse.base_url %>/category/<%= @category.slug %>.rss" 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| %>
|
||||||
<item>
|
<item>
|
||||||
<title><%= topic.title %></title>
|
<title><%= topic.title %></title>
|
||||||
|
|
|
@ -56,6 +56,9 @@ en:
|
||||||
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:"
|
||||||
private_message_abbrev: "PM"
|
private_message_abbrev: "PM"
|
||||||
|
rss_description:
|
||||||
|
latest: "Latest topics"
|
||||||
|
hot: "Hot topics"
|
||||||
|
|
||||||
groups:
|
groups:
|
||||||
errors:
|
errors:
|
||||||
|
|
|
@ -179,6 +179,10 @@ Discourse::Application.routes.draw do
|
||||||
get 'popular' => 'list#popular_redirect'
|
get 'popular' => 'list#popular_redirect'
|
||||||
get 'popular/more' => '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|
|
[:latest, :hot, :favorited, :read, :posted, :unread, :new].each do |filter|
|
||||||
get "#{filter}" => "list##{filter}"
|
get "#{filter}" => "list##{filter}"
|
||||||
get "#{filter}/more" => "list##{filter}"
|
get "#{filter}/more" => "list##{filter}"
|
||||||
|
|
Reference in a new issue