FEATURE: RSS feed for top page period filters

This commit is contained in:
Arpit Jalan 2017-03-13 14:24:10 +05:30
parent 4d4a1a1552
commit 848120c098
4 changed files with 65 additions and 4 deletions

View File

@ -46,6 +46,7 @@ class ListController < ApplicationController
:parent_category_category_top,
# top pages (ie. with a period)
TopTopic.periods.map { |p| :"top_#{p}" },
TopTopic.periods.map { |p| :"top_#{p}_feed" },
TopTopic.periods.map { |p| :"category_top_#{p}" },
TopTopic.periods.map { |p| :"category_none_top_#{p}" },
TopTopic.periods.map { |p| :"parent_category_category_top_#{p}" },
@ -168,7 +169,7 @@ class ListController < ApplicationController
@link = "#{Discourse.base_url}/top"
@atom_link = "#{Discourse.base_url}/top.rss"
@description = I18n.t("rss_description.top")
@topic_list = TopicQuery.new(nil).list_top_for("monthly")
@topic_list = TopicQuery.new(nil).list_top_for(SiteSetting.top_page_default_timeframe.to_sym)
render 'list', formats: [:rss]
end
@ -232,7 +233,7 @@ class ListController < ApplicationController
list.for_period = period
list.more_topics_url = construct_url_with(:next, top_options)
list.prev_topics_url = construct_url_with(:prev, top_options)
@rss = "top"
@rss = "top_#{period}"
if use_crawler_layout?
@title = I18n.t("js.filters.top.#{period}.title")
@ -252,6 +253,19 @@ class ListController < ApplicationController
define_method("parent_category_category_top_#{period}") do
self.send("top_#{period}", category: @category.id)
end
# rss feed
define_method("top_#{period}_feed") do |options = nil|
discourse_expires_in 1.minute
@description = I18n.t("rss_description.top_#{period}")
@title = "#{SiteSetting.title} - #{@description}"
@link = "#{Discourse.base_url}/top/#{period}"
@atom_link = "#{Discourse.base_url}/top/#{period}.rss"
@topic_list = TopicQuery.new(nil).list_top_for(period)
render 'list', formats: [:rss]
end
end
protected

View File

@ -229,6 +229,12 @@ en:
latest: "Latest topics"
hot: "Hot topics"
top: "Top topics"
top_all: "All time top topics"
top_yearly: "Yearly top topics"
top_quarterly: "Quarterly top topics"
top_monthly: "Monthly top topics"
top_weekly: "Weekly top topics"
top_daily: "Daily top topics"
posts: "Latest posts"
private_posts: "Latest private messages"
group_posts: "Latest posts from %{group_name}"

View File

@ -503,6 +503,7 @@ Discourse::Application.routes.draw do
get "category_hashtags/check" => "category_hashtags#check"
TopTopic.periods.each do |period|
get "top/#{period}.rss" => "list#top_#{period}_feed", format: :rss
get "top/#{period}" => "list#top_#{period}"
get "c/:category/l/top/#{period}" => "list#category_top_#{period}", as: "category_top_#{period}"
get "c/:category/none/l/top/#{period}" => "list#category_none_top_#{period}", as: "category_none_top_#{period}"

View File

@ -49,13 +49,53 @@ describe ListController do
end
describe 'RSS feeds' do
it 'renders RSS' do
it 'renders latest RSS' do
get "latest_feed", format: :rss
expect(response).to be_success
expect(response.content_type).to eq('application/rss+xml')
end
it 'renders top RSS' do
get "top_feed", format: :rss
expect(response).to be_success
expect(response.content_type).to eq('application/rss+xml')
end
it 'renders all time top RSS' do
get "top_all_feed", format: :rss
expect(response).to be_success
expect(response.content_type).to eq('application/rss+xml')
end
it 'renders yearly top RSS' do
get "top_yearly_feed", format: :rss
expect(response).to be_success
expect(response.content_type).to eq('application/rss+xml')
end
it 'renders quarterly top RSS' do
get "top_quarterly_feed", format: :rss
expect(response).to be_success
expect(response.content_type).to eq('application/rss+xml')
end
it 'renders monthly top RSS' do
get "top_monthly_feed", format: :rss
expect(response).to be_success
expect(response.content_type).to eq('application/rss+xml')
end
it 'renders weekly top RSS' do
get "top_weekly_feed", format: :rss
expect(response).to be_success
expect(response.content_type).to eq('application/rss+xml')
end
it 'renders daily top RSS' do
get "top_daily_feed", format: :rss
expect(response).to be_success
expect(response.content_type).to eq('application/rss+xml')
end
end
context 'category' do