SuchMeta
A gem that simplifies SEO meta tags, allowing for customization and internationalization.
Setup & Installation
Add this line to your application's Gemfile:
gem 'such_meta'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install such_meta
Use the built-in generator to set up such_meta.en.yml
:
$ bundle exec rails g such_meta:install
The generator will add the such_meta.en.yml
file to config/locales/such_meta.en.yml
. Use this yml file to set default meta tags for the site and to target specific controller actions. Examples are included below.
Included In This Gem:
There are two basic ways to configure your meta tags:
Get
You can either "get" the meta tag, by passing a tag_type
: such_meta(tag_type)
. If there is a controller/action defined in such_meta.en.yml under specific
, the custom tag is returned. Otherwise, the default tags defined under default
.
Set
Or, you can "set" the meta tag, by passing the tag_type
and the value
that you'd like to override: such_meta(tag_type, value)
.
Setting Up Your Yaml File
Default Meta Tags:
en:
such_meta:
default:
title: 'Default'
description: 'Default description for Such Meta'
keywords: 'Default Keyword 1, Default Keyword 2, Default Keyword 3'
og:
title: 'Default Facebook Title'
type: 'Default Facebook Type'
image: 'Default Image'
twitter:
card: 'Default Twitter'
site: 'Default Site'
Specific Meta Tags
en:
such_meta:
default: <!-- please see above -->
specific:
controller_name:
index:
title: 'Controller Index Title'
description: 'Description for Controller Index'
keywords: 'Keyword 1, Keyword 2, Keyword 3'
show:
title: 'Controller Show Title'
description: 'Description for Controller Show'
keywords:
og:
title: 'Facebook'
type: 'Type'
url: 'http://www.sampleurl.com'
image: 'https://image.com/300/400'
twitter:
card: 'Twitter'
site: 'Site'
Recommended Usage
Here are some recommended meta tags to get you started. These tags belong in application.html.erb
in a traditional Rails application:
Title
<title><%= such_meta(:title) %></title>
Description
<meta name="description" content="<%= such_meta(:description) %>">
Keywords
<meta name="keywords" content="<%= such_meta(:keywords) %>">
Facebook
<meta property="og:title" content="<%= such_meta('og.title') %>">
<meta property="og:type" content="<%= such_meta('og.type') %>">
<meta property="og:image" content="<%= such_meta('og.image') %>">
<meta property="og:url" content="<%= such_meta('og.url') %>">
<meta property="twitter:card" content="<%= such_meta('twitter.card') %>">
<meta property="twitter:description" content="<%= such_meta('twitter.description') %>">
<meta property="twitter:site" content="<%= such_meta('twitter.site') %>">
<meta property="twitter:title" content="<%= such_meta('twitter.title') %>">
<meta property="twitter:image" content="<%= such_meta('twitter.image') %>">
Contributing
- Fork it ( https://github.com/crushlovely/suchmeta/fork )
- 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 a new Pull Request
Running tests
bundle exec guard