Created
May 3, 2014 16:22
-
-
Save derekconjar/d94854cd4fbe446d801b to your computer and use it in GitHub Desktop.
An example of SEO for Middleman sites. Add data (like titles, meta descriptions, etc.) using YAML files and frontmatter, and use custom helpers to process the data and display them properly within your ERB layouts and partials.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<title><%= title_helper %></title> | |
<meta charset="utf-8"> | |
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<meta name="description" content="<%= description_helper %>"> | |
<link rel="canonical" href="<%= permalink_helper %>"> | |
<link rel="author" href="<%= data.site.gplus %>"> | |
<link rel="alternate" type="application/rss+xml" title="http://feeds.feedburner.com/derekconjar"> | |
<meta property="og:locale" content="en_US"> | |
<meta property="og:title" content="<%= title_helper %>"> | |
<meta property="og:description" content="<%= description_helper %>"> | |
<meta property="og:url" content="<%= permalink_helper %>"> | |
<meta property="og:site_name" content="<%= site_name_helper %>"> | |
<meta property="og:image" content="<%= image_helper %>"> | |
<meta property="og:type" content="article"> | |
<meta name="twitter:card" content="summary"> | |
<meta name="twitter:site" content="<%= data.site.twitter_handle %>"> | |
<meta name="twitter:creator" content="<%= data.site.twitter_handle %>"> | |
<meta name="twitter:title" content="<%= title_helper %>"> | |
<meta name="twitter:description" content="<%= description_helper %>"> | |
<meta name="twitter:image" content="<%= image_helper %>"> | |
<meta name="google-site-verification" content="nnaAbi0PPS-NaF_f_sIM83C12Zh_JV3GNqzR52gtdao"> | |
<link rel="shortcut icon" href="/images/favicons/favicon.ico" type="image/x-icon"> | |
<link rel="apple-touch-icon" href="/images/favicons/apple-touch-icon.png"> | |
<link rel="apple-touch-icon" sizes="57x57" href="/images/favicons/apple-touch-icon-57x57.png"> | |
<link rel="apple-touch-icon" sizes="60x60" href="/images/favicons/apple-touch-icon-60x60.png"> | |
<link rel="apple-touch-icon" sizes="72x72" href="/images/favicons/apple-touch-icon-72x72.png"> | |
<link rel="apple-touch-icon" sizes="76x76" href="/images/favicons/apple-touch-icon-76x76.png"> | |
<link rel="apple-touch-icon" sizes="114x114" href="/images/favicons/apple-touch-icon-114x114.png"> | |
<link rel="apple-touch-icon" sizes="120x120" href="/images/favicons/apple-touch-icon-120x120.png"> | |
<link rel="apple-touch-icon" sizes="144x144" href="/images/favicons/apple-touch-icon-144x144.png"> | |
<link rel="apple-touch-icon" sizes="152x152" href="/images/favicons/apple-touch-icon-152x152.png"> | |
<%= stylesheet_link_tag "all" %> | |
<!--[if lt IE 9]> | |
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> | |
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script> | |
<![endif]--> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SearchEngineHelpers | |
def title_helper(article = nil) | |
if article.nil? | |
if current_page.data.title.nil? | |
"#{data.site.name} - #{data.site.tagline}" | |
else | |
escape_html(current_page.data.title) | |
end | |
else | |
escape_html(article.title) | |
end | |
end | |
def description_helper | |
if current_page.data.description.nil? | |
escape_html(data.site.description) | |
else | |
escape_html(current_page.data.description) | |
end | |
end | |
def permalink_helper(article = nil) | |
if article.nil? | |
data.site.url + current_page.url.gsub("index.html", "") | |
else | |
"#{data.site.url}#{article.url}" | |
end | |
end | |
def image_helper | |
data.site.url + '/images/' + current_page.data.image.to_s || nil | |
end | |
def rss_link_helper | |
data.site.url + '/feed.xml' | |
end | |
def site_name_helper | |
data.site.name | |
end | |
def sitemap_entry_helper(page) | |
data.site.url + '/' + page.destination_path.gsub('index.html', '') | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url: "http://www.example.com" | |
name: "ACME Widgets" | |
tagline: "Best Widgets in the Universe" | |
description: "Default meta description" | |
gplus: "https://plus.google.com/XXXXXXXXXXXXXXX" | |
twitter_handle: "@acmewidgets" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | |
<% pages = sitemap.resources.find_all{ |p| p.source_file.match(/\.html/) } %> | |
<% pages.each do |page| %> | |
<% if page.url.include? "/thanks" or page.url.include? "/404" %> | |
<% next %> | |
<% end %> | |
<url> | |
<loc><%= sitemap_entry_helper(page) %></loc> | |
<priority>0.8</priority> | |
</url> | |
<% end %> | |
</urlset> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what does your config.rb file look like for this project? Middleman isn't picking up the site.yml and search_engine_helpers.rb files for me. I'm assuming I need to add something to my config file but I'm not sure what