Automatically generated tags and tag clouds with Jekyll (multiple word tags allowed)
Jekyll is a great thing, and supports tags right out of the box, but in order to get urls like in mephisto, /tags/something here, you have to either add an extension (which do exist, though I haven't tried), or generate them with the Rakefile, or however really, but I chose the Rakefile. Luckily raimonds simanovskis had already done so, but his solution didn't support tags with spaces, which I had used in mephisto, and to not break compatibility when switching, I had to edit the relevant part of his Rakefile to support tags with spaces.
So an an example post looks like this:
---
layout: post
title: Cloning an ISO to a USB flash drive (or anywhere) ...
syntax-highlighting: yes
tags:
- dd
- snow leopard
---
Oh, and Leopard too...
The original method (can be viewed in it's entire, original, unedited form here). To allow support for tags with space (which some people don't like but I do!), you have to change it so it looks like:
desc 'Generate tags pages'
task :tags => :tag_cloud do
puts "Generating tags..."
require 'rubygems'
require 'jekyll'
include Jekyll::Filters
options = Jekyll.configuration({})
site = Jekyll::Site.new(options)
site.read_posts('')
# Remove tags directory before regenerating
FileUtils.rm_rf("tags")
site.tags.sort.each do |tag, posts|
html = <<-HTML
---
layout: default
title: "tagged: #{tag}"
syntax-highlighting: yes
---
<h1 class="title">#{tag}</h1>
{% for post in site.posts %}
{% for tag in post.tags %}
{% if tag == '#[tag]'%}
{% include post.html %}
{% endif %}
{% endfor %}
{% endfor %}
HTML
FileUtils.mkdir_p("tags/#{tag}")
File.open("tags/#{tag}/index.html", 'w+') do |file|
file.puts html
end
end
puts 'Done.'
end
Note the line if tag == "#[tag]" should be if tag == "#{tag}" but liquid 2.0 doesn't support escaping, and my ghetto method doesn't work. So just pull the entire function from github.