-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
74 lines (59 loc) · 1.58 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
require 'webrick'
require "term/ansicolor"
require "jekyll"
task :default => :tag_cloud
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('')
FileUtils.rm_rf "tags"
site.tags.sort.each do |tag, posts|
html = ''
html << <<-HTML
---
layout: default
title: Postings tagged "#{tag}"
---
<h1 id="#{tag}">Postings tagged "#{tag}"</h1>
HTML
html << '<ul class="posts">'
posts.each do |post|
post_data = post.to_liquid
html << <<-HTML
<li><a href="#{post.url}">#{post_data['title']}</a></li>
HTML
end
html << '</ul>'
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 => :tags 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