seo: fix canonical tags on post index and show page.

* Fix incorrect canonical tags. Before we were using
  `<meta name="canonical" content="...">`. This is wrong, it should have been
  `<link rel="canonical" href="...">`.

* Add a default canonical tag on all pages. Fixes Google treating the
  same content on different subdomains (safebooru, shima, kagamihara, etc)
  as duplicate content. Also fixes Google sometimes treating similar but
  distinct content on the same domain as duplicate content.
This commit is contained in:
evazion
2020-06-27 19:07:34 -05:00
parent c739e2b226
commit 580211ee64
6 changed files with 49 additions and 10 deletions

View File

@@ -10,6 +10,10 @@
<% atom_feed_tag "Posts: #{@post_set.tag_string}", posts_url(tags: @post_set.tag_string, format: :atom) %>
<% end %>
<% if params[:tags].blank? && @post_set.current_page == 1 %>
<% canonical_url root_url(host: Danbooru.config.hostname) %>
<% end %>
<% if @post_set.hide_from_crawler? %>
<meta name="robots" content="nofollow,noindex">
<% end %>
@@ -18,8 +22,6 @@
<meta name="rating" content="adult">
<% end %>
<%= tag.meta name: "canonical", content: posts_url(tags: params[:tags], host: Danbooru.config.hostname, protocol: "https") %>
<% if @post_set.best_post.present? %>
<%= tag.meta property: "og:image", content: @post_set.best_post.open_graph_image_url %>
<%= tag.meta name: "twitter:image", content: @post_set.best_post.open_graph_image_url %>

View File

@@ -1,7 +1,8 @@
<% page_title @post.presenter.humanized_essential_tag_string %>
<% meta_description "View this #{@post.image_width}x#{@post.image_height} #{number_to_human_size(@post.file_size)} image" %>
<% canonical_url post_url(@post, host: Danbooru.config.hostname) %>
<% atom_feed_tag "Comments for post ##{@post.id}", comments_url(:atom, search: { post_id: @post.id }) %>
<%= render "posts/partials/common/secondary_links" %>
<% content_for(:sidebar) do %>
@@ -148,8 +149,6 @@
<%= tag.meta property: "og:image", content: @post.open_graph_image_url %>
<% end %>
<%= tag.meta name: "canonical", content: post_url(@post, host: Danbooru.config.hostname, protocol: "https") %>
<% if @post.twitter_card_supported? %>
<meta name="twitter:card" content="summary_large_image">