simplify rss <link> generation

This commit is contained in:
joshua stein 2014-03-12 17:50:51 -05:00
parent 24c92840c3
commit 6cab668a2f
3 changed files with 14 additions and 14 deletions

View file

@ -161,9 +161,8 @@ 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}" : "") << "\" />"
@rss_link ||= { :title => "RSS 2.0 - Newest Comments",
:href => "/comments.rss#{@user ? "?token=#{@user.rss_token}" : ""}" }
@heading = @title = "Newest Comments"
@cur_url = "/comments"

View file

@ -22,9 +22,8 @@ class HomeController < ApplicationController
def index
@stories = find_stories
@rss_link ||= "<link rel=\"alternate\" type=\"application/rss+xml\" " <<
"title=\"RSS 2.0\" href=\"/rss" <<
(@user ? "?token=#{@user.rss_token}" : "") << "\" />"
@rss_link ||= { :title => "RSS 2.0",
:href => "/rss#{@user ? "?token=#{@user.rss_token}" : ""}" }
@heading = @title = ""
@cur_url = "/"
@ -48,9 +47,8 @@ class HomeController < ApplicationController
@heading = @title = "Newest Stories"
@cur_url = "/newest"
@rss_link = "<link rel=\"alternate\" type=\"application/rss+xml\" " <<
"title=\"RSS 2.0 - Newest Items\" href=\"/newest.rss" <<
(@user ? "?token=#{@user.rss_token}" : "") << "\" />"
@rss_link = { :title => "RSS 2.0 - Newest Items",
:href => "/newest.rss#{@user ? "?token=#{@user.rss_token}" : ""}" }
respond_to do |format|
format.html { render :action => "index" }
@ -85,6 +83,10 @@ class HomeController < ApplicationController
@heading = @title = "Recent Stories"
@cur_url = "/recent"
# our content changes every page load, so point at /newest.rss to be stable
@rss_link = { :title => "RSS 2.0 - Newest Items",
:href => "/newest.rss#{@user ? "?token=#{@user.rss_token}" : ""}" }
render :action => "index"
end
@ -96,10 +98,8 @@ class HomeController < ApplicationController
@heading = @title = @tag.description.blank?? @tag.tag : @tag.description
@cur_url = tag_url(@tag.tag)
@rss_link = "<link rel=\"alternate\" type=\"application/rss+xml\" " <<
"title=\"RSS 2.0 - Tagged #{CGI.escape(@tag.tag)} " <<
"(#{CGI.escape(@tag.description.to_s)})\" href=\"/t/" +
"#{CGI.escape(@tag.tag)}.rss\" />"
@rss_link = { :title => "RSS 2.0 - Tagged #{@tag.tag} (#{@tag.description})",
:href => "/t/#{@tag.tag}.rss" }
respond_to do |format|
format.html { render :action => "index" }

View file

@ -25,7 +25,8 @@
<% end %>
<%= csrf_meta_tags %>
<% if @rss_link %>
<%= raw(@rss_link) %>
<link rel="alternate" type="application/rss+xml"
title="<%= @rss_link[:title] %>" href="<%= @rss_link[:href] %>" />
<% end %>
</head>
<body>