canonical-url 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +44 -0
- data/Rakefile +52 -0
- data/VERSION.yml +4 -0
- data/lib/canonical_url.rb +19 -0
- data/rails/init.rb +4 -0
- metadata +61 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Michael Bleigh and Intridea, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Canonical URL
|
2
|
+
=============
|
3
|
+
|
4
|
+
Canonical URL provides a simple way to utilize the new [Canonical URL Standards][1] adopted by all of the major search engines to improve recognition of duplicated URLs. This allows you to represent information in several different places without harming your search engine rank.
|
5
|
+
|
6
|
+
[1]: http://www.seomoz.org/blog/canonical-url-tag-the-most-important-advancement-in-seo-practices-since-sitemaps
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
Canonical URL is available both as a gem and as a standard Rails plugin. To install as a gem, add this to your `environment.rb`:
|
12
|
+
|
13
|
+
config.gem 'mbleigh-canonical-url', :source => 'http://gems.github.com'
|
14
|
+
|
15
|
+
To install as a traditional plugin:
|
16
|
+
|
17
|
+
script/plugin install git://github.com/mbleigh/canonical-url
|
18
|
+
|
19
|
+
Usage
|
20
|
+
-----
|
21
|
+
|
22
|
+
The plugin is very simple to use and consists of a controller method and a helper. To set a canonical URL you will first need to add it into your site's layout, like so:
|
23
|
+
|
24
|
+
<html>
|
25
|
+
<head>
|
26
|
+
...
|
27
|
+
<%= canonical_link_tag %>
|
28
|
+
...
|
29
|
+
</head>
|
30
|
+
...
|
31
|
+
</html>
|
32
|
+
|
33
|
+
This will automatically insert a canonical URL tag into every page of your site, defaulting to the request's current URL (it will not output anything when you have not specified a canonical URL through the controller or explicitly through the link tag). Then you can set canonical URLs in the controller as follows:
|
34
|
+
|
35
|
+
class BlogController < ApplicationController
|
36
|
+
def show
|
37
|
+
@post = find_post # assume this is a standard blog post type record
|
38
|
+
canonical_url blog_post_path(post.year, post.month, post.day, post.slug)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Now no matter what the routing is that takes you to the post, the canonical URL will remain the same.
|
43
|
+
|
44
|
+
Copyright (c) 2009 [Michael Bleigh](http://www.mbleigh.com/) and [Intridea, Inc.](http://www.intridea.com/). See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |s|
|
6
|
+
s.name = "canonical-url"
|
7
|
+
s.summary = %Q{Rails plugin to take advantage of the new Canonical URL support of search engines.}
|
8
|
+
s.email = "michael@intridea.com"
|
9
|
+
s.homepage = "http://github.com/mbleigh/canonical-url"
|
10
|
+
s.description = "TODO"
|
11
|
+
s.authors = ["Michael Bleigh"]
|
12
|
+
s.files = FileList["[A-Z]*", "{lib,rails}/**/*"]
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'rake/rdoctask'
|
19
|
+
Rake::RDocTask.new do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'canonical-url'
|
22
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
23
|
+
rdoc.rdoc_files.include('README*')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
end
|
26
|
+
|
27
|
+
# require 'rake/testtask'
|
28
|
+
# Rake::TestTask.new(:test) do |t|
|
29
|
+
# t.libs << 'lib' << 'test'
|
30
|
+
# t.pattern = 'test/**/*_test.rb'
|
31
|
+
# t.verbose = false
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# begin
|
35
|
+
# require 'rcov/rcovtask'
|
36
|
+
# Rcov::RcovTask.new do |t|
|
37
|
+
# t.libs << 'test'
|
38
|
+
# t.test_files = FileList['test/**/*_test.rb']
|
39
|
+
# t.verbose = true
|
40
|
+
# end
|
41
|
+
# rescue LoadError
|
42
|
+
# puts "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# begin
|
46
|
+
# require 'cucumber/rake/task'
|
47
|
+
# Cucumber::Rake::Task.new(:features)
|
48
|
+
# rescue LoadError
|
49
|
+
# puts "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# task :default => :test
|
data/VERSION.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module CanonicalURL
|
2
|
+
module ControllerExtensions
|
3
|
+
def canonical_url(url_for_options = {})
|
4
|
+
case url_for_options
|
5
|
+
when Hash
|
6
|
+
@canonical_url = url_for(url_for_options)
|
7
|
+
else
|
8
|
+
@canonical_url = url_for_options
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Helpers
|
14
|
+
def canonical_link_tag(url = nil)
|
15
|
+
return '' unless url || @canonical_url
|
16
|
+
tag('link', :rel => 'canonical', :href => url || @canonical_url || request.url)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/rails/init.rb
ADDED
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: canonical-url
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Bleigh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-13 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Canonical URL for Rails
|
17
|
+
email: michael@intridea.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- LICENSE
|
26
|
+
- Rakefile
|
27
|
+
- README.markdown
|
28
|
+
- VERSION.yml
|
29
|
+
- lib/canonical_url.rb
|
30
|
+
- rails/init.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://github.com/mbleigh/canonical-url
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --inline-source
|
38
|
+
- --charset=UTF-8
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.3.5
|
57
|
+
signing_key:
|
58
|
+
specification_version: 2
|
59
|
+
summary: Rails plugin to take advantage of the new Canonical URL support of search engines.
|
60
|
+
test_files: []
|
61
|
+
|