SEO gem for your Middleman apps.
Based on meta-tags Rails gem.
Add this line to your application's Gemfile:
gem 'middleman-meta-tags'
And then execute:
$ bundle
Or install it yourself as:
$ gem install middleman-meta-tags
Edit config.rb
and add:
activate :meta_tags
set_meta_tags title: 'Relevant title'
title 'Relevant title'
set_meta_tags description: 'Powerful website full of best practices and keywords'
description 'Powerful website full of best practices and keywords'
set_meta_tags keywords: %w(some seo keywords).join(', ')
keywords %w(some seo keywords).join(', ')
To set the HTTP Meta-Refresh property of a page, use the refresh
key:
set_meta_tags refresh: "0;url=http://example.com/"
Into your <head></head>
tag:
display_meta_tags site: 'My Awesome Website'
By default, there is a |
as separator between title and website name.
You can modify it by adding: separator: '»'
If you want to enable auto meta tagging, put this in you <head></head>
tag:
auto_display_meta_tags
This will look inside of data/site.yml
file to find any site wide defaults.
Then it looks the page meta data to attempt to display the following keys:
site
=> META title
title
=> META title
description
=> META description
keywords
=> META keywords
twitter_card
(defaults to summary_large_image
) => META twitter:card
twitter_author
=> META twitter:creator
description
=> META twitter:description
thumbnail
=> META twitter:image:src
publisher_twitter
=> META twitter:site
title
=> META twitter:title
description
=> META og:description
thumbnail
=> META og:image
site
=> META og:site_name
title
=> META og:title
host
=> optional attribute for composing thumbnail
src with asset helperIn addition, if you want to customize meta tags by each page's frontmatter, you
can add customize_by_frontmatter: true
in data/site.yml
. The priority would
be set_meta_tags > frontmatter > site wide defaults.
Create a helper method inside of your config.rb, like so
helper do
def my_tags
set_meta_tags key => value
end
end
And add it to the layouts and views that you need.
For the thumbnail
to render for twitter metatags, a full url must be used:
thumbnail: 'http://example.com/path/to/image.jpg'
If pointing to an image in your Middleman source, you can instead specify the
relative image path as you would with an asset helper provided you have also
configured the host
in your site.yml
. If your Middleman build activates
extensions like :asset_hash
, the full, hashed URL will be generated in your
metatags.
# site.yml
host: http://example.com
# your article
thumbnail 'page/to/image/jpg'
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)./lib/middleman-meta-tags/version.rb
and CHANGELOG.mdgem build middleman-meta-tags.gemspec
bundle exec rake release