show rss <link> header on /comments

This commit is contained in:
joshua stein 2013-01-13 21:39:52 -06:00
parent ae2c0421e6
commit 14ed917baa
3 changed files with 13 additions and 6 deletions

View file

@ -58,4 +58,10 @@ class ApplicationController < ActionController::Base
def user_is_spider?
!!request.env["HTTP_USER_AGENT"].to_s.match(/Googlebot/)
end
def find_user_from_rss_token
if !@user && request[:format] == "rss" && params[:token].to_s.present?
@user = User.find_by_rss_token(params[:token])
end
end
end

View file

@ -3,6 +3,9 @@ class CommentsController < ApplicationController
before_filter :require_logged_in_user_or_400,
:only => [ :create, :preview, :preview_new, :upvote, :downvote, :unvote ]
# for rss feeds, load the user's tag filters if a token is passed
before_filter :find_user_from_rss_token, :only => [ :index ]
def create
if !(story = Story.find_by_short_id(params[:story_id])) || story.is_gone?
@ -187,6 +190,10 @@ class CommentsController < ApplicationController
end
def index
@rss_link ||= "<link rel=\"alternate\" type=\"application/rss+xml\" " <<
"title=\"RSS 2.0\" href=\"/comments.rss" <<
(@user ? "?token=#{@user.rss_token}" : "") << "\" />"
@heading = @title = "Newest Comments"
@cur_url = "/comments"

View file

@ -187,10 +187,4 @@ private
[ stories, show_more ]
end
def find_user_from_rss_token
if !@user && request[:format] == "rss" && params[:token].to_s.present?
@user = User.find_by_rss_token(params[:token])
end
end
end