Create a gist now

Instantly share code, notes, and snippets.

Goes in Rakefile for Jekyll for those wanting tag pages
# Using multi-word tags support from
# If using with jekyll gem, remove bits loop and site.read_bits('') and add require 'rubygems' and require 'jekyll'
# Using full HTML instead of layout include to manually set different page title (tag, not tag_slug) and canonical URL in header
desc 'Build tags pages'
task :build_with_tags do
sh 'rm -rf _site'
puts "Generating tags..."
# use custom jekyll that includes archives pages, bits, multiviews, etc
require '/Users/Stammy/Projects/jekyll-stammy/lib/jekyll.rb'
include Jekyll::Filters
options = Jekyll.configuration({})
site =
# nuke old tags pages, recreate
site.tags.sort.each do |tag, posts|
# generate slug-friendly tag
tag_slug = tag.gsub(' ','-').gsub('&', '&')
html = <<-HTML
layout: nil
<!doctype html>
<html lang="en-US">
<meta "charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>#{tag} &mdash;</title>
{% if page.description %}
<meta content="{{ page.description }}" name="description">
{% endif %}
<meta name="description" content="{{ site.description }}"/>
<link rel="canonical" href="{{ site.base_url }}/tags/#{tag_slug}"/>
<link rel="alternate" type="application/rss+xml" title=" Feed" href=""/>
<link rel="stylesheet" href="/sass/screen.css" type="text/css"/>
{% include nav.html %}
<div id="site">
<div id="post">
{% include cta.html %}
<h1>Posts tagged as <span>#{tag}</span></h1>
<ul class="posts post_listing">
{% for post in site.posts %}
{% for tag in post.tags %}
{% if tag == '#{tag}' %}
{% include post_listing.html %}
{% endif %}
{% endfor %}
{% endfor %}
{% for bit in site.bits %}
{% for tag in bit.tags %}
{% if tag == '#{tag}' %}
{% include bit_listing.html %}
{% endif %}
{% endfor %}
{% endfor %}
<p class="larger">View more in the <a href="{{ site.base_url }}/archives" title="Archives - Paul Stamatiou">archives</a> or <a href="{{ site.base_url }}/search" title="Search">search</a>.</p>
{% include load_last_js.html %}
HTML"tags/#{tag_slug}.html", 'w+') do |file|
file.puts html
puts 'Generating tag cloud...'
html = ''
max_count ={|t,p| p.count}.max
site.tags.sort.each do |tag, posts|
s = posts.count
if s > 1
font_size = ((24 - 10.0*(max_count-s)/max_count)*2).to_i/2.0
tag_slug = tag.gsub(' ','-')
html << "<a href=\"{{ site.base_url }}/tags/#{tag_slug}\" title=\"Posts tagged #{tag}\" style=\"font-size: #{font_size}px; line-height:#{font_size}px\">#{tag}</a> "
end'_includes/tag_cloud.html', 'w+') do |file|
file.puts html
puts 'Done. Now running Jekyll and Compass..'
def jekyll
sh 'jekyll'
sh 'compass compile'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment