mbleigh-canonical-url 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +44 -0
- data/lib/canonical_url.rb +18 -0
- metadata +55 -0
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 (we assume that the current URL is the canonical URL for any page where it is not specified). 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.
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
tag('link', :rel => 'canonical', :href => url || @canonical_url || request.url)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mbleigh-canonical-url
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
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: TODO
|
|
17
|
+
email: michael@intridea.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- README.markdown
|
|
26
|
+
- lib/canonical_url.rb
|
|
27
|
+
has_rdoc: true
|
|
28
|
+
homepage: http://github.com/mbleigh/canonical-url
|
|
29
|
+
post_install_message:
|
|
30
|
+
rdoc_options:
|
|
31
|
+
- --inline-source
|
|
32
|
+
- --charset=UTF-8
|
|
33
|
+
require_paths:
|
|
34
|
+
- lib
|
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: "0"
|
|
40
|
+
version:
|
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: "0"
|
|
46
|
+
version:
|
|
47
|
+
requirements: []
|
|
48
|
+
|
|
49
|
+
rubyforge_project:
|
|
50
|
+
rubygems_version: 1.2.0
|
|
51
|
+
signing_key:
|
|
52
|
+
specification_version: 2
|
|
53
|
+
summary: Rails plugin to take advantage of the new Canonical URL support of search engines.
|
|
54
|
+
test_files: []
|
|
55
|
+
|