-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
73 lines (64 loc) · 1.62 KB
/
Rakefile
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
# -*- coding: utf-8 -*-
task :default => 'tags:generate'
# Found at: http://gist.github.com/143571
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
---
<script type="text/javascript">
$(document).ready(function(){
$('h3').each(function (){
$(this).next().hide()
});
$('.title').after('<p><span>Click the arrows to show/hide categories.</span></p>');
});
$(function(){
$('h3').click(function() {
var hidden = $(this).next().is(':hidden');
if (hidden) {
$(this).html(
$(this).html().replace('→', '↓')
);
}
else {
$(this).html(
$(this).html().replace('↓', '→')
);
}
$(this).next().slideToggle();
return hidden;
});
});
</script>
HTML
# Sort by the number of posts in the category.
categories = site.categories.sort_by { |s| s[1].length }
categories.reverse.each do |category, posts|
html << <<-HTML
<h3 id="#{category}">→ #{category} (#{posts.length})</h3>
HTML
html << '<ul class="posts">'
posts.reverse.each do |post|
post_data = post.to_liquid
html << <<-HTML
<li><span>#{date_to_string post.date}</span> → <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