[!NOTE] Archived Version: This cheatsheet covers Middleman v3. For newer installations, refer to Middleman v4+ documentation.
Middleman is a static site generator written in Ruby using modern web development shortcuts and standards.
Configuration (config.rb)
Directories & Assets
set :css_dir, "stylesheets"
set :js_dir, "javascripts"
set :images_dir, "images"
# Automatic image dimension tags on image_tag helper
activate :automatic_image_sizes
Compass Integration
compass_config do |config|
config.output_style = :compact
end
Page Routing & Layouts
# Disable layout for raw HTML or XML templates
page "/sitemap.xml", layout: false
# Assign alternate layout
page "/admin/*", layout: :admin_layout
# Group multiple paths under one layout
with_layout :docs do
page "/guides/*"
page "/api/*"
end
# Fake proxy pages
page "/about.html", proxy: "/template-page.html" do
@page_title = "About Us"
end
Custom Helpers
helpers do
def format_currency(amount)
"$%.2f" % amount
end
end
Build Configuration
Optimize assets only when running middleman build:
configure :build do
activate :minify_css
activate :minify_javascript
activate :cache_buster
activate :relative_assets
# Prefix assets with custom CDN path
# set :http_path, "https://cdn.example.com/"
end