Snipp
Search Engine Optimization (SEO) helpers for Ruby on Rails
Supported
- HTML meta tags
- Rich snippets and structured data
Installation
Add the "snipp" to your application's Gemfile:
gem 'snipp'
And run bundle install
command.
HTML Meta Tags
Call html_meta_tags
in a view template.
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<%= html_meta_tags %>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
...
Set content attribute values
The priority of setting values
- Call
set_html_meta
- Use I18n dictionary (controller action scope)
- Use I18n dictionary (default scope)
- Set Snipp.config.html_meta_tags
Use helper
Call set_html_meta
in a view.
set_html_meta({
title: "Page Title",
description: "Page Description",
og: {
title: "Title for Social Media"
},
link: {
canonical: "https://github.com/yulii/snipp"
}
}, {
arg: "Option Values for I18n",
page: params[:page]
})
User I18n dictionary files
for each controller action
I18n.t(:title, scope: [:views, params[:controller], params[:action], :meta])
default values
I18n.t(:title, scope: [:default, :meta])
For more information
- read erb files in
app/view/snipp/html.html.erb
- read locale files in
config/locales
Rich Snippets
Call item_tag
like content_tag
<%= item_tag :div, scope: true, type: :review do %>
<%= item_tag :span, 'Snipp', prop: :itemreviewd %>
Reviewed by <%= item_tag :span, '@yulii', prop: :reviewer %> on
<%= item_tag :time, 'April 1', prop: :dtreviewd, datetime: "2013-04-01" %>.
<%= item_tag :span, 'Review summary...', prop: :summary %>
<%= item_tag :span, 'Review description...', prop: :description %>
Rating: <%= item_tag :span, '4.5', prop: :rating %>
<% end %>
This would output
<div itemscope itemtype="http://data-vocabulary.org/Review">
<span itemprop="itemreviewed">Snipp</span>
Reviewed by <span itemprop="reviewer">@yulii</span> on
<time itemprop="dtreviewed" datetime="2013-04-01">April 1</time>.
<span itemprop="summary">Review summary...</span>
<span itemprop="description">Review description...</span>
Rating: <span itemprop="rating">4.5</span>
</div>
Breadcrumbs
- Define naming routes. You can specify a name for any route using the :as option in Rails Application.
- Setup the Rails Application for Internationalization (i18n).
- Call
breadcrumb
method.
<%= breadcrumb [:index, :foods, :fruits] %>
This would output something like Top > Foods > Fruits
, if you will set labels in your Rails.root/config/locales
en:
views:
breadcrumb:
# Sample
index: "Top"
food: "Foods"
food_fruit: "Fruits"
Link to root_path
, food_path
, food_fruit_path
.
Change the separator
Use the :s or :separator option.
<%= breadcrumb [:index, :foods, :fruits], s: "/" %>
Use variables and Customize labels
<%= breadcrumb [:index, :foods, :fruits, { path: fruits_color_path('Red'), label: 'Red' }, { path: food_path(color: 'Red', name: 'Apple'), label: 'Apple' }], s: "/" %>
For more information, read erb files in app/view/snipp/
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
LICENSE
(The MIT License)
Copyright © 2013 yulii. See LICENSE.txt for further details.