Skip to content

Instantly share code, notes, and snippets.

@lidaobing
Created June 3, 2012 14:19
Show Gist options
  • Save lidaobing/2863697 to your computer and use it in GitHub Desktop.
Save lidaobing/2863697 to your computer and use it in GitHub Desktop.
desc 'Generate tag cloud'
task :tag_cloud do
puts "Generating tag_cloud..."
require 'rubygems'
require 'jekyll'
include Jekyll::Filters
options = Jekyll.configuration({})
site = Jekyll::Site.new(options)
site.read_posts('')
html = '<h4>Tags</h4><ul class="tag-cloud">'
site.tags.sort_by{|k,v| -v.count}.slice(0,10).each do |tag, posts|
html << <<-HTML
<li><a href="/tags/#{tag}.html">#{tag}(#{posts.count})</a></li>
HTML
end
html << '</ul>'
File.open("_includes/tag_cloud.html", 'w+') do |file|
file.puts html
end
puts 'Done.'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment