mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
FIX: Better page titles for SEO
This commit is contained in:
@ -46,8 +46,12 @@ class ApplicationController < ActionController::Base
|
|||||||
SiteSetting.enable_escaped_fragments? && params.key?("_escaped_fragment_")
|
SiteSetting.enable_escaped_fragments? && params.key?("_escaped_fragment_")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def use_crawler_layout?
|
||||||
|
@use_crawler_layout ||= (has_escaped_fragment? || CrawlerDetection.crawler?(request.user_agent))
|
||||||
|
end
|
||||||
|
|
||||||
def set_layout
|
def set_layout
|
||||||
has_escaped_fragment? || CrawlerDetection.crawler?(request.user_agent) ? 'crawler' : 'application'
|
use_crawler_layout? ? 'crawler' : 'application'
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue_from Exception do |exception|
|
rescue_from Exception do |exception|
|
||||||
|
@ -57,13 +57,24 @@ class ListController < ApplicationController
|
|||||||
list_opts[:no_definitions] = true
|
list_opts[:no_definitions] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
list = TopicQuery.new(user, list_opts).public_send("list_#{filter}")
|
list = TopicQuery.new(user, list_opts).public_send("list_#{filter}")
|
||||||
list.more_topics_url = construct_next_url_with(list_opts)
|
list.more_topics_url = construct_next_url_with(list_opts)
|
||||||
list.prev_topics_url = construct_prev_url_with(list_opts)
|
list.prev_topics_url = construct_prev_url_with(list_opts)
|
||||||
if Discourse.anonymous_filters.include?(filter)
|
if Discourse.anonymous_filters.include?(filter)
|
||||||
@description = SiteSetting.site_description
|
@description = SiteSetting.site_description
|
||||||
@rss = filter
|
@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
|
||||||
|
end
|
||||||
|
|
||||||
respond(list)
|
respond(list)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -158,6 +169,11 @@ class ListController < ApplicationController
|
|||||||
list.for_period = period
|
list.for_period = period
|
||||||
list.more_topics_url = construct_next_url_with(top_options)
|
list.more_topics_url = construct_next_url_with(top_options)
|
||||||
list.prev_topics_url = construct_prev_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)
|
respond(list)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ class StaticController < ApplicationController
|
|||||||
|
|
||||||
if map.has_key?(@page)
|
if map.has_key?(@page)
|
||||||
@topic = Topic.find_by_id(SiteSetting.send(map[@page][:topic_id]))
|
@topic = Topic.find_by_id(SiteSetting.send(map[@page][:topic_id]))
|
||||||
|
@title = @topic.title
|
||||||
raise Discourse::NotFound unless @topic
|
raise Discourse::NotFound unless @topic
|
||||||
@body = @topic.posts.first.cooked
|
@body = @topic.posts.first.cooked
|
||||||
@faq_overriden = !SiteSetting.faq_url.blank?
|
@faq_overriden = !SiteSetting.faq_url.blank?
|
||||||
|
@ -10,3 +10,5 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% content_for :title do %><%= I18n.t('js.filters.categories.title') %><% end %>
|
||||||
|
@ -28,6 +28,11 @@
|
|||||||
<% content_for :head do %>
|
<% 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') %>
|
<%= 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 %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if @title %>
|
||||||
|
<% content_for :title do %><%= @title %><% end %>
|
||||||
|
<% elsif @category %>
|
||||||
<% content_for :title do %><%=@category.name%> <%=t('topics')%><% end %>
|
<% content_for :title do %><%=@category.name%> <%=t('topics')%><% end %>
|
||||||
<% elsif params[:page] %>
|
<% elsif params[:page] %>
|
||||||
<% content_for :title do %><%=t 'page_num', num: params[:page].to_i + 1 %><% end %>
|
<% content_for :title do %><%=t 'page_num', num: params[:page].to_i + 1 %><% end %>
|
||||||
|
@ -14,3 +14,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= @body.html_safe %>
|
<%= @body.html_safe %>
|
||||||
|
|
||||||
|
<% if @title %>
|
||||||
|
<% content_for :title do %><%= @title %><% end %>
|
||||||
|
<% end %>
|
||||||
|
Reference in New Issue
Block a user