FIX: Better page titles for SEO

This commit is contained in:
Robin Ward 2014-10-30 14:26:35 -04:00
parent 212b593960
commit 572842721d
6 changed files with 34 additions and 2 deletions

View file

@ -46,8 +46,12 @@ class ApplicationController < ActionController::Base
SiteSetting.enable_escaped_fragments? && params.key?("_escaped_fragment_")
end
def use_crawler_layout?
@use_crawler_layout ||= (has_escaped_fragment? || CrawlerDetection.crawler?(request.user_agent))
end
def set_layout
has_escaped_fragment? || CrawlerDetection.crawler?(request.user_agent) ? 'crawler' : 'application'
use_crawler_layout? ? 'crawler' : 'application'
end
rescue_from Exception do |exception|

View file

@ -57,13 +57,24 @@ class ListController < ApplicationController
list_opts[:no_definitions] = true
end
list = TopicQuery.new(user, list_opts).public_send("list_#{filter}")
list.more_topics_url = construct_next_url_with(list_opts)
list.prev_topics_url = construct_prev_url_with(list_opts)
if Discourse.anonymous_filters.include?(filter)
@description = SiteSetting.site_description
@rss = filter
if use_crawler_layout?
filter_title = I18n.t("js.filters.#{filter.to_s}.title")
if list_opts[:category]
@title = I18n.t('js.filters.with_category', filter: filter_title, category: Category.find(list_opts[:category]).name)
else
@title = I18n.t('js.filters.with_topics', filter: filter_title)
end
end
end
respond(list)
end
@ -158,6 +169,11 @@ class ListController < ApplicationController
list.for_period = period
list.more_topics_url = construct_next_url_with(top_options)
list.prev_topics_url = construct_prev_url_with(top_options)
if use_crawler_layout?
@title = I18n.t("js.filters.top.#{period}.title")
end
respond(list)
end

View file

@ -28,6 +28,7 @@ class StaticController < ApplicationController
if map.has_key?(@page)
@topic = Topic.find_by_id(SiteSetting.send(map[@page][:topic_id]))
@title = @topic.title
raise Discourse::NotFound unless @topic
@body = @topic.posts.first.cooked
@faq_overriden = !SiteSetting.faq_url.blank?

View file

@ -9,4 +9,6 @@
<%- end %>
</div>
</div>
<% end %>
<% end %>
<% content_for :title do %><%= I18n.t('js.filters.categories.title') %><% end %>

View file

@ -28,6 +28,11 @@
<% content_for :head do %>
<%= auto_discovery_link_tag(@category, {action: :category_feed, format: :rss}, title: t('rss_topics_in_category', category: @category.name), type: 'application/rss+xml') %>
<% end %>
<% end %>
<% if @title %>
<% content_for :title do %><%= @title %><% end %>
<% elsif @category %>
<% content_for :title do %><%=@category.name%> <%=t('topics')%><% end %>
<% elsif params[:page] %>
<% content_for :title do %><%=t 'page_num', num: params[:page].to_i + 1 %><% end %>

View file

@ -14,3 +14,7 @@
<% end %>
<%= @body.html_safe %>
<% if @title %>
<% content_for :title do %><%= @title %><% end %>
<% end %>