Skip to content

Instantly share code, notes, and snippets.

@alexyoung
Created July 9, 2009 11:02
Show Gist options
  • Save alexyoung/143571 to your computer and use it in GitHub Desktop.
Save alexyoung/143571 to your computer and use it in GitHub Desktop.
namespace :tags do
task :generate do
puts 'Generating tags...'
require 'rubygems'
require 'jekyll'
include Jekyll::Filters
options = Jekyll.configuration({})
site = Jekyll::Site.new(options)
site.read_posts('')
html =<<-HTML
---
layout: default
title: Tags
---
<h2>Tags</h2>
HTML
site.categories.sort.each do |category, posts|
html << <<-HTML
<h3 id="#{category}">#{category}</h3>
HTML
html << '<ul class="posts">'
posts.each do |post|
post_data = post.to_liquid
html << <<-HTML
<li>
<div>#{date_to_string post.date}</div>
<a href="#{post.url}">#{post_data['title']}</a>
</li>
HTML
end
html << '</ul>'
end
File.open('tags.html', 'w+') do |file|
file.puts html
end
puts 'Done.'
end
end
@coolaj86
Copy link

@andrewheiss

I tried a few things, but I couldn't get it to work. Any progress?

@andrewheiss
Copy link

After trying to make some Liquid filters, I finally got it to work using a patch to the Jekyll core. If you add elstudio's patch (http://github.com/mojombo/jekyll/issuesearch?state=open&q=sort+#issue/58), it sorts the tags hash using RBTree (you'll have to install that gem). Your tags should be sorted without any modification to your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment