Easy integration of meta tags into your Middleman applications
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib chore: bump to 0.4.0 Mar 28, 2018
.gitignore Bootstrap gem Mar 22, 2014
.ruby-gemset chore: bump 0.3.0 and add .ruby-* Jan 30, 2017
.ruby-version chore: bump 0.3.0 and add .ruby-* Jan 30, 2017
CHANGELOG.md chore: bump to 0.4.0 Mar 28, 2018
Gemfile Bootstrap gem Mar 22, 2014
LICENSE chore: bump 0.3.0 and add .ruby-* Jan 30, 2017
README.md Updated README to include meta-refresh tag Nov 21, 2017
Rakefile
middleman-meta-tags.gemspec Update email address Dec 24, 2014

README.md

Middleman MetaTags

SEO gem for your Middleman apps.

Based on meta-tags Rails gem.

Installation

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

Usage

Configuration

Edit config.rb and add:

activate :meta_tags

Title

set_meta_tags title: 'Relevant title'
title 'Relevant title'

Description

set_meta_tags description: 'Powerful website full of best practices and keywords'
description 'Powerful website full of best practices and keywords'

Keywords

set_meta_tags keywords: %w(some seo keywords).join(', ')
keywords %w(some seo keywords).join(', ')

Meta-Refresh

To set the HTTP Meta-Refresh property of a page, use the refresh key:

set_meta_tags refresh: "0;url=http://example.com/"

Display meta tags

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: '&raquo;'

Autotagging

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:

  • MM site => META title
  • MM title => META title
  • MM description => META description
  • MM keywords => META keywords
  • MM twitter_card (defaults to summary_large_image) => META twitter:card
  • MM twitter_author => META twitter:creator
  • MM description => META twitter:description
  • MM pull_image => META twitter:image:src
  • MM publisher_twitter => META twitter:site
  • MM title => META twitter:title
  • MM description => META og:description
  • MM pull_image => META og:image
  • MM site => META og:site_name
  • MM title => META og:title
  • MM host => optional attribute for composing pull_image src with asset helper

In 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.

Manually adding addition tags

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.

Pull images

For the pull_image to render for twitter metatags, a full url must be used:

pull_image: '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
pull_image 'page/to/image/jpg'

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request