-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
85 lines (73 loc) · 2 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
require 'rubygems'
gem 'mojombo-jekyll'
require 'jekyll'
require 'set'
require 'fileutils'
task :build do
options = Jekyll.configuration({})
site = Jekyll::Site.new(options)
site.read_posts('')
`rm -rf tags`
tags = site.categories.keys
if tags.size > 0
FileUtils.mkdir_p "tags"
tags.each do |tag|
File.open "tags/#{tag}.html", "w" do |f|
f.puts %{---
layout: default
title: simcha's blog
---
{% for page in site.categories.#{tag} %}
{% assign body = page.content %}
{% include post-div.html %}
{% endfor %}
}
end
end
end
`rm -rf 20*`
by_year = site.posts.inject({}) do |by_year, post|
by_year[post.date.year.to_s] ||= []
by_year[post.date.year.to_s] << post
by_year
end
by_year.keys.each do |year|
FileUtils.mkdir_p year
File.open "#{year}/index.html", "w" do |f|
f.puts %{---
layout: default
title: posts from #{year}
---
{% for page in site.posts %}
{% capture year %}{{ page.date | date: "%Y"}}{% endcapture %}
{% if year == '#{year}' %}
{% assign body = page.content %}
{% include post-div.html %}
{% endif %}
{% endfor %}}
end
end
by_year_and_month = site.posts.inject({}) do |result, post|
result[[post.date.year.to_s, post.date.strftime("%m")]] ||= []
result[[post.date.year.to_s, post.date.strftime("%m")]] << post
result
end
by_year_and_month.keys.each do |year_and_month|
FileUtils.mkdir_p "#{year_and_month.first}/#{year_and_month.last}"
File.open "#{year_and_month.first}/#{year_and_month.last}/index.html", "w" do |f|
f.puts %{---
layout: default
title: posts from #{year_and_month.last} #{year_and_month.first}
---
{% for page in site.posts %}
{% capture year %}{{ page.date | date: "%Y"}}{% endcapture %}
{% capture month %}{{ page.date | date: "%m"}}{% endcapture %}
{% if year == '#{year_and_month.first}' & month = '#{year_and_month.last}'%}
{% assign body = page.content %}
{% include post-div.html %}
{% endif %}
{% endfor %}}
end
end
`jekyll --no-auto`
end