Created
June 3, 2012 14:19
-
-
Save lidaobing/2863697 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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