Use canonical-rails gem to generate canonical URLs

This commit is contained in:
Tom Hughes 2017-03-22 18:16:53 +00:00
parent ce209c8c4f
commit 24271b75bd
4 changed files with 46 additions and 19 deletions

View file

@ -95,6 +95,9 @@ gem "kgio"
# Load secure_headers for Content-Security-Policy support # Load secure_headers for Content-Security-Policy support
gem "secure_headers" gem "secure_headers"
# Load canonical-rails to generate canonical URLs
gem "canonical-rails"
# Used to generate logstash friendly log files # Used to generate logstash friendly log files
gem "logstasher" gem "logstasher"

View file

@ -42,11 +42,13 @@ GEM
public_suffix (~> 2.0, >= 2.0.2) public_suffix (~> 2.0, >= 2.0.2)
arel (6.0.4) arel (6.0.4)
ast (2.3.0) ast (2.3.0)
autoprefixer-rails (6.7.5) autoprefixer-rails (6.7.7.1)
execjs execjs
bigdecimal (1.1.0) bigdecimal (1.1.0)
builder (3.2.3) builder (3.2.3)
capybara (2.12.1) canonical-rails (0.1.2)
rails (>= 4.1, < 5.1)
capybara (2.13.0)
addressable addressable
mime-types (>= 1.16) mime-types (>= 1.16)
nokogiri (>= 1.3.3) nokogiri (>= 1.3.3)
@ -67,7 +69,7 @@ GEM
colorize (0.8.1) colorize (0.8.1)
composite_primary_keys (8.1.4) composite_primary_keys (8.1.4)
activerecord (~> 4.2.0) activerecord (~> 4.2.0)
concurrent-ruby (1.0.4) concurrent-ruby (1.0.5)
coveralls (0.8.19) coveralls (0.8.19)
json (>= 1.8, < 3) json (>= 1.8, < 3)
simplecov (~> 0.12.0) simplecov (~> 0.12.0)
@ -89,9 +91,9 @@ GEM
factory_girl_rails (4.8.0) factory_girl_rails (4.8.0)
factory_girl (~> 4.8.0) factory_girl (~> 4.8.0)
railties (>= 3.0.0) railties (>= 3.0.0)
faraday (0.10.1) faraday (0.11.0)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
fspath (3.0.3) fspath (3.1.0)
geoip (1.6.3) geoip (1.6.3)
globalid (0.3.7) globalid (0.3.7)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
@ -100,7 +102,7 @@ GEM
htmlentities (4.3.4) htmlentities (4.3.4)
http_accept_language (2.0.5) http_accept_language (2.0.5)
i18n (0.8.1) i18n (0.8.1)
i18n-js (3.0.0.rc15) i18n-js (3.0.0.rc16)
i18n (~> 0.6, >= 0.6.6) i18n (~> 0.6, >= 0.6.6)
image_optim (0.24.2) image_optim (0.24.2)
exifr (~> 1.2, >= 1.2.2) exifr (~> 1.2, >= 1.2.2)
@ -108,13 +110,13 @@ GEM
image_size (~> 1.5) image_size (~> 1.5)
in_threads (~> 1.3) in_threads (~> 1.3)
progress (~> 3.0, >= 3.0.1) progress (~> 3.0, >= 3.0.1)
image_optim_rails (0.2.0) image_optim_rails (0.3.0)
image_optim (~> 0.24.0) image_optim (~> 0.24.0)
rails rails
sprockets sprockets
image_size (1.5.0) image_size (1.5.0)
in_threads (1.3.1) in_threads (1.4.0)
jquery-rails (4.2.2) jquery-rails (4.3.1)
rails-dom-testing (>= 1, < 3) rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
@ -138,11 +140,10 @@ GEM
sprockets (>= 2, < 4) sprockets (>= 2, < 4)
sprockets-rails (>= 2, < 4) sprockets-rails (>= 2, < 4)
tilt tilt
libv8 (3.16.14.17) libv8 (3.16.14.19)
libxml-ruby (3.0.0) libxml-ruby (3.0.0)
logstash-event (1.2.02) logstash-event (1.2.02)
logstasher (1.1.1) logstasher (1.2.1)
activerecord (>= 4.0)
activesupport (>= 4.0) activesupport (>= 4.0)
logstash-event (~> 1.2.0) logstash-event (~> 1.2.0)
request_store request_store
@ -159,7 +160,7 @@ GEM
multi_json (1.12.1) multi_json (1.12.1)
multi_xml (0.6.0) multi_xml (0.6.0)
multipart-post (2.0.0) multipart-post (2.0.0)
nokogiri (1.7.0.1) nokogiri (1.7.1)
mini_portile2 (~> 2.1.0) mini_portile2 (~> 2.1.0)
nokogumbo (1.4.9) nokogumbo (1.4.9)
nokogiri nokogiri
@ -211,8 +212,8 @@ GEM
mimemagic (= 0.3.0) mimemagic (= 0.3.0)
parser (2.4.0.0) parser (2.4.0.0)
ast (~> 2.2) ast (~> 2.2)
pg (0.19.0) pg (0.20.0)
poltergeist (1.13.0) poltergeist (1.14.0)
capybara (~> 2.1) capybara (~> 2.1)
cliver (~> 0.3.1) cliver (~> 0.3.1)
websocket-driver (>= 0.2.0) websocket-driver (>= 0.2.0)
@ -283,7 +284,7 @@ GEM
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3) tilt (>= 1.1, < 3)
secure_headers (3.6.1) secure_headers (3.6.2)
useragent useragent
simplecov (0.12.0) simplecov (0.12.0)
docile (~> 1.1.0) docile (~> 1.1.0)
@ -304,12 +305,12 @@ GEM
ref ref
thor (0.19.4) thor (0.19.4)
thread_safe (0.3.6) thread_safe (0.3.6)
tilt (2.0.6) tilt (2.0.7)
timecop (0.8.1) timecop (0.8.1)
tins (1.13.2) tins (1.13.2)
tzinfo (1.2.2) tzinfo (1.2.2)
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (3.0.4) uglifier (3.1.9)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
unicode-display_width (1.1.3) unicode-display_width (1.1.3)
useragent (0.16.8) useragent (0.16.8)
@ -334,6 +335,7 @@ DEPENDENCIES
actionpack-page_caching actionpack-page_caching
autoprefixer-rails autoprefixer-rails
bigdecimal (~> 1.1.0) bigdecimal (~> 1.1.0)
canonical-rails
coffee-rails (~> 4.1.0) coffee-rails (~> 4.1.0)
composite_primary_keys (~> 8.1.0) composite_primary_keys (~> 8.1.0)
coveralls coveralls

View file

@ -24,7 +24,7 @@
<%= tag("meta", { :name => "msapplication-TileColor", :content => "#00a300" }) %> <%= tag("meta", { :name => "msapplication-TileColor", :content => "#00a300" }) %>
<%= tag("meta", { :name => "msapplication-TileImage", :content => image_path("mstile-144x144.png") }) %> <%= tag("meta", { :name => "msapplication-TileImage", :content => image_path("mstile-144x144.png") }) %>
<%= tag("meta", { :name => "theme-color", :content => "#ffffff" }) %> <%= tag("meta", { :name => "theme-color", :content => "#ffffff" }) %>
<%= tag("link", { :rel => "canonical", :href => root_url(:host => SERVER_URL) }) %> <%= canonical_tag %>
<%= tag("link", { :rel => "publisher", :href => "https://plus.google.com/111953119785824514010" }) %> <%= tag("link", { :rel => "publisher", :href => "https://plus.google.com/111953119785824514010" }) %>
<%= tag("link", { :rel => "search", :type => "application/opensearchdescription+xml", :title => "OpenStreetMap Search", :href => asset_path("osm.xml") }) %> <%= tag("link", { :rel => "search", :type => "application/opensearchdescription+xml", :title => "OpenStreetMap Search", :href => asset_path("osm.xml") }) %>
<%= tag("meta", { :name => "description", :content => "OpenStreetMap is the free wiki world map." }) %> <%= tag("meta", { :name => "description", :content => "OpenStreetMap is the free wiki world map." }) %>

View file

@ -0,0 +1,22 @@
CanonicalRails.setup do |config|
# Force the protocol. If you do not specify, the protocol will be based on the incoming request's protocol.
# config.protocol#= 'https://'
# This is the main host, not just the TLD, omit slashes and protocol. If you have more than one, pick the one you want to rank in search results.
config.host = SERVER_URL
# http://en.wikipedia.org/wiki/URL_normalization
# Trailing slash represents semantics of a directory, ie a collection view - implying an :index get route;
# otherwise we have to assume semantics of an instance of a resource type, a member view - implying a :show get route
#
# Acts as a whitelist for routes to have trailing slashes
config.collection_actions = [:index]
# Parameter spamming can cause index dilution by creating seemingly different URLs with identical or near-identical content.
# Unless whitelisted, these parameters will be omitted
config.whitelisted_parameters = []
end