public
Last active

Goes in Rakefile for Jekyll for those wanting tag pages

  • Download Gist
Rakefile
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
# Using multi-word tags support from http://tesoriere.com/2010/08/25/automatically-generated-tags-and-tag-clouds-with-jekyll--multiple-word-tags-allowed-/
# If using with jekyll gem, remove bits loop and site.read_bits('') and add require 'rubygems' and require 'jekyll'
# Using full HTML instead of layout include to manually set different page title (tag, not tag_slug) and canonical URL in header
 
 
desc 'Build tags pages'
task :build_with_tags do
sh 'rm -rf _site'
puts "Generating tags..."
# use custom jekyll that includes archives pages, bits, multiviews, etc
# https://github.com/stammy/jekyll
require '/Users/Stammy/Projects/jekyll-stammy/lib/jekyll.rb'
include Jekyll::Filters
 
options = Jekyll.configuration({})
site = Jekyll::Site.new(options)
site.read_posts('')
site.read_bits('')
 
# nuke old tags pages, recreate
FileUtils.rm_rf("tags")
FileUtils.mkdir_p("tags")
 
site.tags.sort.each do |tag, posts|
# generate slug-friendly tag
tag_slug = tag.gsub(' ','-').gsub('&', '&')
 
html = <<-HTML
---
layout: nil
---
<!doctype html>
 
<html lang="en-US">
<head>
<meta "charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>#{tag} &mdash; PaulStamatiou.com</title>
 
{% if page.description %}
<meta content="{{ page.description }}" name="description">
{% endif %}
<meta name="description" content="{{ site.description }}"/>
<link rel="canonical" href="{{ site.base_url }}/tags/#{tag_slug}"/>
 
<link rel="alternate" type="application/rss+xml" title="PaulStamatiou.com Feed" href="http://feeds.feedburner.com/paulstamatiou"/>
<link rel="stylesheet" href="/sass/screen.css" type="text/css"/>
</head>
<body>
{% include nav.html %}
<div id="site">
<div id="post">
{% include cta.html %}
<h1>Posts tagged as <span>#{tag}</span></h1>
<ul class="posts post_listing">
{% for post in site.posts %}
{% for tag in post.tags %}
{% if tag == '#{tag}' %}
{% include post_listing.html %}
{% endif %}
{% endfor %}
{% endfor %}
{% for bit in site.bits %}
{% for tag in bit.tags %}
{% if tag == '#{tag}' %}
{% include bit_listing.html %}
{% endif %}
{% endfor %}
{% endfor %}
</ul>
<p class="larger">View more in the <a href="{{ site.base_url }}/archives" title="Archives - Paul Stamatiou">archives</a> or <a href="{{ site.base_url }}/search" title="Search">search</a>.</p>
</div>
</div>
{% include load_last_js.html %}
</body>
</html>
HTML
File.open("tags/#{tag_slug}.html", 'w+') do |file|
file.puts html
end
end
 
puts 'Generating tag cloud...'
html = ''
max_count = site.tags.map{|t,p| p.count}.max
site.tags.sort.each do |tag, posts|
s = posts.count
if s > 1
font_size = ((24 - 10.0*(max_count-s)/max_count)*2).to_i/2.0
tag_slug = tag.gsub(' ','-')
html << "<a href=\"{{ site.base_url }}/tags/#{tag_slug}\" title=\"Posts tagged #{tag}\" style=\"font-size: #{font_size}px; line-height:#{font_size}px\">#{tag}</a> "
end
end
File.open('_includes/tag_cloud.html', 'w+') do |file|
file.puts html
end
puts 'Done. Now running Jekyll and Compass..'
jekyll
end
 
 
def jekyll
sh 'jekyll'
sh 'compass compile'
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.