Forked from pkazmierczak/jekyll-create-tag-pages-rakefile.rb
Created
May 12, 2012 13:45
-
-
Save teiko/2666591 to your computer and use it in GitHub Desktop.
This fork works for 'tags', not 'categories'.
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 tags page' | |
task :tags do | |
puts "Generating tags..." | |
require 'rubygems' | |
require 'jekyll' | |
include Jekyll::Filters | |
options = Jekyll.configuration({}) | |
site = Jekyll::Site.new(options) | |
site.read_posts('') | |
site.tags.sort.each do |tag, posts| | |
html = '' | |
html << <<-HTML | |
--- | |
layout: main | |
title: Posts tagged "#{tag}" | |
--- | |
<h1 id="#{tag}">Postings tagged "#{tag}"</h1> | |
HTML | |
posts.reverse.each do |post| | |
post_data = post.to_liquid | |
html << <<-HTML | |
<div class="section list"> | |
<h1>#{date_to_string(post.date)}</h1> | |
<p class="line"> | |
<a class="title" href="#{post.url}">#{post_data['title']}</a> | |
</p> | |
<p class="excerpt"> | |
#{post_data['excerpt']} | |
</p> | |
</div> | |
HTML | |
end | |
File.open("tags/#{tag}.html", 'w+') do |file| | |
file.puts html | |
end | |
end | |
puts 'Done.' | |
end |
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 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 | |
desc 'Generate tags pages' | |
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 = '' | |
max_count = site.tags.map{|t,p| p.count}.max | |
site.tags.sort.each do |tag, posts| | |
s = posts.count | |
font_size = ((20 - 10.0*(max_count-s)/max_count)*2).to_i/2.0 | |
html << "<a href=\"/tags/#{tag.gsub(/ /,"%20")}\" title=\"Postings tagged #{tag}\" style=\"font-size: #{font_size}px; line-height:#{font_size}px\">#{tag}</a> " | |
end | |
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