Workaround solution to help Yandex crawler index discource.

Yandex search engine doesn't index noscript tag content. See also
http://meta.discourse.org/t/noscript-tag-and-some-search-engines/8078
This commit is contained in:
Anton Batenev 2013-07-04 22:08:23 +04:00
parent 28c168fc2b
commit af36d32f7f
5 changed files with 30 additions and 0 deletions

View File

@ -40,6 +40,11 @@ class TopicsController < ApplicationController
anonymous_etag(@topic_view.topic) do
redirect_to_correct_topic && return if slugs_do_not_match
# render workaround pseudo-static HTML page for Yandex crawler (if enabled)
# (see http://meta.discourse.org/t/noscript-tag-and-some-search-engines/8078)
return render 'topics/plain', layout: false if (SiteSetting.yandex_workaround && params.has_key?('_escaped_fragment_'))
View.create_for(@topic_view.topic, request.remote_ip, current_user)
track_visit_to_topic
perform_show_response

View File

@ -78,6 +78,10 @@ module ApplicationHelper
end
end
# Add workaround tag for Yandex crawler
# (see http://help.yandex.ru/webmaster/?id=1125296)
result << tag('meta', name: "fragment", content: "!") if SiteSetting.yandex_workaround
result
end

View File

@ -26,6 +26,7 @@ class SiteSetting < ActiveRecord::Base
client_setting(:must_approve_users, false)
client_setting(:ga_tracking_code, "")
client_setting(:ga_domain_name, "")
client_setting(:yandex_workaround, false)
client_setting(:enable_long_polling, true)
client_setting(:polling_interval, 3000)
client_setting(:anon_polling_interval, 30000)

View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="<%=SiteSetting.default_locale%>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><%= render_topic_title(@topic_view.topic) %></title>
</head>
<body>
<% @topic_view.posts.each do |post| %>
<% if post.user %>
<div>
#<%=post.post_number%> <%= t 'by'%>: <b><%= post.user.name %></b>, <%= post.created_at.to_formatted_s(:long_ordinal) %>
</div>
<div>
<%= post.cooked.html_safe %>
</div>
<hr/>
<% end %>
<% end %>
</body>

View File

@ -500,6 +500,7 @@ en:
must_approve_users: "Admins must approve all users before they gain access"
ga_tracking_code: "Google analytics tracking code code, eg: UA-12345678-9; see http://google.com/analytics"
ga_domain_name: "Google analytics domain name, eg: mysite.com; see http://google.com/analytics"
yandex_workaround: "Enable workaround solution to help Yandex crawler (http://www.yandex.com) index your site. WARNING: enable it only if you are really have to do it."
top_menu: "Determine which items appear in the homepage navigation, and in what order. Example latest|hot|read|favorited|unread|new|posted|categories"
post_menu: "Determine which items appear on the post menu, and in what order. Example like|edit|flag|delete|share|bookmark|reply"
share_links: "Determine which items appear on the share dialog, and in what order. Example twitter|facebook|google+|email"