meta-tags 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -1
- data/.travis.yml +7 -13
- data/CHANGELOG.md +18 -0
- data/Gemfile +5 -0
- data/README.md +163 -71
- data/Rakefile +2 -2
- data/lib/meta_tags.rb +18 -0
- data/lib/meta_tags/configuration.rb +21 -0
- data/lib/meta_tags/meta_tags_collection.rb +5 -10
- data/lib/meta_tags/renderer.rb +114 -37
- data/lib/meta_tags/text_normalizer.rb +71 -6
- data/lib/meta_tags/version.rb +1 -1
- data/lib/meta_tags/view_helper.rb +12 -11
- data/meta-tags.gemspec +2 -1
- data/spec/configuration_spec.rb +14 -0
- data/spec/controller_helper_spec.rb +4 -4
- data/spec/spec_helper.rb +69 -13
- data/spec/text_normalizer/normalize_title_spec.rb +43 -0
- data/spec/text_normalizer/truncate_array_spec.rb +60 -0
- data/spec/view_helper/charset_spec.rb +16 -0
- data/spec/view_helper/custom_spec.rb +67 -0
- data/spec/view_helper/description_spec.rb +61 -0
- data/spec/view_helper/icon_spec.rb +42 -0
- data/spec/view_helper/keywords_spec.rb +58 -0
- data/spec/view_helper/links_spec.rb +125 -0
- data/spec/view_helper/module_spec.rb +41 -0
- data/spec/view_helper/noindex_spec.rb +107 -0
- data/spec/view_helper/open_graph_spec.rb +86 -0
- data/spec/view_helper/open_search_spec.rb +33 -0
- data/spec/view_helper/refresh_spec.rb +32 -0
- data/spec/view_helper/title_spec.rb +155 -0
- data/spec/view_helper/twitter_spec.rb +31 -0
- data/spec/view_helper_spec.rb +57 -0
- metadata +53 -21
- data/spec/meta_tags_spec.rb +0 -570
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
OGQ1ZjE5YzFjMjcxNzM1OTliZDNhY2MxMDU0M2ExMTkxOTMzZTkxMQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 31cca6e8ca34c077fb3c456043bbf68954ba74e6
|
4
|
+
data.tar.gz: 76a7bfab6224589500465629cd82c2148537268c
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
N2YxYjc4YjI4ZDc3ZjIyYjBmNWJiNjBhNzI2MmY3MmRlMDliMjU2ZTQ5Y2My
|
11
|
-
MmM2YTJmZjUzMzFjYWFlMDQxMzJlZmYxMWVkZTdlYjFjMjAwY2U=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
M2FmMmJlZGZhNTU0YWIwMTUzYzZhNGY5OWQxNDA4MGYyOTZlOTUzMzM4NTg4
|
14
|
-
YzU4MGVhZTNiNzk0NzYwNDQ5NTUwYjM2NTA5MTA3YjQxMzI1MWVhZGUwY2Vl
|
15
|
-
NjY5MjVlNTZhYmY1MjNhNjA1MWQ0ZjVkMTU2NjFkZWE2OTI4NWI=
|
6
|
+
metadata.gz: bf8d09a4550dbd500c3296845b22d017d0f7689f78b9cfe2046ee14ec7f564492cbd2a625f319527a26aabc8e0df7a0650f8b509fa451fb9c7f483f4e1d4f955
|
7
|
+
data.tar.gz: 093c8a4f7d2d6065d87dd9bd0a1deba9f43bc1865ef93a44216c7fea1704bcb45f60b48a3a59984ddbeb746f6080e159536ec0b42e569f2ef17ba0ddaf04eb25
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.2
|
data/.travis.yml
CHANGED
@@ -1,27 +1,21 @@
|
|
1
1
|
rvm:
|
2
|
-
- ree
|
3
|
-
- 1.8.7
|
4
|
-
- 1.9.3
|
5
2
|
- 2.0.0
|
6
|
-
- 2.1.
|
3
|
+
- 2.1.7
|
4
|
+
- 2.2.3
|
7
5
|
|
8
6
|
env:
|
9
7
|
- "RAILS_VERSION=3.1.0"
|
10
8
|
- "RAILS_VERSION=3.2.0"
|
11
9
|
- "RAILS_VERSION=4.0.0"
|
12
10
|
- "RAILS_VERSION=4.1.0"
|
11
|
+
- "RAILS_VERSION=4.2.0"
|
13
12
|
|
14
13
|
matrix:
|
15
|
-
exclude:
|
16
|
-
- rvm: ree
|
17
|
-
env: "RAILS_VERSION=4.0.0"
|
18
|
-
- rvm: ree
|
19
|
-
env: "RAILS_VERSION=4.1.0"
|
20
|
-
- rvm: 1.8.7
|
21
|
-
env: "RAILS_VERSION=4.0.0"
|
22
|
-
- rvm: 1.8.7
|
23
|
-
env: "RAILS_VERSION=4.1.0"
|
24
14
|
|
25
15
|
notifications:
|
26
16
|
recipients:
|
27
17
|
- kpumuk@kpumuk.info
|
18
|
+
|
19
|
+
addons:
|
20
|
+
code_climate:
|
21
|
+
repo_token: "8792cbc0d1780830ddd3dd7eb1c25f09f386ba8f04449ad830039469406a6ab3"
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
## 2.1.0 (October 6, 2015)
|
2
|
+
|
3
|
+
Changes:
|
4
|
+
|
5
|
+
- Ruby < 2.0 is not longer supported
|
6
|
+
|
7
|
+
Features:
|
8
|
+
|
9
|
+
- Added charset meta tag
|
10
|
+
- Added ability to configure limits for title, description, keywords
|
11
|
+
- Added OpenSearch links support
|
12
|
+
- Added icon links support
|
13
|
+
- Alternate links can now be generated for RSS or mobile versions
|
14
|
+
|
15
|
+
Bugfixes
|
16
|
+
- Generate `<meta name=""/>` instead of `<meta property=""/>` for custom meta tags
|
17
|
+
- Double HTML escaping in meta tags
|
18
|
+
|
1
19
|
## 2.0.0 (April 15, 2014)
|
2
20
|
|
3
21
|
Features:
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# MetaTags: a gem to make your Rails application SEO-friendly
|
2
2
|
|
3
|
-
[![Travis-CI build status](https://secure.travis-ci.org/kpumuk/meta-tags.
|
3
|
+
[![Travis-CI build status](https://secure.travis-ci.org/kpumuk/meta-tags.svg)](http://travis-ci.org/kpumuk/meta-tags)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/meta-tags.svg)](http://badge.fury.io/rb/meta-tags)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/kpumuk/meta-tags.png)](https://codeclimate.com/github/kpumuk/meta-tags)
|
6
|
+
[![Coverage](https://codeclimate.com/github/kpumuk/meta-tags/coverage.png)](https://codeclimate.com/github/kpumuk/meta-tags)
|
6
7
|
|
7
8
|
Search Engine Optimization (SEO) plugin for Ruby on Rails applications.
|
8
9
|
|
@@ -11,6 +12,8 @@ Search Engine Optimization (SEO) plugin for Ruby on Rails applications.
|
|
11
12
|
MetaTags master branch now fully supports Rails 3.0+ and is not backward
|
12
13
|
compatible. Latest version fully compatible with 2.x is 1.2.3.
|
13
14
|
|
15
|
+
Ruby versions older than 2.0.0 are no longer officially supported.
|
16
|
+
|
14
17
|
## Installation
|
15
18
|
|
16
19
|
Add the "meta-tags" gem to your `Gemfile`.
|
@@ -19,6 +22,20 @@ Add the "meta-tags" gem to your `Gemfile`.
|
|
19
22
|
|
20
23
|
And run `bundle install` command.
|
21
24
|
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
MetaTags follows best-practices for meta tags. Although default limits for
|
28
|
+
truncation have recommended values, you can change them to reflect your own
|
29
|
+
preferences. In order to do that, you can create an initializer
|
30
|
+
`config/initializers/meta_tags.rb`, with following code:
|
31
|
+
|
32
|
+
MetaTags.configure do |c|
|
33
|
+
c.title_limit = 70
|
34
|
+
c.description_limit = 160
|
35
|
+
c.keywords_limit = 255
|
36
|
+
c.keywords_separator = ', '
|
37
|
+
end
|
38
|
+
|
22
39
|
## SEO Basics and MetaTags
|
23
40
|
|
24
41
|
### Titles
|
@@ -27,11 +44,11 @@ Page titles are very important for Search engines. The titles in the
|
|
27
44
|
browser are displayed in the title bar. The search engines would look at
|
28
45
|
the this title bar to determine what the page is all about.
|
29
46
|
|
30
|
-
set_meta_tags :
|
47
|
+
set_meta_tags title: 'Member Login'
|
31
48
|
# <title>Some Page Title</title>
|
32
|
-
set_meta_tags :
|
49
|
+
set_meta_tags site: 'Site Title', title: 'Member Login'
|
33
50
|
# <title>Site Title | Page Title</title>
|
34
|
-
set_meta_tags :
|
51
|
+
set_meta_tags site: 'Site Title', title: 'Member Login', reverse: true
|
35
52
|
# <title>Page Title | Site Title</title>
|
36
53
|
|
37
54
|
Recommended title tag length: up to <b>70 characters</b>, <b>10 words</b>.
|
@@ -43,7 +60,7 @@ browsers as that of titles. But these descriptions may be displayed by
|
|
43
60
|
some search engines. They are used to describe the contents of a page in
|
44
61
|
2 or 3 sentences.
|
45
62
|
|
46
|
-
set_meta_tags :
|
63
|
+
set_meta_tags description: "All text about keywords, other keywords"
|
47
64
|
# <meta name="description" content="All text about keywords, other keywords" />
|
48
65
|
|
49
66
|
Recommended description tag length: up to <b>160 characters</b>.
|
@@ -54,7 +71,7 @@ Meta keywords tag are used to place your keywords that you think a
|
|
54
71
|
surfer would search in Search engines. Repeating keywords unnecessarily
|
55
72
|
would be considered spam and you may get permanently banned from SERP's
|
56
73
|
|
57
|
-
set_meta_tags :
|
74
|
+
set_meta_tags keywords: %w[keyword1 Keyword2 KeyWord3]
|
58
75
|
# <meta name="keywords" content="keyword1, keyword2, keyword3" />
|
59
76
|
|
60
77
|
Recommended keywords tag length: up to <b>255 characters</b>, <b>20 words</b>.
|
@@ -64,9 +81,9 @@ Recommended keywords tag length: up to <b>255 characters</b>, <b>20 words</b>.
|
|
64
81
|
By using the noindex meta tag, you can signal to search engines to not
|
65
82
|
include specific pages in their indexes.
|
66
83
|
|
67
|
-
set_meta_tags :
|
84
|
+
set_meta_tags noindex: true
|
68
85
|
# <meta name="robots" content="noindex" />
|
69
|
-
set_meta_tags :
|
86
|
+
set_meta_tags noindex: 'googlebot'
|
70
87
|
# <meta name="googlebot" content="noindex" />
|
71
88
|
|
72
89
|
This is useful for pages like login, password reset, privacy policy, etc.
|
@@ -83,9 +100,9 @@ page. It's entirely likely that a robot might find the same links on some
|
|
83
100
|
other page without a nofollow (perhaps on some other site), and so
|
84
101
|
still arrives at your undesired page.
|
85
102
|
|
86
|
-
set_meta_tags :
|
103
|
+
set_meta_tags nofollow: true
|
87
104
|
# <meta name="robots" content="nofollow" />
|
88
|
-
set_meta_tags :
|
105
|
+
set_meta_tags nofollow: 'googlebot'
|
89
106
|
# <meta name="googlebot" content="nofollow" />
|
90
107
|
|
91
108
|
Further reading:
|
@@ -99,7 +116,7 @@ Canonical link element tells a search engine what is the canonical or main URL
|
|
99
116
|
for a content which have multiple URLs. The search engine will always return
|
100
117
|
that URL, and link popularity and authority will be applied to that URL.
|
101
118
|
|
102
|
-
set_meta_tags :
|
119
|
+
set_meta_tags canonical: "http://yoursite.com/canonical/url"
|
103
120
|
# <link rel="canonical" href="http://yoursite.com/canonical/url" />
|
104
121
|
|
105
122
|
Further reading:
|
@@ -107,11 +124,33 @@ Further reading:
|
|
107
124
|
* [About rel="canonical"](http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=139394)
|
108
125
|
* [Canonicalization](http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=139066)
|
109
126
|
|
127
|
+
### Icon
|
128
|
+
|
129
|
+
A favicon (short for Favorite icon), also known as a shortcut icon, Web site
|
130
|
+
icon, tab icon or bookmark icon, is a file containing one or more small icons,
|
131
|
+
most commonly 16×16 pixels, associated with a particular website or web page.
|
132
|
+
|
133
|
+
set_meta_tags icon: '/favicon.ico'
|
134
|
+
# <link rel="icon" href="/favicon.ico" type="image/x-icon" />
|
135
|
+
set_meta_tags icon: '/favicon.png', type: 'image/png'
|
136
|
+
# <link rel="icon" href="/favicon.png" type="image/png" />
|
137
|
+
set_meta_tags icon: [
|
138
|
+
{ href: '/images/icons/icon_96.png', sizes: '32x32 96x96', type: 'image/png' },
|
139
|
+
{ href: '/images/icons/icon_itouch_precomp_32.png', rel: 'apple-touch-icon-precomposed', sizes: '32x32', type: 'image/png' },
|
140
|
+
]
|
141
|
+
# <link rel="icon" href="/images/icons/icon_96.png" type="image/png" sizes="32x32 96x96" />
|
142
|
+
# <link rel="apple-touch-icon-precomposed" href="/images/icons/icon_itouch_precomp_32.png" type="image/png" sizes="32x32" />
|
143
|
+
|
144
|
+
Further reading:
|
145
|
+
|
146
|
+
* [Favicon](https://www.wikiwand.com/en/Favicon)
|
147
|
+
* [Touch Icons](https://mathiasbynens.be/notes/touch-icons)
|
148
|
+
|
110
149
|
### Author links
|
111
150
|
|
112
151
|
Link to your Google+ profile using rel="author"
|
113
152
|
|
114
|
-
set_meta_tags :
|
153
|
+
set_meta_tags author: "http://yourgplusprofile.com/profile/url"
|
115
154
|
# <link rel="author" href="http://yourgplusprofile.com/profile/url" />
|
116
155
|
|
117
156
|
Further reading:
|
@@ -122,29 +161,38 @@ Further reading:
|
|
122
161
|
|
123
162
|
Link to your Google+ profile using rel="publisher"
|
124
163
|
|
125
|
-
set_meta_tags :
|
164
|
+
set_meta_tags publisher: "http://yourgplusprofile.com/profile/url"
|
126
165
|
# <link rel="publisher" href="http://yourgplusprofile.com/profile/url" />
|
127
166
|
|
128
167
|
* [Link to your website](https://support.google.com/plus/answer/1713826?hl=en)
|
129
168
|
* [The Difference Between rel=author & rel=publisher](http://www.websitemagazine.com/content/blogs/posts/archive/2013/02/05/the-difference-between-rel-author-amp-rel-publisher.aspx)
|
130
169
|
|
131
|
-
### Multi-regional and multilingual URLs
|
170
|
+
### Multi-regional and multilingual URLs, RSS and mobile links
|
132
171
|
|
133
|
-
Alternate link elements tell a search engine when there is content that's
|
134
|
-
users in a certain region.
|
172
|
+
Alternate link elements tell a search engine when there is content that's
|
173
|
+
translated or targeted to users in a certain region.
|
135
174
|
|
136
|
-
set_meta_tags :
|
175
|
+
set_meta_tags alternate: { "fr" => "http://yoursite.fr/alternate/url" }
|
137
176
|
# <link rel="alternate" href="http://yoursite.fr/alternate/url" hreflang="fr" />
|
138
177
|
|
139
|
-
set_meta_tags :
|
140
|
-
|
178
|
+
set_meta_tags alternate: { "fr" => "http://yoursite.fr/alternate/url",
|
179
|
+
"de" => "http://yoursite.de/alternate/url" }
|
141
180
|
# <link rel="alternate" href="http://yoursite.fr/alternate/url" hreflang="en" />
|
142
181
|
# <link rel="alternate" href="http://yoursite.de/alternate/url" hreflang="de" />
|
143
182
|
|
183
|
+
If you need more than just multi-lingual links, you can use an alternative syntax:
|
184
|
+
|
185
|
+
set_meta_tags alternate: [
|
186
|
+
{ href: 'http://example.fr/base/url', hreflang: 'fr' },
|
187
|
+
{ href: 'http://example.com/feed.rss', type: 'application/rss+xml', title: 'RSS' },
|
188
|
+
{ href: 'http://m.example.com/page-1', media: 'only screen and (max-width: 640px)'},
|
189
|
+
]
|
190
|
+
|
144
191
|
Further reading:
|
145
192
|
|
146
193
|
* [Multi-regional and multilingual sites](https://support.google.com/webmasters/answer/182192)
|
147
194
|
* [About rel="alternate" hreflang="x"](http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=189077)
|
195
|
+
* [Separate URLs](https://developers.google.com/webmasters/mobile-sites/mobile-seo/configurations/separate-urls#annotation-in-the-html)
|
148
196
|
|
149
197
|
### Pagination links
|
150
198
|
|
@@ -152,9 +200,9 @@ Previous and next links indicate indicate the relationship between individual
|
|
152
200
|
URLs. Using these attributes is a strong hint to Google that you want us to
|
153
201
|
treat these pages as a logical sequence.
|
154
202
|
|
155
|
-
set_meta_tags :
|
203
|
+
set_meta_tags prev: "http://yoursite.com/url?page=1"
|
156
204
|
# <link rel="prev" href="http://yoursite.com/url?page=1" />
|
157
|
-
set_meta_tags :
|
205
|
+
set_meta_tags next: "http://yoursite.com/url?page=3"
|
158
206
|
# <link rel="next" href="http://yoursite.com/url?page=3" />
|
159
207
|
|
160
208
|
Further reading:
|
@@ -171,9 +219,9 @@ refreshed, by including the alternative URL in the content parameter. By
|
|
171
219
|
setting the refresh time interval to zero (or a very low value), this allows
|
172
220
|
meta refresh to be used as a method of URL redirection.
|
173
221
|
|
174
|
-
set_meta_tags :
|
222
|
+
set_meta_tags refresh: 5
|
175
223
|
# <meta content="5" http-equiv="refresh" />
|
176
|
-
set_meta_tags :
|
224
|
+
set_meta_tags refresh: '5;url=http://example.com'
|
177
225
|
# <meta content="5;url=http://example.com" http-equiv="refresh" />
|
178
226
|
|
179
227
|
Further reading:
|
@@ -181,14 +229,30 @@ Further reading:
|
|
181
229
|
* [Meta refresh](http://en.wikipedia.org/wiki/Meta_refresh)
|
182
230
|
* [What is the Meta Refresh Tag](http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm)
|
183
231
|
|
232
|
+
|
233
|
+
### Open Search
|
234
|
+
|
235
|
+
Open Search link element to describe a search engine in a standard and accessible format.
|
236
|
+
|
237
|
+
set_meta_tags open_search: {
|
238
|
+
title: "Open Search",
|
239
|
+
href: "/opensearch.xml"
|
240
|
+
}
|
241
|
+
# <link href="/opensearch.xml" rel="search" title="Open Search" type="application/opensearchdescription+xml" />
|
242
|
+
|
243
|
+
Further reading:
|
244
|
+
|
245
|
+
* [OpenSearch specs](http://www.opensearch.org/Specifications/OpenSearch/1.1)
|
246
|
+
* [OpenSearch wiki](http://en.wikipedia.org/wiki/OpenSearch)
|
247
|
+
|
184
248
|
### Hashes
|
185
249
|
|
186
250
|
Any namespace can be built just passing any symbol name and a Hash. For example:
|
187
251
|
|
188
|
-
set_meta_tags :
|
189
|
-
:
|
190
|
-
:
|
191
|
-
:
|
252
|
+
set_meta_tags foo: {
|
253
|
+
bar: "lorem",
|
254
|
+
baz: {
|
255
|
+
qux: "ipsum"
|
192
256
|
}
|
193
257
|
}
|
194
258
|
# <meta property="foo:bar" content="lorem"/>
|
@@ -198,8 +262,8 @@ Any namespace can be built just passing any symbol name and a Hash. For example:
|
|
198
262
|
|
199
263
|
Repeated meta tags can be built just using an Array inside a Hash. For example:
|
200
264
|
|
201
|
-
set_meta_tags :
|
202
|
-
:
|
265
|
+
set_meta_tags og: {
|
266
|
+
image: ["http://example.com/rock.jpg", "http://example.com/rock2.jpg"]
|
203
267
|
}
|
204
268
|
#<meta property="og:image" content="http://example.com/rock.jpg" />
|
205
269
|
#<meta property="og:image" content="http://example.com/rock2.jpg" />
|
@@ -211,14 +275,14 @@ protocol `<meta>` tags to your webpages. The tags allow you to specify
|
|
211
275
|
structured information about your web pages. The more information you provide, the more opportunities your web pages can be surfaced within Facebook today
|
212
276
|
and in the future. Here's an example for a movie page:
|
213
277
|
|
214
|
-
set_meta_tags :
|
215
|
-
:
|
216
|
-
:
|
217
|
-
:
|
218
|
-
:
|
219
|
-
:
|
220
|
-
:
|
221
|
-
:
|
278
|
+
set_meta_tags og: {
|
279
|
+
title: 'The Rock',
|
280
|
+
type: 'video.movie',
|
281
|
+
url: 'http://www.imdb.com/title/tt0117500/',
|
282
|
+
image: 'http://ia.media-imdb.com/rock.jpg',
|
283
|
+
video: {
|
284
|
+
director: 'http://www.imdb.com/name/nm0000881/',
|
285
|
+
writer: ['http://www.imdb.com/name/nm0918711/', 'http://www.imdb.com/name/nm0177018/']
|
222
286
|
}
|
223
287
|
}
|
224
288
|
# <meta property="og:title" content="The Rock"/>
|
@@ -229,6 +293,33 @@ and in the future. Here's an example for a movie page:
|
|
229
293
|
# <meta property="og:video:writer" content="http://www.imdb.com/name/nm0918711/"/>
|
230
294
|
# <meta property="og:video:writer" content="http://www.imdb.com/name/nm0177018/"/>
|
231
295
|
|
296
|
+
Multiple images declared as an **array** (look at the `_` character):
|
297
|
+
|
298
|
+
set_meta_tags og: {
|
299
|
+
title: 'Two structured image properties',
|
300
|
+
type: 'website',
|
301
|
+
url: 'view-source:http://examples.opengraphprotocol.us/image-array.html',
|
302
|
+
image: [{
|
303
|
+
_: 'http://examples.opengraphprotocol.us/media/images/75.png',
|
304
|
+
width: 75,
|
305
|
+
height: 75,
|
306
|
+
},
|
307
|
+
{
|
308
|
+
_: 'http://examples.opengraphprotocol.us/media/images/50.png',
|
309
|
+
width: 50,
|
310
|
+
height: 50,
|
311
|
+
}]
|
312
|
+
}
|
313
|
+
# <meta property="og:title" content="Two structured image properties">
|
314
|
+
# <meta property="og:type" content="website">
|
315
|
+
# <meta property="og:url" content="http://examples.opengraphprotocol.us/image-array.html">
|
316
|
+
# <meta property="og:image" content="http://examples.opengraphprotocol.us/media/images/75.png">
|
317
|
+
# <meta property="og:image:width" content="75">
|
318
|
+
# <meta property="og:image:height" content="75">
|
319
|
+
# <meta property="og:image" content="http://examples.opengraphprotocol.us/media/images/50.png">
|
320
|
+
# <meta property="og:image:width" content="50">
|
321
|
+
# <meta property="og:image:height" content="50">
|
322
|
+
|
232
323
|
Further reading:
|
233
324
|
|
234
325
|
* [Open Graph protocol](http://developers.facebook.com/docs/opengraph/)
|
@@ -238,9 +329,9 @@ Further reading:
|
|
238
329
|
Twitter cards make it possible for you to attach media experiences to Tweets that link to your content.
|
239
330
|
There are 3 card types (summary, photo and player). Here's an example for summary:
|
240
331
|
|
241
|
-
set_meta_tags :
|
242
|
-
:
|
243
|
-
:
|
332
|
+
set_meta_tags twitter: {
|
333
|
+
card: "summary",
|
334
|
+
site: "@username"
|
244
335
|
}
|
245
336
|
# <meta name="twitter:card" content="summary"/>
|
246
337
|
# <meta name="twitter:site" content="@username"/>
|
@@ -249,12 +340,12 @@ Take in consideration that if you're already using OpenGraph to describe data on
|
|
249
340
|
|
250
341
|
When you need to generate a [Twitter Photo card](https://dev.twitter.com/docs/cards/types/photo-card), `twitter:image` property is a string, while image dimensions are specified using `twitter:image:width` and `twitter:image:height`, or a `Hash` objects in terms of MetaTags gems. There is a special syntax to make this work:
|
251
342
|
|
252
|
-
set_meta_tags :
|
253
|
-
:
|
254
|
-
:
|
255
|
-
:
|
256
|
-
:
|
257
|
-
:
|
343
|
+
set_meta_tags twitter: {
|
344
|
+
card: "photo",
|
345
|
+
image: {
|
346
|
+
_: "http://example.com/1.png",
|
347
|
+
width: 100,
|
348
|
+
height: 100,
|
258
349
|
}
|
259
350
|
}
|
260
351
|
# <meta name="twitter:card" content="photo"/>
|
@@ -273,13 +364,13 @@ be rendered on the page, even if meta-tags gem does not know about them.
|
|
273
364
|
|
274
365
|
Example:
|
275
366
|
|
276
|
-
set_meta_tags :
|
367
|
+
set_meta_tags author: "Dmytro Shteflyuk"
|
277
368
|
# <meta name="author" content="Dmytro Shteflyuk"/>
|
278
369
|
|
279
370
|
You can also specify value as an Array, and values will be displayed as a list
|
280
371
|
of `meta` tags:
|
281
372
|
|
282
|
-
set_meta_tags :
|
373
|
+
set_meta_tags author: [ "Dmytro Shteflyuk", "John Doe" ]
|
283
374
|
# <meta name="author" content="Dmytro Shteflyuk"/>
|
284
375
|
# <meta name="author" content="John Doe"/>
|
285
376
|
|
@@ -288,7 +379,7 @@ of `meta` tags:
|
|
288
379
|
First, add this code to your main layout:
|
289
380
|
|
290
381
|
<head>
|
291
|
-
<%= display_meta_tags :
|
382
|
+
<%= display_meta_tags site: 'My website' %>
|
292
383
|
</head>
|
293
384
|
|
294
385
|
Then, to set the page title, add this to each of your views (see below for other options):
|
@@ -316,9 +407,9 @@ You can define following instance variables:
|
|
316
407
|
|
317
408
|
Also you could use `set_meta_tags` method to define all meta tags simultaneously:
|
318
409
|
|
319
|
-
set_meta_tags :
|
320
|
-
:
|
321
|
-
:
|
410
|
+
set_meta_tags title: 'Member Login',
|
411
|
+
description: 'Member login page.',
|
412
|
+
keywords: 'Site, Login, Members'
|
322
413
|
|
323
414
|
You can find allowed options for `set_meta_tags` method below.
|
324
415
|
|
@@ -335,9 +426,9 @@ To set meta tags you can use following methods:
|
|
335
426
|
|
336
427
|
Also there is `set_meta_tags` method exists:
|
337
428
|
|
338
|
-
<% set_meta_tags :
|
339
|
-
:
|
340
|
-
:
|
429
|
+
<% set_meta_tags title: 'Member Login',
|
430
|
+
description: 'Member login page.',
|
431
|
+
keywords: 'Site, Login, Members' %>
|
341
432
|
|
342
433
|
The `title` method returns title itself, so you can use it to show the title
|
343
434
|
somewhere on the page:
|
@@ -356,6 +447,7 @@ Use these options to customize the title format:
|
|
356
447
|
* `:title` — page title;
|
357
448
|
* `:description` — page description;
|
358
449
|
* `:keywords` — page keywords;
|
450
|
+
* `:charset` — page character set;
|
359
451
|
* `:prefix` — text between site name and separator;
|
360
452
|
* `:separator` — text used to separate website name from page title;
|
361
453
|
* `:suffix` — text between separator and page title;
|
@@ -374,25 +466,25 @@ Use these options to customize the title format:
|
|
374
466
|
|
375
467
|
And here are a few examples to give you ideas.
|
376
468
|
|
377
|
-
<%= display_meta_tags :
|
378
|
-
<%= display_meta_tags :
|
379
|
-
<%= display_meta_tags :
|
380
|
-
<%= display_meta_tags :
|
381
|
-
<%= display_meta_tags :
|
382
|
-
<%= display_meta_tags :
|
469
|
+
<%= display_meta_tags separator: "—".html_safe %>
|
470
|
+
<%= display_meta_tags prefix: false, separator: ":" %>
|
471
|
+
<%= display_meta_tags lowercase: true %>
|
472
|
+
<%= display_meta_tags reverse: true, prefix: false %>
|
473
|
+
<%= display_meta_tags og: { title: 'The Rock', type: 'video.movie' } %>
|
474
|
+
<%= display_meta_tags alternate: { 'zh-Hant' => 'http://example.com.tw/base/url' } %>
|
383
475
|
|
384
476
|
### Allowed values
|
385
477
|
|
386
478
|
You can specify `:title` as a string or array:
|
387
479
|
|
388
|
-
set_meta_tags :
|
480
|
+
set_meta_tags title: ['part1', 'part2'], site: 'site'
|
389
481
|
# site | part1 | part2
|
390
|
-
set_meta_tags :
|
482
|
+
set_meta_tags title: ['part1', 'part2'], reverse: true, site: 'site'
|
391
483
|
# part2 | part1 | site
|
392
484
|
|
393
485
|
Keywords can be passed as string of comma-separated values, or as an array:
|
394
486
|
|
395
|
-
set_meta_tags :
|
487
|
+
set_meta_tags keywords: ['tag1', 'tag2']
|
396
488
|
# tag1, tag2
|
397
489
|
|
398
490
|
Description is a string (HTML will be stripped from output string).
|
@@ -405,8 +497,8 @@ the `title`.
|
|
405
497
|
|
406
498
|
Say, you have the following in your application layout:
|
407
499
|
|
408
|
-
display_meta_tags :
|
409
|
-
:
|
500
|
+
display_meta_tags og: {
|
501
|
+
title: :title
|
410
502
|
}
|
411
503
|
|
412
504
|
The value of `og[:title]` is a symbol and therefore references the value of the
|
@@ -432,10 +524,10 @@ code duplication, you can define a helper in `application_helper.rb`:
|
|
432
524
|
|
433
525
|
def default_meta_tags
|
434
526
|
{
|
435
|
-
:
|
436
|
-
:
|
437
|
-
:
|
438
|
-
:
|
527
|
+
title: 'Member Login',
|
528
|
+
description: 'Member login page.',
|
529
|
+
keywords: 'Site, Login, Members',
|
530
|
+
separator: "—".html_safe,
|
439
531
|
}
|
440
532
|
end
|
441
533
|
|
@@ -447,7 +539,7 @@ And in your pjax templates:
|
|
447
539
|
|
448
540
|
<!-- set title here, so we can use it both in "display_title" and in "title" %>
|
449
541
|
<% title "My Page title" %>
|
450
|
-
<%= content_tag :div, :
|
542
|
+
<%= content_tag :div, data: { title: display_title(default_meta_tags) } do %>
|
451
543
|
<h1><%= title %></h1>
|
452
544
|
<!-- HTML goes here -->
|
453
545
|
<% end %>
|