forked from chrismdp/chrismdp.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
205 lines (181 loc) · 4.5 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
rule '.html' => [ proc { |name| name.sub(/\.html/,'_haml.haml') } ] do |t|
sh %{ haml -E utf-8 #{t.source} #{t.name.sub(/_haml\./,'.')} }
end
rule '.css' => ['.scss'] do |t|
sh %{ sass -t compressed #{t.source} #{t.name} }
end
task :tag do
raise "Doesn't exist"
end
task :cloud do
puts 'Generating tag cloud...'
require 'rubygems'
require 'jekyll'
include Jekyll::Filters
options = Jekyll.configuration({})
site = Jekyll::Site.new(options)
site.read
html =<<-HTML
---
layout: default
title: Tags
type: A tag cloud
---
<div class='hero-unit'>
<p>
<a href='{{ site.url }}'>a blog by Chris Parsons</a>
</p>
<h1>
Tag cloud
</h1>
</div>
<hr />
<div class='row' id='post'>
<div class='col-sm-8'>
<p>Click on a tag to see the relevant posts.</p>
<ul class='tags'>
HTML
site.categories.sort.each do |category, posts|
next if category == ".net"
html << <<-HTML
HTML
s = posts.count
font_size = 12;
html << "<li><a class='tag' href=\"/tag/#{category}/\" title=\"Entries tagged #{category}\" style=\"font-size: #{font_size}px;\">#{category}</a></li>"
end
html << <<-HTML
</ul>
<br/><br/>
</div>
<div class='sidebar col-sm-4'>
<div class='widget'>
<ul class='list-unstyled'>
<li>
<i class='icon-chevron-right'></i>
<a href='/all'>Archives</a>
</li>
</ul>
</div>
</div>
</div>
HTML
File.open('tags/index.html', 'w+') do |file|
file.puts html
end
puts 'Done.'
end
def build_atom_feed(category, posts)
html = ''
html << <<-HTML
---
layout: nil
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Chris Parsons: posts tagged #{category}</title>
<link href="http://chrismdp.com/"/>
<updated>#{ posts.first.to_liquid['date'].xmlschema }</updated>
<id>http://chrismdp.com/tag/#{category}</id>
<author>
<name>Chris</name>
<email>[email protected]</email>
</author>
HTML
posts.each.with_index do |post, index|
post_data = post.to_liquid
html += "<entry>\n"
html += "<title>#{post_data['title']}</title>\n"
post_data.fetch('categories').each do |post_category|
html += "<category term='#{post_category}'/>\n"
end
html += <<-HTML
<author>
<name>Chris</name>
<email>[email protected]</email>
</author>
HTML
html += "<link href='http://chrismdp.com#{ post_data['url'] }'/>\n"
html += "<updated>#{ post_data['date'].xmlschema}</updated>\n"
html += "<id>http://chrismdp.com#{ post_data['id'] }</id>\n"
html += "<content type='html'>{% for post in site.posts %}{% if post.id == \"#{ post_data['id']}\" %}{{ post.content | xml_escape }}{% endif %}{% endfor %}</content>\n"
html += "</entry>\n"
end
html += "</feed>\n"
html
end
def build_tag_page(category, posts)
html = ''
html << <<-HTML
---
layout: default
title: Entries tagged "#{category}"
type: "#{category.gsub(/\b\w/){$&.upcase}}"
---
<div class='hero-unit'>
<p>
<a href='{{ site.url }}'>a blog by Chris Parsons</a>
</p>
<h1>
Posts tagged "#{category}"
</h1>
</div>
<hr />
<div class='row' id='post'>
<div class='col-sm-8'>
HTML
posts.each do |post|
post_data = post.to_liquid
html << <<-HTML
<article class="post">
<div class="entry-body">
<a href="#{post.url}">
<h2 class="entry-title">#{post_data['title']}</h2>
</a>
</div>
<div class="entry-meta">
<span class="entry-date">#{post_data['date'].strftime("%d %b %Y")}</span>
</div>
</article>
HTML
end
html << <<-HTML
</div>
<div class='col-sm-4 sidebar'>
<div class='widget'>
<ul class='list-unstyled'>
<li>
<i class='icon-chevron-right'></i>
<a href='/all'>Archives</a>
</li>
<li>
<i class='icon-chevron-right'></i>
<a href='/tags'>All Categories</a>
</li>
</ul>
</div>
</div>
</div>
HTML
html
end
desc 'Generate tags page'
task :tags do
puts "Generating tags..."
require 'rubygems'
require 'jekyll'
include Jekyll::Filters
options = Jekyll.configuration({ 'markdown' => 'kramdown' })
site = Jekyll::Site.new(options)
site.read
site.categories.sort.each do |category, posts|
next if category == ".net"
FileUtils.mkdir_p "tag/#{category}"
File.open("tag/#{category}/index.html", 'w+') do |file|
file.puts build_tag_page(category, posts)
end
File.open("tag/#{category}/atom.xml", 'w+') do |file|
file.puts build_atom_feed(category, posts)
end
end
puts 'Done.'
end