From af36d32f7f4b48d1d7a708473b2efa81401fc757 Mon Sep 17 00:00:00 2001 From: Anton Batenev <antonbatenev@yandex.ru> Date: Thu, 4 Jul 2013 22:08:23 +0400 Subject: [PATCH 1/2] 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 --- app/controllers/topics_controller.rb | 5 +++++ app/helpers/application_helper.rb | 4 ++++ app/models/site_setting.rb | 1 + app/views/topics/plain.html.erb | 19 +++++++++++++++++++ config/locales/server.en.yml | 1 + 5 files changed, 30 insertions(+) create mode 100644 app/views/topics/plain.html.erb diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 5b34b1c08..4dc05c278 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 66bc001dc..a902e0f74 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index 971629455..6dc25428d 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -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) diff --git a/app/views/topics/plain.html.erb b/app/views/topics/plain.html.erb new file mode 100644 index 000000000..79e02f2c9 --- /dev/null +++ b/app/views/topics/plain.html.erb @@ -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> diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 17b2630ee..85efbd034 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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" From 694a6f4970e420b753db609d4f78cbc5348eec9c Mon Sep 17 00:00:00 2001 From: Anton Batenev <antonbatenev@yandex.ru> Date: Fri, 5 Jul 2013 15:59:39 +0400 Subject: [PATCH 2/2] Fix recommendations from #1145 --- app/controllers/topics_controller.rb | 4 ++-- app/helpers/application_helper.rb | 6 +++--- app/models/site_setting.rb | 3 ++- config/locales/server.en.yml | 3 ++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 4dc05c278..d6188abd1 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -41,9 +41,9 @@ 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) + # render workaround pseudo-static HTML page for old crawlers which ignores <noscript> # (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_')) + return render 'topics/plain', layout: false if (SiteSetting.enable_escaped_fragments && params.has_key?('_escaped_fragment_')) View.create_for(@topic_view.topic, request.remote_ip, current_user) track_visit_to_topic diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a902e0f74..606936b19 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -78,9 +78,9 @@ 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 + # Add workaround tag for old crawlers which ignores <noscript> + # (see https://developers.google.com/webmasters/ajax-crawling/docs/specification) + result << tag('meta', name: "fragment", content: "!") if SiteSetting.enable_escaped_fragments result end diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index 6dc25428d..85dace207 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -26,7 +26,8 @@ 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_escaped_fragments, false) + client_setting(:enable_noscript_support, true) client_setting(:enable_long_polling, true) client_setting(:polling_interval, 3000) client_setting(:anon_polling_interval, 30000) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 85efbd034..f2446deeb 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -500,7 +500,8 @@ 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." + enable_escaped_fragments: "Enable workaround solution to help old crawlers to index your site. WARNING: enable it only if you are really have to do it." + enable_noscript_support: "Enable supporting <noscipt> tag" 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"